Mercurial > hg > octave-kai > gnulib-hg
annotate lib/vasnprintf.h @ 11224:5aa57cee93aa
avoid gcc 3.4.3 bug on long double NaN on Irix 6.5
* tests/nan.h (NaNl): Rewrite as function on Irix, to avoid
compilation bug by using runtime conversion.
* m4/isfinite.m4 (gl_ISFINITE): Likewise.
* m4/isnanl.m4 (gl_FUNC_ISNANL): Likewise.
* modules/ceill-tests (Files): Use nan.h.
* modules/floorl-tests (Files): Likewise.
* modules/frexpl-tests (Files): Likewise.
* modules/isnanl-tests (Files): Likewise.
* modules/ldexpl-tests (Files): Likewise.
* modules/roundl-tests (Files): Likewise.
* modules/truncl-tests (Files): Likewise.
* tests/test-ceill.c (main): Use a working NaN.
* tests/test-floorl.c (main): Likewise.
* tests/test-frexpl.c (main): Likewise.
* tests/test-isnan.c (test_long_double): Likewise.
* tests/test-isnanl.h (main): Likewise.
* tests/test-ldexpl.h (main): Likewise.
* tests/test-roundl.h (main): Likewise.
* tests/test-truncl.h (main): Likewise.
See http://lists.gnu.org/archive/html/bug-gnulib/2009-02/msg00190.html.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Thu, 26 Feb 2009 20:18:42 -0700 (2009-02-27) |
parents | c4fa39bf5223 |
children | b5e42ef33b49 |
rev | line source |
---|---|
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* vsprintf with automatic memory allocation. |
9613
c4fa39bf5223
Don't redefine __attribute__ without a need.
Bruno Haible <bruno@clisp.org>
parents:
8386
diff
changeset
|
2 Copyright (C) 2002-2004, 2007-2008 Free Software Foundation, Inc. |
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
4440
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4224
diff
changeset
|
4 This program is free software; you can redistribute it and/or modify |
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4224
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4224
diff
changeset
|
6 the Free Software Foundation; either version 2, or (at your option) |
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 any later version. |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
4440
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4224
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4224
diff
changeset
|
12 GNU General Public License for more details. |
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
4440
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4224
diff
changeset
|
14 You should have received a copy of the GNU General Public License along |
e58a1c05a6ba
Update gettext source files from gettext automatically, using srclist-update.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4224
diff
changeset
|
15 with this program; if not, write to the Free Software Foundation, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5297
diff
changeset
|
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 #ifndef _VASNPRINTF_H |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #define _VASNPRINTF_H |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 /* Get va_list. */ |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 #include <stdarg.h> |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 /* Get size_t. */ |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <stddef.h> |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 #ifndef __attribute__ |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 /* This feature is available in gcc versions 2.5 and later. */ |
9613
c4fa39bf5223
Don't redefine __attribute__ without a need.
Bruno Haible <bruno@clisp.org>
parents:
8386
diff
changeset
|
29 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) |
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 # define __attribute__(Spec) /* empty */ |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 # endif |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 /* The __-protected variants of `format' and `printf' attributes |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 # define __format__ format |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 # define __printf__ printf |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 # endif |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 #endif |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 |
8386
4ec84f742938
Convert tabs in the middle of preprocessor directives.
Bruno Haible <bruno@clisp.org>
parents:
8338
diff
changeset
|
40 #ifdef __cplusplus |
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 extern "C" { |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 #endif |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 /* Write formatted output to a string dynamically allocated with malloc(). |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 You can pass a preallocated buffer for the result in RESULTBUF and its |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 size in *LENGTHP; otherwise you pass RESULTBUF = NULL. |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 If successful, return the address of the string (this may be = RESULTBUF |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 if no dynamic memory allocation was necessary) and set *LENGTHP to the |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 number of resulting bytes, excluding the trailing NUL. Upon error, set |
5297
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
50 errno and return NULL. |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
51 |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
52 When dynamic memory allocation occurs, the preallocated buffer is left |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
53 alone (with possibly modified contents). This makes it possible to use |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
54 a statically allocated or stack-allocated buffer, like this: |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
55 |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
56 char buf[100]; |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
57 size_t len = sizeof (buf); |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
58 char *output = vasnprintf (buf, &len, format, args); |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
59 if (output == NULL) |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
60 ... error handling ...; |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
61 else |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
62 { |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
63 ... use the output string ...; |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
64 if (output != buf) |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
65 free (output); |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
66 } |
c0fb011695d9
Add comment about preallocated buffer. Suggested by Simon Josefsson.
Bruno Haible <bruno@clisp.org>
parents:
4440
diff
changeset
|
67 */ |
8338
557787fcc6cd
Use function name rpl_vasnprintf if vasnprintf already exists.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
68 #if REPLACE_VASNPRINTF |
557787fcc6cd
Use function name rpl_vasnprintf if vasnprintf already exists.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
69 # define asnprintf rpl_asnprintf |
557787fcc6cd
Use function name rpl_vasnprintf if vasnprintf already exists.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
70 # define vasnprintf rpl_vasnprintf |
557787fcc6cd
Use function name rpl_vasnprintf if vasnprintf already exists.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
71 #endif |
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 __attribute__ ((__format__ (__printf__, 3, 4))); |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 __attribute__ ((__format__ (__printf__, 3, 0))); |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 |
8386
4ec84f742938
Convert tabs in the middle of preprocessor directives.
Bruno Haible <bruno@clisp.org>
parents:
8338
diff
changeset
|
77 #ifdef __cplusplus |
4224
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 } |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 #endif |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 |
83eabea25586
New modules vasnprintf and vasprintf.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 #endif /* _VASNPRINTF_H */ |