aboutsummaryrefslogtreecommitdiffstats
path: root/libc/stdio/fgetln.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdio/fgetln.c')
-rw-r--r--libc/stdio/fgetln.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/libc/stdio/fgetln.c b/libc/stdio/fgetln.c
index 95a5b31d9..0947dd852 100644
--- a/libc/stdio/fgetln.c
+++ b/libc/stdio/fgetln.c
@@ -71,19 +71,18 @@ char *
fgetln(FILE *fp, size_t *lenp)
{
unsigned char *p;
+ char *ret;
size_t len;
size_t off;
+ FLOCKFILE(fp);
+
/* make sure there is input */
- if (fp->_r <= 0 && __srefill(fp)) {
- *lenp = 0;
- return (NULL);
- }
+ if (fp->_r <= 0 && __srefill(fp))
+ goto error;
/* look for a newline in the input */
if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) {
- char *ret;
-
/*
* Found one. Flag buffer as modified to keep fseek from
* `optimising' a backward seek, in case the user stomps on
@@ -95,6 +94,7 @@ fgetln(FILE *fp, size_t *lenp)
fp->_flags |= __SMOD;
fp->_r -= len;
fp->_p = p;
+ FUNLOCKFILE(fp);
return (ret);
}
@@ -139,12 +139,15 @@ fgetln(FILE *fp, size_t *lenp)
break;
}
*lenp = len;
+ ret = (char *)fp->_lb._base;
#ifdef notdef
- fp->_lb._base[len] = '\0';
+ ret[len] = '\0';
#endif
- return ((char *)fp->_lb._base);
+ FUNLOCKFILE(fp);
+ return (ret);
error:
*lenp = 0; /* ??? */
+ FUNLOCKFILE(fp);
return (NULL); /* ??? */
}