Mercurial > hg > octave-max
diff src/cutils.c @ 4160:b822bfbb2277
[project @ 2002-11-08 19:51:03 by jwe]
author | jwe |
---|---|
date | Fri, 08 Nov 2002 19:51:28 +0000 |
parents | 7d85ceb0c570 |
children | 5b075bd78a91 |
line wrap: on
line diff
--- a/src/cutils.c +++ b/src/cutils.c @@ -52,8 +52,6 @@ #endif -#include "oct-snprintf.h" - void octave_sleep (unsigned int seconds) { @@ -121,6 +119,12 @@ return strncasecmp (s1, s2, n); } +// XXX FIXME XXX -- we really need a configure test for this. + +#if defined __GNUC__ && __GNUC__ >= 3 +#define HAVE_C99_VSNPRINTF 1 +#endif + // We manage storage. User should not free it, and its contents are // only valid until next call to vsnprintf. @@ -136,7 +140,12 @@ if (! buf) buf = malloc (size); - nchars = portable_vsnprintf (buf, size, fmt, args); + if (! buf) + return 0; + +#if defined (HAVE_C99_VSNPRINTF) + + nchars = vsnprintf (buf, size, fmt, args); if (nchars >= size) { @@ -147,6 +156,27 @@ vsnprintf (buf, size, fmt, args); } +#else + + while (1) + { + nchars = vsnprintf (buf, size, fmt, args); + + if (nchars > -1) + return buf; + else + { + size *= 2; + + buf = realloc (buf, size); + + if (! buf) + return 0; + } + } + +#endif + return buf; }