X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3fe5947a05c3e9c84b29e4e7f60c111aeab7fe27..3f4f5e63dadc0023c0a02a08af8e9e9801b38e8e:/src/xbt/snprintf.c diff --git a/src/xbt/snprintf.c b/src/xbt/snprintf.c index c5fffcc3b3..e3222d348c 100644 --- a/src/xbt/snprintf.c +++ b/src/xbt/snprintf.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2005-2010, 2012-2016. The SimGrid Team. +/* Copyright (c) 2005-2023. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -27,14 +27,14 @@ * If not, I'll be glad to provide one. * * FEATURES - * - careful adherence to specs regarding flags, field width and precision; + * - careful adherence to specs regarding flags, field width and precision * - good performance for large string handling (large format, large * argument or large paddings). Performance is similar to system's sprintf * and in several cases significantly better (make sure you compile with * optimizations turned on, tell the compiler the code is strict ANSI - * if necessary to give it more freedom for optimizations); - * - return value semantics per ISO/IEC 9899:1999 ("ISO C99"); - * - written in standard ISO/ANSI C - requires an ANSI C compiler. + * if necessary to give it more freedom for optimizations) + * - return value semantics per ISO/IEC 9899:1999 ("ISO C99") + * - written in standard ISO/ANSI C - requires an ANSI C compiler * * [...] * @@ -49,14 +49,20 @@ * http://www.ijs.si/software/snprintf/ */ -#include "xbt/sysdep.h" /* xbt_abort() */ -#include "src/internal_config.h" /* Do we need vasprintf? */ +/* find vasprintf in stdio.h */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif #include -#include + +#include "src/internal_config.h" /* Do we need vasprintf? */ +#include "xbt/asserts.h" /* xbt_abort() */ +#include "xbt/misc.h" #if !HAVE_VASPRINTF +#include #include /* vsnprintf */ -int vasprintf(char **ptr, const char *fmt, va_list ap); +int vasprintf(char** ptr, const char* fmt, va_list ap) XBT_ATTRIB_PRINTF(2, 0); int vasprintf(char **ptr, const char *fmt, va_list ap) { size_t str_m; @@ -69,8 +75,9 @@ int vasprintf(char **ptr, const char *fmt, va_list ap) str_l = vsnprintf(NULL, (size_t) 0, fmt, ap2); /*get required size */ va_end(ap2); } - xbt_assert(str_l >= 0); /* possible integer overflow if str_m > INT_MAX */ - *ptr = (char *) xbt_malloc(str_m = (size_t) str_l + 1); + assert(str_l >= 0); /* possible integer overflow if str_m > INT_MAX */ + *ptr = (char*)malloc(str_m = (size_t)str_l + 1); + assert(*ptr != NULL); int str_l2 = vsnprintf(*ptr, str_m, fmt, ap); assert(str_l2 == str_l);