summaryrefslogtreecommitdiff
path: root/lib/vasnprintf.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-10-04 04:09:41 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-10-04 04:09:41 +0000
commit55fbe6686af907ac025888e290c5b8ef879b5879 (patch)
tree32340229b3778f12901c6b9dd99401212a8d2f23 /lib/vasnprintf.h
parent14f5062c301fcfb23fb265b9352cc2aa952036c9 (diff)
downloadcoreutils-55fbe6686af907ac025888e290c5b8ef879b5879.tar.xz
Sync from gnulib.
Diffstat (limited to 'lib/vasnprintf.h')
-rw-r--r--lib/vasnprintf.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/vasnprintf.h b/lib/vasnprintf.h
index 4edb95d65..271210699 100644
--- a/lib/vasnprintf.h
+++ b/lib/vasnprintf.h
@@ -1,5 +1,5 @@
/* vsprintf with automatic memory allocation.
- Copyright (C) 2002-2003 Free Software Foundation, Inc.
+ Copyright (C) 2002-2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -47,7 +47,24 @@ extern "C" {
If successful, return the address of the string (this may be = RESULTBUF
if no dynamic memory allocation was necessary) and set *LENGTHP to the
number of resulting bytes, excluding the trailing NUL. Upon error, set
- errno and return NULL. */
+ errno and return NULL.
+
+ When dynamic memory allocation occurs, the preallocated buffer is left
+ alone (with possibly modified contents). This makes it possible to use
+ a statically allocated or stack-allocated buffer, like this:
+
+ char buf[100];
+ size_t len = sizeof (buf);
+ char *output = vasnprintf (buf, &len, format, args);
+ if (output == NULL)
+ ... error handling ...;
+ else
+ {
+ ... use the output string ...;
+ if (output != buf)
+ free (output);
+ }
+ */
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)