Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorThomas Fitzsimmons <fitzsim@redhat.com>2002-05-08 04:12:49 +0400
committerThomas Fitzsimmons <fitzsim@redhat.com>2002-05-08 04:12:49 +0400
commite71372faea4af670215b087a69c2b7432181a852 (patch)
tree5adf28cd89c62937515cb7362e878ec45b51d190 /newlib
parent735bb7e7d7c52aedc7099411ef235fee206e7240 (diff)
* 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 <sys/stdio.h>. * 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.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog28
-rw-r--r--newlib/libc/include/stdio.h5
-rw-r--r--newlib/libc/include/sys/stdio.h14
-rw-r--r--newlib/libc/stdio/clearerr.c2
-rw-r--r--newlib/libc/stdio/fclose.c8
-rw-r--r--newlib/libc/stdio/feof.c6
-rw-r--r--newlib/libc/stdio/ferror.c6
-rw-r--r--newlib/libc/stdio/fflush.c13
-rw-r--r--newlib/libc/stdio/fgetc.c6
-rw-r--r--newlib/libc/stdio/fgetpos.c7
-rw-r--r--newlib/libc/stdio/fgets.c14
-rw-r--r--newlib/libc/stdio/fileno.c6
-rw-r--r--newlib/libc/stdio/fputc.c6
-rw-r--r--newlib/libc/stdio/fputs.c6
-rw-r--r--newlib/libc/stdio/fread.c14
-rw-r--r--newlib/libc/stdio/freopen.c5
-rw-r--r--newlib/libc/stdio/fseek.c13
-rw-r--r--newlib/libc/stdio/ftell.c9
-rw-r--r--newlib/libc/stdio/fwrite.c7
-rw-r--r--newlib/libc/stdio/getc.c7
-rw-r--r--newlib/libc/stdio/putc.c7
-rw-r--r--newlib/libc/stdio/setvbuf.c26
-rw-r--r--newlib/libc/stdio/ungetc.c20
-rw-r--r--newlib/libc/stdio/vfprintf.c6
-rw-r--r--newlib/libc/sys/linux/sys/stdio.h16
25 files changed, 222 insertions, 35 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index dfc3087ba..2158397c8 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,31 @@
+2002-05-07 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * 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 <sys/stdio.h>.
+ * 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.
+
2002-05-06 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/stdlib.h (a64l, l64a, _l64a_r): Added prototypes.
diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h
index 9fb9451e4..767438fac 100644
--- a/newlib/libc/include/stdio.h
+++ b/newlib/libc/include/stdio.h
@@ -47,6 +47,8 @@ extern "C" {
#include <sys/reent.h>
+#include <sys/stdio.h>
+
typedef _fpos_t fpos_t;
typedef struct __sFILE FILE;
@@ -220,6 +222,9 @@ FILE * _EXFUN(popen, (const char *, const char *));
int _EXFUN(putw, (int, FILE *));
void _EXFUN(setbuffer, (FILE *, char *, int));
int _EXFUN(setlinebuf, (FILE *));
+void _EXFUN(flockfile, (FILE *));
+int _EXFUN(ftrylockfile, (FILE *));
+void _EXFUN(funlockfile, (FILE *));
#endif
/*
diff --git a/newlib/libc/include/sys/stdio.h b/newlib/libc/include/sys/stdio.h
new file mode 100644
index 000000000..8177322a0
--- /dev/null
+++ b/newlib/libc/include/sys/stdio.h
@@ -0,0 +1,14 @@
+#ifndef _NEWLIB_STDIO_H
+#define _NEWLIB_STDIO_H
+
+/* Internal locking macros, used to protect stdio functions. In the
+ general case, expand to nothing. */
+#if !defined(_flockfile)
+# define _flockfile(fp)
+#endif
+
+#if !defined(_funlockfile)
+# define _funlockfile(fp)
+#endif
+
+#endif /* _NEWLIB_STDIO_H */
diff --git a/newlib/libc/stdio/clearerr.c b/newlib/libc/stdio/clearerr.c
index 861d9a211..6a1b0af3c 100644
--- a/newlib/libc/stdio/clearerr.c
+++ b/newlib/libc/stdio/clearerr.c
@@ -59,5 +59,7 @@ _VOID
_DEFUN (clearerr, (fp),
FILE * fp)
{
+ _flockfile(fp);
__sclearerr (fp);
+ _funlockfile(fp);
}
diff --git a/newlib/libc/stdio/fclose.c b/newlib/libc/stdio/fclose.c
index 3266d8a55..ad3d1e8e0 100644
--- a/newlib/libc/stdio/fclose.c
+++ b/newlib/libc/stdio/fclose.c
@@ -64,10 +64,15 @@ _DEFUN (fclose, (fp),
if (fp == NULL)
return (0); /* on NULL */
+ _flockfile(fp);
+
CHECK_INIT (fp);
if (fp->_flags == 0) /* not open! */
- return (0);
+ {
+ _funlockfile(fp);
+ return (0);
+ }
r = fp->_flags & __SWR ? fflush (fp) : 0;
if (fp->_close != NULL && (*fp->_close) (fp->_cookie) < 0)
r = EOF;
@@ -78,5 +83,6 @@ _DEFUN (fclose, (fp),
if (HASLB (fp))
FREELB (fp);
fp->_flags = 0; /* release this FILE for reuse */
+ _funlockfile(fp);
return (r);
}
diff --git a/newlib/libc/stdio/feof.c b/newlib/libc/stdio/feof.c
index 55f151bd4..b7981bded 100644
--- a/newlib/libc/stdio/feof.c
+++ b/newlib/libc/stdio/feof.c
@@ -36,5 +36,9 @@ int
_DEFUN (feof, (fp),
FILE * fp)
{
- return __sfeof (fp);
+ int result;
+ _flockfile(fp);
+ result = __sfeof (fp);
+ _funlockfile(fp);
+ return result;
}
diff --git a/newlib/libc/stdio/ferror.c b/newlib/libc/stdio/ferror.c
index 19fa78d14..ef17fd89d 100644
--- a/newlib/libc/stdio/ferror.c
+++ b/newlib/libc/stdio/ferror.c
@@ -63,5 +63,9 @@ int
_DEFUN (ferror, (fp),
FILE * fp)
{
- return __sferror (fp);
+ int result;
+ _flockfile(fp);
+ result = __sferror (fp);
+ _funlockfile(fp);
+ return result;
}
diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c
index 635e5a738..866bc83aa 100644
--- a/newlib/libc/stdio/fflush.c
+++ b/newlib/libc/stdio/fflush.c
@@ -69,11 +69,16 @@ _DEFUN (fflush, (fp),
if (fp == NULL)
return _fwalk (_REENT, fflush);
+ _flockfile(fp);
+
CHECK_INIT (fp);
t = fp->_flags;
if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL)
- return 0;
+ {
+ _funlockfile(fp);
+ return 0;
+ }
n = fp->_p - p; /* write this much */
/*
@@ -89,11 +94,13 @@ _DEFUN (fflush, (fp),
t = (*fp->_write) (fp->_cookie, (char *) p, n);
if (t <= 0)
{
- fp->_flags |= __SERR;
- return EOF;
+ fp->_flags |= __SERR;
+ _funlockfile(fp);
+ return EOF;
}
p += t;
n -= t;
}
+ _funlockfile(fp);
return 0;
}
diff --git a/newlib/libc/stdio/fgetc.c b/newlib/libc/stdio/fgetc.c
index 3d3d2c4ed..1160b67a7 100644
--- a/newlib/libc/stdio/fgetc.c
+++ b/newlib/libc/stdio/fgetc.c
@@ -42,5 +42,9 @@ int
_DEFUN (fgetc, (fp),
FILE * fp)
{
- return __sgetc (fp);
+ int result;
+ _flockfile(fp);
+ result = __sgetc (fp);
+ _funlockfile(fp);
+ return result;
}
diff --git a/newlib/libc/stdio/fgetpos.c b/newlib/libc/stdio/fgetpos.c
index 214021a84..ed6f5cfd3 100644
--- a/newlib/libc/stdio/fgetpos.c
+++ b/newlib/libc/stdio/fgetpos.c
@@ -53,9 +53,14 @@ _DEFUN (fgetpos, (fp, pos),
FILE * fp _AND
fpos_t * pos)
{
+ _flockfile(fp);
*pos = ftell (fp);
if (*pos != -1)
- return 0;
+ {
+ _funlockfile(fp);
+ return 0;
+ }
+ _funlockfile(fp);
return 1;
}
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;
}
diff --git a/newlib/libc/stdio/fileno.c b/newlib/libc/stdio/fileno.c
index d578c3ede..c9ecbb424 100644
--- a/newlib/libc/stdio/fileno.c
+++ b/newlib/libc/stdio/fileno.c
@@ -35,6 +35,10 @@ int
_DEFUN (fileno, (f),
FILE * f)
{
+ int result;
+ _flockfile(f);
CHECK_INIT (f);
- return __sfileno (f);
+ result = __sfileno (f);
+ _funlockfile(f);
+ return result;
}
diff --git a/newlib/libc/stdio/fputc.c b/newlib/libc/stdio/fputc.c
index 966a0dbf7..b945095e5 100644
--- a/newlib/libc/stdio/fputc.c
+++ b/newlib/libc/stdio/fputc.c
@@ -47,5 +47,9 @@ _DEFUN (fputc, (ch, file),
int ch _AND
FILE * file)
{
- return putc (ch, file);
+ int result;
+ _flockfile(file);
+ result = putc (ch, file);
+ _funlockfile(file);
+ return result;
}
diff --git a/newlib/libc/stdio/fputs.c b/newlib/libc/stdio/fputs.c
index 62ce98fb7..78758ce93 100644
--- a/newlib/libc/stdio/fputs.c
+++ b/newlib/libc/stdio/fputs.c
@@ -60,6 +60,7 @@ _DEFUN (fputs, (s, fp),
char _CONST * s _AND
FILE * fp)
{
+ int result;
struct __suio uio;
struct __siov iov;
@@ -67,5 +68,8 @@ _DEFUN (fputs, (s, fp),
iov.iov_len = uio.uio_resid = strlen (s);
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
- return __sfvwrite (fp, &uio);
+ _flockfile(fp);
+ result = __sfvwrite (fp, &uio);
+ _funlockfile(fp);
+ return result;
}
diff --git a/newlib/libc/stdio/fread.c b/newlib/libc/stdio/fread.c
index 38f791b6d..faca53735 100644
--- a/newlib/libc/stdio/fread.c
+++ b/newlib/libc/stdio/fread.c
@@ -122,6 +122,8 @@ _DEFUN (fread, (buf, size, count, fp),
if ((resid = count * size) == 0)
return 0;
+
+ _flockfile(fp);
if (fp->_r < 0)
fp->_r = 0;
total = resid;
@@ -139,8 +141,12 @@ _DEFUN (fread, (buf, size, count, fp),
/* no more input: return partial result */
#ifdef __SCLE
if (fp->_flags & __SCLE)
- return crlf(fp, buf, total-resid, 1) / size;
+ {
+ _funlockfile(fp);
+ return crlf(fp, buf, total-resid, 1) / size;
+ }
#endif
+ _funlockfile(fp);
return (total - resid) / size;
}
}
@@ -149,7 +155,11 @@ _DEFUN (fread, (buf, size, count, fp),
fp->_p += resid;
#ifdef __SCLE
if (fp->_flags & __SCLE)
- return crlf(fp, buf, total, 0) / size;
+ {
+ _funlockfile(fp);
+ return crlf(fp, buf, total, 0) / size;
+ }
#endif
+ _funlockfile(fp);
return count;
}
diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c
index 63f583375..ea61f0463 100644
--- a/newlib/libc/stdio/freopen.c
+++ b/newlib/libc/stdio/freopen.c
@@ -76,12 +76,15 @@ _DEFUN (freopen, (file, mode, fp),
int flags, oflags, e;
struct _reent *ptr;
+ _flockfile(fp);
+
CHECK_INIT (fp);
ptr = fp->_data;
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
(void) fclose (fp);
+ _funlockfile(fp);
return NULL;
}
@@ -137,6 +140,7 @@ _DEFUN (freopen, (file, mode, fp),
{ /* did not get it after all */
fp->_flags = 0; /* set it free */
ptr->_errno = e; /* restore in case _close clobbered */
+ _funlockfile(fp);
return NULL;
}
@@ -153,5 +157,6 @@ _DEFUN (freopen, (file, mode, fp),
fp->_flags |= __SCLE;
#endif
+ _funlockfile(fp);
return fp;
}
diff --git a/newlib/libc/stdio/fseek.c b/newlib/libc/stdio/fseek.c
index 1b7298914..10c6c532e 100644
--- a/newlib/libc/stdio/fseek.c
+++ b/newlib/libc/stdio/fseek.c
@@ -96,6 +96,8 @@ fseek (fp, offset, whence)
struct stat st;
int havepos;
+ _flockfile(fp);
+
/* Make sure stdio is set up. */
CHECK_INIT (fp);
@@ -115,6 +117,7 @@ fseek (fp, offset, whence)
if ((seekfn = fp->_seek) == NULL)
{
ptr->_errno = ESPIPE; /* ??? */
+ _funlockfile(fp);
return EOF;
}
@@ -138,6 +141,7 @@ fseek (fp, offset, whence)
{
curoff = (*seekfn) (fp->_cookie, (fpos_t) 0, SEEK_CUR);
if (curoff == -1L)
+ _funlockfile(fp);
return EOF;
}
if (fp->_flags & __SRD)
@@ -161,6 +165,7 @@ fseek (fp, offset, whence)
default:
ptr->_errno = EINVAL;
+ _funlockfile(fp);
return (EOF);
}
@@ -262,6 +267,7 @@ fseek (fp, offset, whence)
if (HASUB (fp))
FREEUB (fp);
fp->_flags &= ~__SEOF;
+ _funlockfile(fp);
return 0;
}
@@ -290,6 +296,7 @@ fseek (fp, offset, whence)
fp->_p += n;
fp->_r -= n;
}
+ _funlockfile(fp);
return 0;
/*
@@ -299,7 +306,10 @@ fseek (fp, offset, whence)
dumb:
if (fflush (fp) || (*seekfn) (fp->_cookie, offset, whence) == POS_ERR)
- return EOF;
+ {
+ _funlockfile(fp);
+ return EOF;
+ }
/* success: clear EOF indicator and discard ungetc() data */
if (HASUB (fp))
FREEUB (fp);
@@ -307,5 +317,6 @@ dumb:
fp->_r = 0;
/* fp->_w = 0; *//* unnecessary (I think...) */
fp->_flags &= ~__SEOF;
+ _funlockfile(fp);
return 0;
}
diff --git a/newlib/libc/stdio/ftell.c b/newlib/libc/stdio/ftell.c
index 6a8061816..8066acc3b 100644
--- a/newlib/libc/stdio/ftell.c
+++ b/newlib/libc/stdio/ftell.c
@@ -80,6 +80,8 @@ _DEFUN (ftell, (fp),
{
fpos_t pos;
+ _flockfile(fp);
+
/* Ensure stdio is set up. */
CHECK_INIT (fp);
@@ -87,6 +89,7 @@ _DEFUN (ftell, (fp),
if (fp->_seek == NULL)
{
fp->_data->_errno = ESPIPE;
+ _funlockfile(fp);
return -1L;
}
@@ -99,7 +102,10 @@ _DEFUN (ftell, (fp),
{
pos = (*fp->_seek) (fp->_cookie, (fpos_t) 0, SEEK_CUR);
if (pos == -1L)
- return pos;
+ {
+ _funlockfile(fp);
+ return pos;
+ }
}
if (fp->_flags & __SRD)
{
@@ -122,5 +128,6 @@ _DEFUN (ftell, (fp),
pos += fp->_p - fp->_bf._base;
}
+ _funlockfile(fp);
return pos;
}
diff --git a/newlib/libc/stdio/fwrite.c b/newlib/libc/stdio/fwrite.c
index 642fb274f..1c91632b8 100644
--- a/newlib/libc/stdio/fwrite.c
+++ b/newlib/libc/stdio/fwrite.c
@@ -98,7 +98,12 @@ _DEFUN (fwrite, (buf, size, count, fp),
* generally slow and since this occurs whenever size==0.
*/
+ _flockfile(fp);
if (__sfvwrite (fp, &uio) == 0)
- return count;
+ {
+ _funlockfile(fp);
+ return count;
+ }
+ _funlockfile(fp);
return (n - uio.uio_resid) / size;
}
diff --git a/newlib/libc/stdio/getc.c b/newlib/libc/stdio/getc.c
index 4b2509737..f7a2cac5a 100644
--- a/newlib/libc/stdio/getc.c
+++ b/newlib/libc/stdio/getc.c
@@ -74,7 +74,10 @@ int
getc (fp)
register FILE *fp;
{
+ int result;
+ _flockfile(fp);
/* CHECK_INIT is called (eventually) by __srefill. */
-
- return __sgetc (fp);
+ result = __sgetc (fp);
+ _funlockfile(fp);
+ return result;
}
diff --git a/newlib/libc/stdio/putc.c b/newlib/libc/stdio/putc.c
index 27a7a4280..7e53868ab 100644
--- a/newlib/libc/stdio/putc.c
+++ b/newlib/libc/stdio/putc.c
@@ -78,7 +78,10 @@ putc (c, fp)
int c;
register FILE *fp;
{
+ int result;
+ _flockfile(fp);
/* CHECK_INIT is (eventually) called by __swbuf. */
-
- return __sputc (c, fp);
+ result = __sputc (c, fp);
+ _funlockfile(fp);
+ return result;
}
diff --git a/newlib/libc/stdio/setvbuf.c b/newlib/libc/stdio/setvbuf.c
index 357ea5142..d44cdba5f 100644
--- a/newlib/libc/stdio/setvbuf.c
+++ b/newlib/libc/stdio/setvbuf.c
@@ -103,6 +103,9 @@ _DEFUN (setvbuf, (fp, buf, mode, size),
register size_t size)
{
int ret = 0;
+
+ _flockfile(fp);
+
CHECK_INIT (fp);
/*
@@ -111,7 +114,10 @@ _DEFUN (setvbuf, (fp, buf, mode, size),
*/
if ((mode != _IOFBF && mode != _IOLBF && mode != _IONBF) || (int)(_POINTER_INT) size < 0)
- return (EOF);
+ {
+ _funlockfile(fp);
+ return (EOF);
+ }
/*
* Write current buffer, if any; drop read count, if any.
@@ -145,15 +151,16 @@ _DEFUN (setvbuf, (fp, buf, mode, size),
size = BUFSIZ;
}
if (buf == NULL)
- {
- /* Can't allocate it, let's try another approach */
+ {
+ /* Can't allocate it, let's try another approach */
nbf:
- fp->_flags |= __SNBF;
- fp->_w = 0;
- fp->_bf._base = fp->_p = fp->_nbuf;
- fp->_bf._size = 1;
- return (ret);
- }
+ fp->_flags |= __SNBF;
+ fp->_w = 0;
+ fp->_bf._base = fp->_p = fp->_nbuf;
+ fp->_bf._size = 1;
+ _funlockfile(fp);
+ return (ret);
+ }
fp->_flags |= __SMBF;
}
/*
@@ -186,5 +193,6 @@ nbf:
if (fp->_flags & __SWR)
fp->_w = fp->_flags & (__SLBF | __SNBF) ? 0 : size;
+ _funlockfile(fp);
return 0;
}
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;
}
diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c
index 302b5aab9..27cc6d911 100644
--- a/newlib/libc/stdio/vfprintf.c
+++ b/newlib/libc/stdio/vfprintf.c
@@ -298,8 +298,12 @@ _DEFUN (VFPRINTF, (fp, fmt0, ap),
_CONST char *fmt0 _AND
va_list ap)
{
+ int result;
+ _flockfile(fp);
CHECK_INIT (fp);
- return _VFPRINTF_R (fp->_data, fp, fmt0, ap);
+ result = _VFPRINTF_R (fp->_data, fp, fmt0, ap);
+ _funlockfile(fp);
+ return result;
}
int
diff --git a/newlib/libc/sys/linux/sys/stdio.h b/newlib/libc/sys/linux/sys/stdio.h
new file mode 100644
index 000000000..859406f3f
--- /dev/null
+++ b/newlib/libc/sys/linux/sys/stdio.h
@@ -0,0 +1,16 @@
+#ifndef _NEWLIB_STDIO_H
+#define _NEWLIB_STDIO_H
+
+/* Internal locking macros, used to protect stdio functions. In the
+ linux case, expand to flockfile, and funlockfile, both defined in
+ LinuxThreads. */
+#if !defined(__SINGLE_THREAD__)
+# if !defined(_flockfile)
+# define _flockfile(fp) /* FIXME: Uncomment when LinuxThreads is in: flockfile(fp) */
+# endif
+# if !defined(_funlockfile)
+# define _funlockfile(fp) /* FIXME: Uncomment when LinuxThreads is in: funlockfile(fp) */
+# endif
+#endif /* __SINGLE_THREAD__ */
+
+#endif /* _NEWLIB_STDIO_H */