From e71372faea4af670215b087a69c2b7432181a852 Mon Sep 17 00:00:00 2001 From: Thomas Fitzsimmons Date: Wed, 8 May 2002 00:12:49 +0000 Subject: * libc/include/sys/stdio.h: New file. * libc/sys/linux/sys/stdio.h: New file. * libc/include/stdio.h: Add declarations for flockfile, ftrylockfile, and funlockfile. Include . * libc/stdio/clearerr.c: Add file locking. * libc/stdio/fclose.c: Likewise. * libc/stdio/feof.c: Likewise. * libc/stdio/ferror.c: Likewise. * libc/stdio/fflush.c: Likewise. * libc/stdio/fgetc.c: Likewise. * libc/stdio/fgetpos.c: Likewise. * libc/stdio/fgets.c: Likewise. * libc/stdio/fileno.c: Likewise. * libc/stdio/fputc.c: Likewise. * libc/stdio/fputs.c: Likewise. * libc/stdio/fread.c: Likewise. * libc/stdio/freopen.c: Likewise. * libc/stdio/fseek.c: Likewise. * libc/stdio/ftell.c: Likewise. * libc/stdio/fwrite.c: Likewise. * libc/stdio/getc.c: Likewise. * libc/stdio/putc.c: Likewise. * libc/stdio/setvbuf.c: Likewise. * libc/stdio/ungetc.c: Likewise. * libc/stdio/vfprintf.c: Likewise. --- newlib/libc/stdio/fgets.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'newlib/libc/stdio/fgets.c') diff --git a/newlib/libc/stdio/fgets.c b/newlib/libc/stdio/fgets.c index d395d3344..46e190077 100644 --- a/newlib/libc/stdio/fgets.c +++ b/newlib/libc/stdio/fgets.c @@ -80,6 +80,7 @@ _DEFUN (fgets, (buf, n, fp), s = buf; + _flockfile(fp); #ifdef __SCLE if (fp->_flags & __SCLE) { @@ -92,8 +93,12 @@ _DEFUN (fgets, (buf, n, fp), break; } if (c == EOF && s == buf) - return NULL; + { + _funlockfile(fp); + return NULL; + } *s = 0; + _funlockfile(fp); return buf; } #endif @@ -110,7 +115,10 @@ _DEFUN (fgets, (buf, n, fp), { /* EOF: stop with partial or no line */ if (s == buf) - return 0; + { + _funlockfile(fp); + return 0; + } break; } len = fp->_r; @@ -133,6 +141,7 @@ _DEFUN (fgets, (buf, n, fp), fp->_p = t; (void) memcpy ((_PTR) s, (_PTR) p, len); s[len] = 0; + _funlockfile(fp); return (buf); } fp->_r -= len; @@ -142,5 +151,6 @@ _DEFUN (fgets, (buf, n, fp), } while ((n -= len) != 0); *s = 0; + _funlockfile(fp); return buf; } -- cgit v1.2.3