This is the mail archive of the
mailing list for the glibc project.
[RFC] signal-safe fprintf?
- From: Paul Pluzhnikov <ppluzhnikov at google dot com>
- To: libc-alpha at sourceware dot org
- Cc: ahh at google dot com, ppluzhnikov at google dot com
- Date: Tue, 05 Mar 2013 15:43:21 -0800
- Subject: [RFC] signal-safe fprintf?
A followup to the 'free(NULL)' vfprintf thread:
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