1 /* Copyright (C) 2007, 2008 Eric Blake
2 * Permission to use, copy, modify, and distribute this software
3 * is freely granted, provided that this notice is preserved.
5 /* This code was derived from asprintf.c */
17 _asnprintf_r (struct _reent
*__restrict ptr
,
20 const char *__restrict fmt
, ...)
29 /* mark an existing buffer, but allow allocation of larger string */
30 f
._flags
= __SWR
| __SSTR
| __SOPT
;
34 /* mark a zero-length reallocatable buffer */
35 f
._flags
= __SWR
| __SSTR
| __SMBF
;
40 f
._bf
._base
= f
._p
= (unsigned char *) buf
;
41 /* For now, inherit the 32-bit signed limit of FILE._bf._size.
42 FIXME - it would be nice to rewrite sys/reent.h to support size_t
46 _REENT_ERRNO(ptr
) = EOVERFLOW
;
49 f
._bf
._size
= f
._w
= len
;
50 f
._file
= -1; /* No file. */
52 ret
= _svfprintf_r (ptr
, &f
, fmt
, ap
);
58 return (char *) f
._bf
._base
;
61 #ifdef _NANO_FORMATTED_IO
63 _asniprintf_r (struct _reent
*, char *, size_t *, const char *, ...)
64 _ATTRIBUTE ((__alias__("_asnprintf_r")));
70 asnprintf (char *__restrict buf
,
71 size_t *__restrict lenp
,
72 const char *__restrict fmt
, ...)
78 struct _reent
*ptr
= _REENT
;
82 /* mark an existing buffer, but allow allocation of larger string */
83 f
._flags
= __SWR
| __SSTR
| __SOPT
;
87 /* mark a zero-length reallocatable buffer */
88 f
._flags
= __SWR
| __SSTR
| __SMBF
;
93 f
._bf
._base
= f
._p
= (unsigned char *) buf
;
94 /* For now, inherit the 32-bit signed limit of FILE._bf._size.
95 FIXME - it would be nice to rewrite sys/reent.h to support size_t
99 _REENT_ERRNO(ptr
) = EOVERFLOW
;
102 f
._bf
._size
= f
._w
= len
;
103 f
._file
= -1; /* No file. */
105 ret
= _svfprintf_r (ptr
, &f
, fmt
, ap
);
111 return (char *) f
._bf
._base
;
114 #ifdef _NANO_FORMATTED_IO
116 asniprintf (char *, size_t *, const char *, ...)
117 _ATTRIBUTE ((__alias__("asnprintf")));
119 #endif /* ! _REENT_ONLY */