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 */
6 /* doc in siprintf.c */
17 _asniprintf_r (struct _reent
*ptr
,
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
= _svfiprintf_r (ptr
, &f
, fmt
, ap
);
58 return (char *) f
._bf
._base
;
64 asniprintf (char *buf
,
72 struct _reent
*ptr
= _REENT
;
76 /* mark an existing buffer, but allow allocation of larger string */
77 f
._flags
= __SWR
| __SSTR
| __SOPT
;
81 /* mark a zero-length reallocatable buffer */
82 f
._flags
= __SWR
| __SSTR
| __SMBF
;
87 f
._bf
._base
= f
._p
= (unsigned char *) buf
;
88 /* For now, inherit the 32-bit signed limit of FILE._bf._size.
89 FIXME - it would be nice to rewrite sys/reent.h to support size_t
93 _REENT_ERRNO(ptr
) = EOVERFLOW
;
96 f
._bf
._size
= f
._w
= len
;
97 f
._file
= -1; /* No file. */
99 ret
= _svfiprintf_r (ptr
, &f
, fmt
, ap
);
105 return (char *) f
._bf
._base
;
108 #endif /* ! _REENT_ONLY */