Hi Eric. On Wed, 7 Oct 2009, Eric Blake wrote:
> Yes. But in my opinion, it is even slicker to use either the > xvasprintf{-posix} module, which mallocs for you and calls xalloc_die > automatically on malloc failure: > > char *buf = xasprintf (format, args); > > or the vasnprintf{-posix} module, which helps manage an existing buffer, > so that you can avoid malloc overhead in the common case of small output: Thanks for mentioning these as they will likely become useful to me later. Unfortunately, the example I gave doesn't very well represent exactly what I'm trying to do right now. In one case, I'm computing the length for a variable-length array. In another case, I'm computing a column width for a table to be formatted to a stream. No malloc is needed in either case. > Yes, for every known system, snprintf is just a simple va_arg wrapper that > forwards to vsnprintf, so if the latter has a bug, then the former will as > well. Thanks for explaining. > > 2. Is there any single module that ensures portability of all *printf > > functions? Or is it worthwhile to maintain a list of modules trimmed to > > exactly the functions that are currently used? > > At the moment, you have to pull in all the modules one by one. You can > pull in more than you currently use, if you want to play it safe. Also, > compiling with -DGNULIB_POSIXCHECK is supposed to help identify places > where you might be missing a module. Ah, thanks. It looks like bison has a lot of gnulib modules to consider. Already 6 of them are in the printf-posix family (but -DGNULIB_POSIXCHECK suggests none of those if I don't include at least one of them). > Maybe it would be worth an > uber-printf{-posix} module that pulls in all the variants, but I'm > probably not going to write it. While -DGNULIB_POSIXCHECK solves the biggest problem, it still seems a little silly to maintain a list of gnulib's printf-posix modules in bison. Is the following patch ok? I'm not sure how to fill out some of the fields. >From 351599f18e824e4cdc883156f080becc64ffeb41 Mon Sep 17 00:00:00 2001 From: Joel E. Denny <jde...@clemson.edu> Date: Thu, 8 Oct 2009 00:18:25 -0400 Subject: [PATCH] all-printf, all-printf-posix: new modules. * modules/all-printf: New module. * modules/all-printf-posix: New module. --- ChangeLog | 6 ++++++ modules/all-printf | 25 +++++++++++++++++++++++++ modules/all-printf-posix | 31 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 0 deletions(-) create mode 100644 modules/all-printf create mode 100644 modules/all-printf-posix diff --git a/ChangeLog b/ChangeLog index dedcfc8..a953cbc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-10-08 Joel E. Denny <jde...@clemson.edu> + + all-printf, all-printf-posix: new modules. + * modules/all-printf: New module. + * modules/all-printf-posix: New module. + 2009-10-07 Eric Blake <e...@byu.net> areadlinkat-with-size: new module diff --git a/modules/all-printf b/modules/all-printf new file mode 100644 index 0000000..efc6f35 --- /dev/null +++ b/modules/all-printf @@ -0,0 +1,25 @@ +Description: +All functions in the printf family. + +Files: + +Depends-on: +dprintf +obstack-printf +snprintf +vasnprintf +vasprintf +vdprintf +vsnprintf +xprintf +xvasprintf + +configure.ac: + +Makefile.am: + +Include: + +License: + +Maintainer: diff --git a/modules/all-printf-posix b/modules/all-printf-posix new file mode 100644 index 0000000..3005eff --- /dev/null +++ b/modules/all-printf-posix @@ -0,0 +1,31 @@ +Description: +POSIX compatible versions of all functions in the printf family. + +Files: + +Depends-on: +dprintf-posix +fprintf-posix +obstack-printf-posix +printf-posix +snprintf-posix +sprintf-posix +vasnprintf-posix +vasprintf-posix +vdprintf-posix +vfprintf-posix +vprintf-posix +vsnprintf-posix +vsprintf-posix +xprintf-posix +xvasprintf-posix + +configure.ac: + +Makefile.am: + +Include: + +License: + +Maintainer: -- 1.5.4.3