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/ungetc.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'newlib/libc/stdio/ungetc.c') diff --git a/newlib/libc/stdio/ungetc.c b/newlib/libc/stdio/ungetc.c index 418717e68..9e54e5ebf 100644 --- a/newlib/libc/stdio/ungetc.c +++ b/newlib/libc/stdio/ungetc.c @@ -73,6 +73,8 @@ ungetc (c, fp) if (c == EOF) return (EOF); + _flockfile(fp); + /* Ensure stdio has been initialized. ??? Might be able to remove this as some other stdio routine should have already been called to get the char we are un-getting. */ @@ -89,11 +91,17 @@ ungetc (c, fp) * Otherwise, flush any current write stuff. */ if ((fp->_flags & __SRW) == 0) - return EOF; + { + _funlockfile(fp); + return EOF; + } if (fp->_flags & __SWR) { if (fflush (fp)) - return EOF; + { + _funlockfile(fp); + return EOF; + } fp->_flags &= ~__SWR; fp->_w = 0; fp->_lbfsize = 0; @@ -110,9 +118,13 @@ ungetc (c, fp) if (HASUB (fp)) { if (fp->_r >= fp->_ub._size && __submore (fp)) - return EOF; + { + _funlockfile(fp); + return EOF; + } *--fp->_p = c; fp->_r++; + _funlockfile(fp); return c; } @@ -126,6 +138,7 @@ ungetc (c, fp) { fp->_p--; fp->_r++; + _funlockfile(fp); return c; } @@ -141,5 +154,6 @@ ungetc (c, fp) fp->_ubuf[sizeof (fp->_ubuf) - 1] = c; fp->_p = &fp->_ubuf[sizeof (fp->_ubuf) - 1]; fp->_r = 1; + _funlockfile(fp); return c; } -- cgit v1.2.3