annotate lib/vasnprintf.h @ 448:5cccf90bf838 3.0 tip

Fixed bug with complex external references generating invalid relocations in the object file
author lost@l-w.ca
date Fri, 05 Nov 2010 22:27:00 -0600
parents b8bf63962a99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
434
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1 /* vsprintf with automatic memory allocation.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
2 Copyright (C) 2002-2004, 2007-2010 Free Software Foundation, Inc.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
3
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
6 the Free Software Foundation; either version 3, or (at your option)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
7 any later version.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
8
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
12 GNU General Public License for more details.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
13
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
14 You should have received a copy of the GNU General Public License along
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
15 with this program; if not, write to the Free Software Foundation,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
17
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
18 #ifndef _VASNPRINTF_H
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
19 #define _VASNPRINTF_H
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
20
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
21 /* Get va_list. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
22 #include <stdarg.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
23
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
24 /* Get size_t. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
25 #include <stddef.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
26
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
27 #ifndef __attribute__
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
28 /* This feature is available in gcc versions 2.5 and later. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
29 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
30 # define __attribute__(Spec) /* empty */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
31 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
32 /* The __-protected variants of `format' and `printf' attributes
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
33 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
34 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
35 # define __format__ format
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
36 # define __printf__ printf
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
37 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
38 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
39
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
40 #ifdef __cplusplus
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
41 extern "C" {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
42 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
43
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
44 /* Write formatted output to a string dynamically allocated with malloc().
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
45 You can pass a preallocated buffer for the result in RESULTBUF and its
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
46 size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
47 If successful, return the address of the string (this may be = RESULTBUF
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
48 if no dynamic memory allocation was necessary) and set *LENGTHP to the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
49 number of resulting bytes, excluding the trailing NUL. Upon error, set
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
50 errno and return NULL.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
51
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
52 When dynamic memory allocation occurs, the preallocated buffer is left
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
53 alone (with possibly modified contents). This makes it possible to use
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
54 a statically allocated or stack-allocated buffer, like this:
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
55
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
56 char buf[100];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
57 size_t len = sizeof (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
58 char *output = vasnprintf (buf, &len, format, args);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
59 if (output == NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
60 ... error handling ...;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
61 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
62 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
63 ... use the output string ...;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
64 if (output != buf)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
65 free (output);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
66 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
67 */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
68 #if REPLACE_VASNPRINTF
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
69 # define asnprintf rpl_asnprintf
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
70 # define vasnprintf rpl_vasnprintf
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
71 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
72 extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
73 __attribute__ ((__format__ (__printf__, 3, 4)));
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
74 extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
75 __attribute__ ((__format__ (__printf__, 3, 0)));
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
76
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
77 #ifdef __cplusplus
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
78 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
79 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
80
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
81 #endif /* _VASNPRINTF_H */