2004-05-07 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* libc/stdio/iprintf.c (_iprintf_r): Fix old-style argument list for reentrant pointer. Call _vfiprintf_r. * libc/stdio/siprintf.c (_siprintf_r): New function. * libc/stdio/vfprintf.c (__sbprintf): Add reetrant struct pointer argument. Change all callers. Call _VFPRINTF_R. * libc/include/stdio.h (_siprintf_r, _vfiprintf_r): New prototypes.
This commit is contained in:
parent
631fbe65fa
commit
186420eccf
|
@ -282,6 +282,7 @@ long _EXFUN(_ftell_r, (struct _reent *, FILE *));
|
|||
int _EXFUN(_getchar_r, (struct _reent *));
|
||||
char * _EXFUN(_gets_r, (struct _reent *, char *));
|
||||
int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...));
|
||||
int _EXFUN(_siprintf_r, (struct _reent *, char *, const char *, ...));
|
||||
int _EXFUN(_mkstemp_r, (struct _reent *, char *));
|
||||
char * _EXFUN(_mktemp_r, (struct _reent *, char *));
|
||||
void _EXFUN(_perror_r, (struct _reent *, const char *));
|
||||
|
@ -300,6 +301,7 @@ FILE * _EXFUN(_tmpfile_r, (struct _reent *));
|
|||
char * _EXFUN(_tmpnam_r, (struct _reent *, char *));
|
||||
int _EXFUN(_ungetc_r, (struct _reent *, int, FILE *));
|
||||
int _EXFUN(_vasprintf_r, (struct _reent *, char **, const char *, __VALIST));
|
||||
int _EXFUN(_vfiprintf_r, (struct _reent *, FILE *, const char *, __VALIST));
|
||||
int _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST));
|
||||
int _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST));
|
||||
int _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST));
|
||||
|
|
|
@ -96,8 +96,8 @@ int
|
|||
_iprintf_r(struct _reent *ptr, _CONST char *fmt, ...)
|
||||
#else
|
||||
int
|
||||
_iprintf_r(data, fmt, va_alist)
|
||||
char *data;
|
||||
_iprintf_r(ptr, fmt, va_alist)
|
||||
struct _reent *ptr;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
|
@ -111,7 +111,8 @@ _iprintf_r(data, fmt, va_alist)
|
|||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = vfiprintf (_stdout_r (ptr), fmt, ap);
|
||||
ret = _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,12 @@ ANSI_SYNOPSIS
|
|||
|
||||
int siprintf(char *<[str]>, const char *<[format]> [, <[arg]>, ...]);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
|
||||
int siprintf(<[str]>, <[format]>, [, <[arg]>, ...])
|
||||
char *<[str]>;
|
||||
const char *<[format]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<siprintf>> is a restricted version of <<sprintf>>: it has the same
|
||||
|
@ -58,6 +64,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
|||
#include <limits.h>
|
||||
#include "local.h"
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN(siprintf, (str, fmt),
|
||||
|
@ -87,3 +95,38 @@ siprintf(str, fmt, va_alist)
|
|||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
#endif /* ! _REENT_ONLY */
|
||||
|
||||
int
|
||||
#ifdef _HAVE_STDC
|
||||
_DEFUN(_siprintf_r, (rptr, str, fmt),
|
||||
struct _reent *rptr _AND
|
||||
char *str _AND
|
||||
_CONST char *fmt _DOTS)
|
||||
#else
|
||||
_siprintf_r(rptr, str, fmt, va_alist)
|
||||
struct _reent *rptr;
|
||||
char *str;
|
||||
_CONST char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
FILE f;
|
||||
|
||||
f._flags = __SWR | __SSTR;
|
||||
f._bf._base = f._p = (unsigned char *) str;
|
||||
f._bf._size = f._w = INT_MAX;
|
||||
#ifdef _HAVE_STDC
|
||||
va_start (ap, fmt);
|
||||
#else
|
||||
va_start (ap);
|
||||
#endif
|
||||
ret = _vfiprintf_r (rptr, &f, fmt, ap);
|
||||
va_end (ap);
|
||||
*f._p = 0;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
|
|
@ -233,8 +233,9 @@ _DEFUN(__sprint, (fp, uio),
|
|||
* worries about ungetc buffers and so forth.
|
||||
*/
|
||||
static int
|
||||
_DEFUN(__sbprintf, (fp, fmt, ap),
|
||||
register FILE *fp _AND
|
||||
_DEFUN(__sbprintf, (rptr, fp, fmt, ap),
|
||||
struct _reent *rptr _AND
|
||||
register FILE *fp _AND
|
||||
_CONST char *fmt _AND
|
||||
va_list ap)
|
||||
{
|
||||
|
@ -257,7 +258,7 @@ _DEFUN(__sbprintf, (fp, fmt, ap),
|
|||
#endif
|
||||
|
||||
/* do the work, then copy any error status */
|
||||
ret = VFPRINTF (&fake, fmt, ap);
|
||||
ret = _VFPRINTF_R (rptr, &fake, fmt, ap);
|
||||
if (ret >= 0 && fflush(&fake))
|
||||
ret = EOF;
|
||||
if (fake._flags & __SERR)
|
||||
|
@ -541,7 +542,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
|
|||
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
|
||||
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
|
||||
fp->_file >= 0)
|
||||
return (__sbprintf (fp, fmt0, ap));
|
||||
return (__sbprintf (data, fp, fmt0, ap));
|
||||
|
||||
fmt = (char *)fmt0;
|
||||
uio.uio_iov = iovp = iov;
|
||||
|
|
Loading…
Reference in New Issue