diff options
Diffstat (limited to 'libc/stdio/fgets.c')
-rw-r--r-- | libc/stdio/fgets.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libc/stdio/fgets.c b/libc/stdio/fgets.c index f26385d6a..311b7b290 100644 --- a/libc/stdio/fgets.c +++ b/libc/stdio/fgets.c @@ -51,6 +51,7 @@ fgets(char *buf, int n, FILE *fp) if (n <= 0) /* sanity check */ return (NULL); + FLOCKFILE(fp); _SET_ORIENTATION(fp, -1); s = buf; n--; /* leave space for NUL */ @@ -61,8 +62,10 @@ fgets(char *buf, int n, FILE *fp) if (fp->_r <= 0) { if (__srefill(fp)) { /* EOF/error: stop with partial or no line */ - if (s == buf) + if (s == buf) { + FUNLOCKFILE(fp); return (NULL); + } break; } } @@ -84,6 +87,7 @@ fgets(char *buf, int n, FILE *fp) fp->_p = t; (void)memcpy((void *)s, (void *)p, len); s[len] = '\0'; + FUNLOCKFILE(fp); return (buf); } fp->_r -= len; @@ -93,5 +97,6 @@ fgets(char *buf, int n, FILE *fp) n -= len; } *s = '\0'; + FUNLOCKFILE(fp); return (buf); } |