g_printf_string_upper_bound and positional parameters



Hi,

I needed a function like g_strdup_printf in slrn (a console mode
newsreader), and decided to use a modified version of
g_printf_string_upper_bound to implement it.

However, I now added gettext support and one of the translators (Byrial
Jensen <byrial image dk>) complained that the code could not handle
positional parameters.  He suggested finding out the length of a format
string by writing it to the null device instead, like this:

int printf_string_length (const char *format, va_list args)
{
   static FILE *null;

   if (!null)
   {
      null = fopen ("/dev/null", "w");
      if (!null)
         return -1; /* Add some error handling */
   }
   return vfprintf (null, format, args);
   /* Leave null open. */
}

To me, this sounds like a workable solution, but I guess there must be a
reason why it isn't done this way in glib.  Any hints?

I tried to find information about this in the mailing list archive, but
the search at <http://mail.gnome.org/archives/gtk-devel-list/> did not
seem to work - I did not even get results when trying very basic keywords
like "widget".

Kind regards,
    Thomas Schultz




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]