diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2011-11-08 18:30:43 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2011-11-08 18:30:43 +0000 |
commit | 2963a5b2ecb7e11e1675c90a84a50038d6097709 (patch) | |
tree | 531d3e7fae4b95db10cd454efa03734841d0d25f | |
parent | 4f14cc69ba971941b32eddc685568fa3a2e80471 (diff) |
Make __svfscanf() the unlocked, core of vfscanf() and use it in
sscanf()/vsscanf() where locking is unnecessary.
ok millert@
-rw-r--r-- | lib/libc/stdio/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/stdio/__svfscanf.c | 26 | ||||
-rw-r--r-- | lib/libc/stdio/local.h | 3 | ||||
-rw-r--r-- | lib/libc/stdio/sscanf.c | 4 | ||||
-rw-r--r-- | lib/libc/stdio/vfscanf.c | 28 | ||||
-rw-r--r-- | lib/libc/stdio/vsscanf.c | 4 |
6 files changed, 23 insertions, 46 deletions
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc index 7496f06b579..b73bd4b877f 100644 --- a/lib/libc/stdio/Makefile.inc +++ b/lib/libc/stdio/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.19 2011/10/16 13:20:51 stsp Exp $ +# $OpenBSD: Makefile.inc,v 1.20 2011/11/08 18:30:42 guenther Exp $ # stdio sources .PATH: ${LIBCSRCDIR}/stdio @@ -14,7 +14,7 @@ SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \ scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c sscanf.c \ stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vasprintf.c vfprintf.c \ vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c vsscanf.c \ - wbuf.c wsetup.c flockfile.c __svfscanf.c \ + wbuf.c wsetup.c flockfile.c \ fgetwc.c fgetws.c fputwc.c fputws.c fwide.c getwc.c getwchar.c \ putwc.c putwchar.c ungetwc.c \ fwprintf.c swprintf.c vfwprintf.c vswprintf.c vwprintf.c wprintf.c \ diff --git a/lib/libc/stdio/__svfscanf.c b/lib/libc/stdio/__svfscanf.c deleted file mode 100644 index 3040fba4c72..00000000000 --- a/lib/libc/stdio/__svfscanf.c +++ /dev/null @@ -1,26 +0,0 @@ -/* $OpenBSD: __svfscanf.c,v 1.1 2005/05/11 18:39:19 espie Exp $ */ - -/* - * Copyright (c) 2005 Marc Espie <espie@openbsd.org> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/cdefs.h> - -#ifdef __indr_reference -__indr_reference(vfscanf, __svfscanf); -#else -# define VFSCANF __svfscanf -# include "vfscanf.c" -#endif diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h index 21190207538..0ebe1158116 100644 --- a/lib/libc/stdio/local.h +++ b/lib/libc/stdio/local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: local.h,v 1.19 2011/10/16 13:20:51 stsp Exp $ */ +/* $OpenBSD: local.h,v 1.20 2011/11/08 18:30:42 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -59,6 +59,7 @@ int __sflags(const char *, int *); wint_t __fgetwc_unlock(FILE *); wint_t __ungetwc(wint_t, FILE *); int __vfprintf(FILE *, const char *, __va_list); +int __svfscanf(FILE * __restrict, const char * __restrict, __va_list); int __vfwprintf(FILE * __restrict, const wchar_t * __restrict, __va_list); int __vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list); diff --git a/lib/libc/stdio/sscanf.c b/lib/libc/stdio/sscanf.c index ca6b33c9e3c..e371ca693c1 100644 --- a/lib/libc/stdio/sscanf.c +++ b/lib/libc/stdio/sscanf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sscanf.c,v 1.13 2011/05/30 18:48:33 martynas Exp $ */ +/* $OpenBSD: sscanf.c,v 1.14 2011/11/08 18:30:42 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -60,7 +60,7 @@ sscanf(const char *str, const char *fmt, ...) f._read = eofread; f._lb._base = NULL; va_start(ap, fmt); - ret = vfscanf(&f, fmt, ap); + ret = __svfscanf(&f, fmt, ap); va_end(ap); return (ret); } diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index 16bbbbfc126..42c9dfa15b6 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfscanf.c,v 1.27 2011/07/03 17:57:47 martynas Exp $ */ +/* $OpenBSD: vfscanf.c,v 1.28 2011/11/08 18:30:42 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -90,15 +90,11 @@ static u_char *__sccl(char *, u_char *); -#if !defined(VFSCANF) -#define VFSCANF vfscanf -#endif - /* - * vfscanf + * Internal, unlocked version of vfscanf */ int -VFSCANF(FILE *fp, const char *fmt0, __va_list ap) +__svfscanf(FILE *fp, const char *fmt0, __va_list ap) { u_char *fmt = (u_char *)fmt0; int c; /* character from format, or conversion */ @@ -117,7 +113,6 @@ VFSCANF(FILE *fp, const char *fmt0, __va_list ap) static short basefix[17] = { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; - FLOCKFILE(fp); _SET_ORIENTATION(fp, -1); nassigned = 0; @@ -125,10 +120,8 @@ VFSCANF(FILE *fp, const char *fmt0, __va_list ap) base = 0; /* XXX just to keep gcc happy */ for (;;) { c = *fmt++; - if (c == 0) { - FUNLOCKFILE(fp); + if (c == 0) return (nassigned); - } if (isspace(c)) { while ((fp->_r > 0 || __srefill(fp) == 0) && isspace(*fp->_p)) @@ -294,7 +287,6 @@ literal: * Disgusting backwards compatibility hacks. XXX */ case '\0': /* compat */ - FUNLOCKFILE(fp); return (EOF); default: /* compat */ @@ -697,7 +689,6 @@ input_failure: if (nassigned == 0) nassigned = -1; match_failure: - FUNLOCKFILE(fp); return (nassigned); } @@ -796,3 +787,14 @@ doswitch: } /* NOTREACHED */ } + +int +vfscanf(FILE *fp, const char *fmt0, __va_list ap) +{ + int r; + + FLOCKFILE(fp); + r = __svfscanf(fp, fmt0, ap); + FUNLOCKFILE(fp); + return (r); +} diff --git a/lib/libc/stdio/vsscanf.c b/lib/libc/stdio/vsscanf.c index 47c1ae61d73..71eb7529879 100644 --- a/lib/libc/stdio/vsscanf.c +++ b/lib/libc/stdio/vsscanf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vsscanf.c,v 1.11 2006/01/06 18:53:04 millert Exp $ */ +/* $OpenBSD: vsscanf.c,v 1.12 2011/11/08 18:30:42 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -55,5 +55,5 @@ vsscanf(const char *str, const char *fmt, __va_list ap) f._bf._size = f._r = strlen(str); f._read = eofread; f._lb._base = NULL; - return (vfscanf(&f, fmt, ap)); + return (__svfscanf(&f, fmt, ap)); } |