X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d66a44cd8faf523a6b43a1a706641518139db372..9d8804c534eca423fe2ee8de4f0fe7b43420f76c:/src/xbt/snprintf.c diff --git a/src/xbt/snprintf.c b/src/xbt/snprintf.c index 4f1561807a..0dbbadbec4 100644 --- a/src/xbt/snprintf.c +++ b/src/xbt/snprintf.c @@ -1,4 +1,3 @@ -#include "gras_config.h" /* * snprintf.c - a portable implementation of snprintf @@ -281,7 +280,6 @@ */ - /* ============================================= */ /* NO USER SERVICABLE PARTS FOLLOWING THIS POINT */ /* ============================================= */ @@ -323,8 +321,12 @@ #include #include #include + +#include "portable.h" /* to get a working stdarg.h */ + #include #include +#include "xbt/str.h" #ifdef isdigit #undef isdigit @@ -378,12 +380,14 @@ /* prototypes */ + #if defined(NEED_ASPRINTF) int asprintf (char **ptr, const char *fmt, /*args*/ ...); #endif -#if defined(NEED_VASPRINTF) +#if defined(NEED_VASPRINTF) int vasprintf (char **ptr, const char *fmt, va_list ap); #endif + #if defined(NEED_ASNPRINTF) int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...); #endif @@ -394,6 +398,12 @@ int vasnprintf (char **ptr, size_t str_m, const char *fmt, va_list ap); #if defined(HAVE_SNPRINTF) /* declare our portable snprintf routine under name portable_snprintf */ /* declare our portable vsnprintf routine under name portable_vsnprintf */ +# if defined(_MSC_VER) && (_MSC_VER >= 1400) +# define portable_snprintf _snprintf +# if !defined(NEED_SNPRINTF_ONLY) +# define portable_vsnprintf vsnprintf +# endif +# endif #else /* declare our portable routines under names snprintf and vsnprintf */ #define portable_snprintf snprintf @@ -416,6 +426,12 @@ static char credits[] = "\n\ @(#)snprintf.c, v2.2: Copyright 1999, Mark Martinec. Frontier Artistic License applies.\n\ @(#)snprintf.c, v2.2: http://www.ijs.si/software/snprintf/\n"; +static void __foo__(void) +{ + printf("%s",credits); + __foo__(); +} + #if defined(NEED_ASPRINTF) int asprintf(char **ptr, const char *fmt, /*args*/ ...) { va_list ap; @@ -707,7 +723,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { else if (precision == 0) str_arg_l = 0; else { /* memchr on HP does not like n > 2^31 !!! */ - const char *q = memchr(str_arg, '\0', + char *q = (char *) memchr(str_arg, '\0', precision <= 0x7fffffff ? precision : 0x7fffffff); str_arg_l = !q ? precision : (q-str_arg); } @@ -947,7 +963,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { int n = min_field_width - (str_arg_l+number_of_zeros_to_pad); if (n > 0) { if (str_l < str_m) { - size_t avail = str_m-str_l; + int avail = str_m-str_l; fast_memset(str+str_l, (zero_padding?'0':' '), (n>avail?avail:n)); } str_l += n; @@ -964,7 +980,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { int n = zero_padding_insertion_ind; if (n > 0) { if (str_l < str_m) { - size_t avail = str_m-str_l; + int avail = str_m-str_l; fast_memcpy(str+str_l, str_arg, (n>avail?avail:n)); } str_l += n; @@ -973,7 +989,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { n = number_of_zeros_to_pad; if (n > 0) { if (str_l < str_m) { - size_t avail = str_m-str_l; + int avail = str_m-str_l; fast_memset(str+str_l, '0', (n>avail?avail:n)); } str_l += n; @@ -984,7 +1000,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { { int n = str_arg_l - zero_padding_insertion_ind; if (n > 0) { if (str_l < str_m) { - size_t avail = str_m-str_l; + int avail = str_m-str_l; fast_memcpy(str+str_l, str_arg+zero_padding_insertion_ind, (n>avail?avail:n)); } @@ -996,7 +1012,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { int n = min_field_width - (str_arg_l+number_of_zeros_to_pad); if (n > 0) { if (str_l < str_m) { - size_t avail = str_m-str_l; + int avail = str_m-str_l; fast_memset(str+str_l, ' ', (n>avail?avail:n)); } str_l += n; @@ -1025,3 +1041,20 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { return (int) str_l; } #endif + + +/* FIXME: better place */ +#include "xbt/sysdep.h" + +char *bprintf(const char*fmt, ...) { + va_list ap; + char *res; + + va_start(ap, fmt); + + + vasprintf(&res,fmt,ap); + + va_end(ap); + return res; +}