diff options
| author | christos <christos@NetBSD.org> | 2006-10-27 19:59:58 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2006-10-27 19:59:58 +0000 |
| commit | abca035cf37bdc610cd36b5d7e4d1abb347d4402 (patch) | |
| tree | 7407e14c54b8ed27955542a5bc90513c28a548ee /lib/libc/stdio/vfprintf.c | |
| parent | eb6da7fc35bd03da95bb4848f71cb5afc14dbbca (diff) | |
Add signal-safe versions of snprintf and vsnprintf
Diffstat (limited to 'lib/libc/stdio/vfprintf.c')
| -rw-r--r-- | lib/libc/stdio/vfprintf.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index f5fc077583b..d37d3b03277 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfprintf.c,v 1.50 2006/02/16 23:26:19 christos Exp $ */ +/* $NetBSD: vfprintf.c,v 1.51 2006/10/27 19:59:58 christos Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -37,7 +37,7 @@ #if 0 static char *sccsid = "@(#)vfprintf.c 5.50 (Berkeley) 12/16/92"; #else -__RCSID("$NetBSD: vfprintf.c,v 1.50 2006/02/16 23:26:19 christos Exp $"); +__RCSID("$NetBSD: vfprintf.c,v 1.51 2006/10/27 19:59:58 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -73,6 +73,7 @@ static int __sbprintf __P((FILE *, const char *, va_list)) * Flush out all the vectors defined by the given uio, * then reset it so that it can be reused. */ +/* NB: async-signal-safe when fp->_flags & __SAFE */ static int __sprint(fp, uio) FILE *fp; @@ -192,6 +193,7 @@ vfprintf(fp, fmt0, ap) +/* NB: async-signal-safe when fp->_flags & __SAFE */ int __vfprintf_unlocked(fp, fmt0, ap) FILE *fp; @@ -335,11 +337,16 @@ __vfprintf_unlocked(fp, fmt0, ap) */ for (;;) { cp = fmt; - while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) { - fmt += n; - if (wc == '%') { - fmt--; - break; + if (fp->_flags & __SAFE) { + for (; *fmt &&*fmt != '%'; fmt++) + continue; + } else { + while ((n = mbrtowc(&wc, fmt, MB_CUR_MAX, &ps)) > 0) { + fmt += n; + if (wc == '%') { + fmt--; + break; + } } } if ((m = fmt - cp) != 0) { @@ -501,6 +508,14 @@ reswitch: switch (ch) { size = 3; break; } + if (fp->_flags & __SAFE) { + if (ch == 'E' || ch == 'F' || ch == 'G') + cp = "UNK"; + else + cp = "unk"; + size = 3; + break; + } flags |= FPT; if (dtoaresult) |
