diff options
| author | David Xu <davidxu@FreeBSD.org> | 2005-12-16 02:50:53 +0000 |
|---|---|---|
| committer | David Xu <davidxu@FreeBSD.org> | 2005-12-16 02:50:53 +0000 |
| commit | 3b52e4d1b797c7c281cd73c515515e4b6c3867fe (patch) | |
| tree | 6ae4ec26d50bc59ff2d9306207a3b957bc977ae6 | |
| parent | 74a96f4337c140c96fb6445887fe045d8b3ee43f (diff) | |
Notes
| -rw-r--r-- | lib/libc/stdio/fread.c | 23 | ||||
| -rw-r--r-- | lib/libc/stdio/local.h | 3 | ||||
| -rw-r--r-- | lib/libc/stdio/vfscanf.c | 2 |
3 files changed, 19 insertions, 9 deletions
diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c index 73c7c1922eb0d..3edb84ad479d0 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -47,11 +47,23 @@ __FBSDID("$FreeBSD$"); #include "local.h" #include "libc_private.h" +/* + * MT-safe version + */ + size_t -fread(buf, size, count, fp) - void * __restrict buf; - size_t size, count; - FILE * __restrict fp; +fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp) +{ + int ret; + + FLOCKFILE(fp); + ret = __fread(buf, size, count, fp); + FUNLOCKFILE(fp); + return (ret); +} + +size_t +__fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp) { size_t resid; char *p; @@ -65,7 +77,6 @@ fread(buf, size, count, fp) */ if ((resid = count * size) == 0) return (0); - FLOCKFILE(fp); ORIENT(fp, -1); if (fp->_r < 0) fp->_r = 0; @@ -79,13 +90,11 @@ fread(buf, size, count, fp) resid -= r; if (__srefill(fp)) { /* no more input: return partial result */ - FUNLOCKFILE(fp); return ((total - resid) / size); } } (void)memcpy((void *)p, (void *)fp->_p, resid); fp->_r -= resid; fp->_p += resid; - FUNLOCKFILE(fp); return (count); } diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h index 74c3238357ace..de038fad15157 100644 --- a/lib/libc/stdio/local.h +++ b/lib/libc/stdio/local.h @@ -78,7 +78,8 @@ extern int __vfscanf(FILE *, const char *, __va_list); extern int __vfwprintf(FILE *, const wchar_t *, __va_list); extern int __vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list); - +extern size_t __fread(void * __restrict buf, size_t size, size_t count, + FILE * __restrict fp); extern int __sdidinit; diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index ea3004cf15b1b..27df280aa96f9 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -412,7 +412,7 @@ literal: } nread += sum; } else { - size_t r = fread((void *)va_arg(ap, char *), 1, + size_t r = __fread((void *)va_arg(ap, char *), 1, width, fp); if (r == 0) |
