X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/865f97c868ce92518b1cf4f23e23bd1b16b7917c..1a39cc6fdc908c33507b5b0f8bae61f7286fd4ca:/src/xbt/snprintf.c diff --git a/src/xbt/snprintf.c b/src/xbt/snprintf.c index 5fbb4100ea..cba8d0b744 100644 --- a/src/xbt/snprintf.c +++ b/src/xbt/snprintf.c @@ -357,8 +357,8 @@ #endif /* some other values of possible interest: */ - /* #define breakeven_point 8 *//* VAX 4000 - vaxc */ - /* #define breakeven_point 19 *//* VAX 4000 - gcc 2.7.0 */ + /* #define breakeven_point 8 *//* VAX 4000 - vaxc */ + /* #define breakeven_point 19 *//* VAX 4000 - gcc 2.7.0 */ #ifndef breakeven_point # define breakeven_point 6 /* some reasonable one-size-fits-all value */ @@ -417,7 +417,8 @@ int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap); int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ ...); #if !defined(NEED_SNPRINTF_ONLY) -int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap); +int portable_vsnprintf(char *str, size_t str_m, const char *fmt, + va_list ap); #endif #endif @@ -557,7 +558,8 @@ int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap) #if !defined(HAVE_SNPRINTF) || defined(PREFER_PORTABLE_SNPRINTF) #if !defined(NEED_SNPRINTF_ONLY) -int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ ...) +int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ + ...) { va_list ap; int str_l; @@ -570,10 +572,12 @@ int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ ...) #endif #if defined(NEED_SNPRINTF_ONLY) -int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ ...) +int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args */ + ...) { #else -int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) +int portable_vsnprintf(char *str, size_t str_m, const char *fmt, + va_list ap) { #endif @@ -937,7 +941,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) /* Actually it uses 0x prefix even for a zero value. */ && arg_sign != 0 #endif - ) { + ) { tmp[str_arg_l++] = '0'; tmp[str_arg_l++] = 'x'; } @@ -953,7 +957,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) * converting a zero value with a precision of zero is a null string. * Actually HP returns all zeroes, and Linux returns "(nil)". */ #endif - ) { + ) { /* converted to null string */ /* When zero value is formatted with an explicit precision 0, the resulting formatted string is empty (d, i, u, o, x, X, p). */ @@ -1027,7 +1031,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) && !(zero_padding_insertion_ind < str_arg_l && tmp[zero_padding_insertion_ind] == '0') #endif - ) { /* assure leading zero for alternate-form octal numbers */ + ) { /* assure leading zero for alternate-form octal numbers */ if (!precision_specified || precision < num_of_digits + 1) { /* precision is increased to force the first character to be zero, except if a zero value is formatted with an explicit precision @@ -1164,16 +1168,26 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) /* FIXME: better place */ #include "xbt/sysdep.h" +char *bvprintf(const char *fmt, va_list ap) +{ + char *res; + + if (vasprintf(&res, fmt, ap) < 0) { + /* Do not want to use xbt_die() here, as it uses the logging + * infrastucture and may fail to allocate memory too. */ + fprintf(stderr, "bprintf: vasprintf failed. Aborting.\n"); + abort(); + } + return res; +} + char *bprintf(const char *fmt, ...) { va_list ap; char *res; - int len; va_start(ap, fmt); - - len = vasprintf(&res, fmt, ap); - + res = bvprintf(fmt, ap); va_end(ap); return res; }