diff options
author | deischen <deischen@FreeBSD.org> | 2001-01-24 13:01:12 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2001-01-24 13:01:12 +0000 |
commit | 1635c221b7b2678beeeb2b5fa728edd7c8c3735b (patch) | |
tree | d7d4f61b9e319a781a335702fe846592726c22b9 /lib/libc/stdio/vfscanf.c | |
parent | 08685e9e9fd9de1e8dc51cada55659344adaf0cc (diff) | |
download | FreeBSD-src-1635c221b7b2678beeeb2b5fa728edd7c8c3735b.zip FreeBSD-src-1635c221b7b2678beeeb2b5fa728edd7c8c3735b.tar.gz |
Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions. If the threads library is linked in, the real
pthread functions will pulled in.
Use the following convention for system calls wrapped by the
threads library:
__sys_foo - actual system call
_foo - weak definition to __sys_foo
foo - weak definition to __sys_foo
Change all libc uses of system calls wrapped by the threads
library from foo to _foo. In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde). All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes. <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.
Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE. We have recursive mutexes, but would like to avoid
using them if possible.
Remove uneeded includes of <errno.h> from a few files.
Add $FreeBSD$ to a few files in order to pass commitprep.
Approved by: -arch
Diffstat (limited to 'lib/libc/stdio/vfscanf.c')
-rw-r--r-- | lib/libc/stdio/vfscanf.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index 6a83216..04ce95c 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -42,6 +42,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h> @@ -51,8 +52,10 @@ static const char rcsid[] = #include <varargs.h> #endif #include <string.h> +#include "un-namespace.h" #include "collate.h" +#include "libc_private.h" #include "local.h" #define FLOATING_POINT @@ -100,21 +103,32 @@ static const char rcsid[] = static u_char *__sccl(char *, u_char *); /* - * vfscanf + * __vfscanf - MT-safe version */ int -__svfscanf(fp, fmt0, ap) - register FILE *fp; - char const *fmt0; - va_list ap; +__vfscanf(FILE *fp, char const *fmt0, va_list ap) { - register u_char *fmt = (u_char *)fmt0; - register int c; /* character from format, or conversion */ - register size_t width; /* field width, or 0 */ - register char *p; /* points into all kinds of strings */ - register int n; /* handy integer */ - register int flags; /* flags as defined above */ - register char *p0; /* saves original value of p when necessary */ + int ret; + + FLOCKFILE(fp); + ret = __svfscanf(fp, fmt0, ap); + FUNLOCKFILE(fp); + return (ret); +} + +/* + * __svfscanf - non-MT-safe version of __vfscanf + */ +int +__svfscanf(FILE *fp, char const *fmt0, va_list ap) +{ + u_char *fmt = (u_char *)fmt0; + int c; /* character from format, or conversion */ + size_t width; /* field width, or 0 */ + char *p; /* points into all kinds of strings */ + int n; /* handy integer */ + int flags; /* flags as defined above */ + char *p0; /* saves original value of p when necessary */ int nassigned; /* number of fields assigned */ int nconversions; /* number of conversions */ int nread; /* number of characters consumed from fp */ @@ -539,13 +553,13 @@ literal: */ if (flags & NDIGITS) { if (p > buf) - (void) ungetc(*(u_char *)--p, fp); + (void) __ungetc(*(u_char *)--p, fp); goto match_failure; } c = ((u_char *)p)[-1]; if (c == 'x' || c == 'X') { --p; - (void) ungetc(c, fp); + (void) __ungetc(c, fp); } if ((flags & SUPPRESS) == 0) { u_quad_t res; @@ -635,16 +649,16 @@ literal: if (flags & EXPOK) { /* no digits at all */ while (p > buf) - ungetc(*(u_char *)--p, fp); + __ungetc(*(u_char *)--p, fp); goto match_failure; } /* just a bad exponent (e and maybe sign) */ c = *(u_char *)--p; if (c != 'e' && c != 'E') { - (void) ungetc(c, fp);/* sign */ + (void) __ungetc(c, fp);/* sign */ c = *(u_char *)--p; } - (void) ungetc(c, fp); + (void) __ungetc(c, fp); } if ((flags & SUPPRESS) == 0) { double res; |