From 1143b5e42a7816a7665798bcab7d5db4a37935b3 Mon Sep 17 00:00:00 2001 From: deischen Date: Sun, 11 Feb 2001 22:06:43 +0000 Subject: libc MT-safety, part 2. Add a lock to FILE. flockfile and friends are now implemented (for the most part) in libc. flockfile_debug is implemented in libc_r; I suppose it's about time to kill it but will do it in a future commit. Fix a potential deadlock in _fwalk in a threaded environment. A file flag (__SIGN) was added to stdio.h that, when set, tells _fwalk to ignore it in its walk. This seemed to be needed in refill.c because each file needs to be locked when flushing. Add a stub for pthread_self in libc. This is needed by flockfile which is allowed by POSIX to be recursive. Make fgetpos() error return value (-1) match man page. Remove recursive calls to locked functions (stdio); I think I've got them all, but I may have missed a couple. A few K&R -> ANSI conversions along with removal of a few instances of "register". $Id$ -> $FreeBSD$ in libc/stdio/rget.c Not objected to: -arch, a few months ago --- lib/libc/stdio/fgetln.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'lib/libc/stdio/fgetln.c') diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c index 3987b0d..c607a9c 100644 --- a/lib/libc/stdio/fgetln.c +++ b/lib/libc/stdio/fgetln.c @@ -42,9 +42,12 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" +#include "libc_private.h" #include "local.h" /* @@ -54,10 +57,8 @@ static const char rcsid[] = * so we add 1 here. #endif */ -int -__slbexpand(fp, newsize) - FILE *fp; - size_t newsize; +static int +slbexpand(FILE *fp, size_t newsize) { void *p; @@ -81,23 +82,23 @@ __slbexpand(fp, newsize) * it if they wish. Thus, we set __SMOD in case the caller does. */ char * -fgetln(fp, lenp) - register FILE *fp; - size_t *lenp; +fgetln(FILE *fp, size_t *lenp) { - register unsigned char *p; - register size_t len; + unsigned char *p; + size_t len; size_t off; + FLOCKFILE(fp); /* make sure there is input */ if (fp->_r <= 0 && __srefill(fp)) { *lenp = 0; + FUNLOCKFILE(fp); return (NULL); } /* look for a newline in the input */ if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) { - register char *ret; + char *ret; /* * Found one. Flag buffer as modified to keep fseek from @@ -110,6 +111,7 @@ fgetln(fp, lenp) fp->_flags |= __SMOD; fp->_r -= len; fp->_p = p; + FUNLOCKFILE(fp); return (ret); } @@ -124,14 +126,14 @@ fgetln(fp, lenp) #define OPTIMISTIC 80 for (len = fp->_r, off = 0;; len += fp->_r) { - register size_t diff; + size_t diff; /* * Make sure there is room for more bytes. Copy data from * file buffer to line buffer, refill file and look for * newline. The loop stops only when we find a newline. */ - if (__slbexpand(fp, len + OPTIMISTIC)) + if (slbexpand(fp, len + OPTIMISTIC)) goto error; (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, len - off); @@ -145,7 +147,7 @@ fgetln(fp, lenp) p++; diff = p - fp->_p; len += diff; - if (__slbexpand(fp, len)) + if (slbexpand(fp, len)) goto error; (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, diff); @@ -157,9 +159,11 @@ fgetln(fp, lenp) #ifdef notdef fp->_lb._base[len] = 0; #endif + FUNLOCKFILE(fp); return ((char *)fp->_lb._base); error: *lenp = 0; /* ??? */ + FUNLOCKFILE(fp); return (NULL); /* ??? */ } -- cgit v1.1