This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] signal-safe fprintf?


Greetings,

A followup to the 'free(NULL)' vfprintf thread:
http://sourceware.org/ml/libc-alpha/2013-03/msg00137.html

We would like to provide a signal-safe logging function to our end-users.

We would like to not have to re-implement snprintf(), but just call
it. Snprintf() mostly works, except it might call malloc for a given
format string (which we don't control; our end-users do).

It would be *really* convenent if snprintf could be split into the
"regular" snprintf, and a snprintf_nomalloc(). The latter would return
ENOMEM if malloc was actually required.

The same would apply to other *printf functions.

The actual implementation would simply add a "allow_malloc" flag to
current vfprintf() code, and call it from the new wrappers with
appropriate flag setting.

An alternate implementation strategy: "hijack" some unused format
specifier, e.g. '%!" to set the same flag. That is,

  printf("%!a=%2d", 1);      // OK
  printf("%!a=%20000d", 1);  // ENOMEM


Comments?

Thanks,

--
Paul Pluzhnikov


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]