fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / stdio / asprintf.c
blob1d7dd4baec79a74e48217e866fc7828f1ad941f5
1 /*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 /* This code was copied from sprintf.c */
20 #include <stdio.h>
21 #ifdef _HAVE_STDC
22 #include <stdarg.h>
23 #else
24 #include <varargs.h>
25 #endif
26 #include <limits.h>
27 #include <_ansi.h>
28 #include "local.h"
30 int
31 #ifdef _HAVE_STDC
32 _DEFUN (_asprintf_r, (ptr, strp, fmt), struct _reent *ptr _AND char **strp _AND _CONST char *fmt _DOTS)
33 #else
34 _asprintf_r (ptr, strp, fmt, va_alist)
35 struct _reent *ptr;
36 char **strp;
37 _CONST char *fmt;
38 va_dcl
39 #endif
41 int ret;
42 va_list ap;
43 FILE f;
45 /* mark a zero-length reallocatable buffer */
46 f._flags = __SWR | __SSTR | __SMBF;
47 f._bf._base = f._p = NULL;
48 f._bf._size = f._w = 0;
49 f._file = -1; /* No file. */
50 #ifdef _HAVE_STDC
51 va_start (ap, fmt);
52 #else
53 va_start (ap);
54 #endif
55 ret = vfprintf (&f, fmt, ap);
56 va_end (ap);
57 *f._p = 0;
58 *strp = f._bf._base;
59 return (ret);
62 #ifndef _REENT_ONLY
64 int
65 #ifdef _HAVE_STDC
66 _DEFUN (asprintf, (strp, fmt), char **strp _AND _CONST char *fmt _DOTS)
67 #else
68 asprintf (strp, fmt, va_alist)
69 char **strp;
70 _CONST char *fmt;
71 va_dcl
72 #endif
74 int ret;
75 va_list ap;
76 FILE f;
78 /* mark a zero-length reallocatable buffer */
79 f._flags = __SWR | __SSTR | __SMBF;
80 f._bf._base = f._p = NULL;
81 f._bf._size = f._w = 0;
82 f._file = -1; /* No file. */
83 #ifdef _HAVE_STDC
84 va_start (ap, fmt);
85 #else
86 va_start (ap);
87 #endif
88 ret = vfprintf (&f, fmt, ap);
89 va_end (ap);
90 *f._p = 0;
91 *strp = f._bf._base;
92 return (ret);
95 #endif