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
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2009-04-25 02:52:52 +0400
committerJeff Johnston <jjohnstn@redhat.com>2009-04-25 02:52:52 +0400
commitbcde12940007e836f7b831f1cdfda8dc2bda0c58 (patch)
treed9894d46eb51edf603939d8506bf0b5f97b9fa87 /newlib/libc
parent35f31b6a983710aa9a2bd7e308d1567f326f3f5f (diff)
2009-04-24 Jeff johnston <jjohnstn@redhat.com>
* libc/stdio/fgetc.c: Make sure sfp lock is acquired before the file lock and released before the file lock to avoid a deadlock scenario. * libc/stdio/fgets.c: Ditto. * libc/stdio/fgetwc.c: Ditto. * libc/stdio/fgetws.c: Ditto. * libc/stdio/fread.c: Ditto. * libc/stdio/fseek.c: Ditto. * libc/stdio/getc.c: Ditto. * libc/stdio/getdelim.c: Ditto. * libc/stdio/gets.c: Ditto.
Diffstat (limited to 'newlib/libc')
-rw-r--r--newlib/libc/stdio/fgetc.c2
-rw-r--r--newlib/libc/stdio/fgets.c6
-rw-r--r--newlib/libc/stdio/fgetwc.c2
-rw-r--r--newlib/libc/stdio/fgetws.c3
-rw-r--r--newlib/libc/stdio/fread.c7
-rw-r--r--newlib/libc/stdio/fseek.c10
-rw-r--r--newlib/libc/stdio/getc.c4
-rw-r--r--newlib/libc/stdio/getdelim.c2
-rw-r--r--newlib/libc/stdio/gets.c3
9 files changed, 39 insertions, 0 deletions
diff --git a/newlib/libc/stdio/fgetc.c b/newlib/libc/stdio/fgetc.c
index e275cfeeb..9837a2ebc 100644
--- a/newlib/libc/stdio/fgetc.c
+++ b/newlib/libc/stdio/fgetc.c
@@ -93,9 +93,11 @@ _DEFUN(fgetc, (fp),
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
int result;
CHECK_INIT(_REENT, fp);
+ __sfp_lock_acquire ();
_flockfile (fp);
result = __sgetc_r (_REENT, fp);
_funlockfile (fp);
+ __sfp_lock_release ();
return result;
#else
return _fgetc_r (_REENT, fp);
diff --git a/newlib/libc/stdio/fgets.c b/newlib/libc/stdio/fgets.c
index 7f02e3fcb..21bfdd4c6 100644
--- a/newlib/libc/stdio/fgets.c
+++ b/newlib/libc/stdio/fgets.c
@@ -98,6 +98,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
CHECK_INIT(ptr, fp);
+ __sfp_lock_acquire ();
_flockfile (fp);
#ifdef __SCLE
if (fp->_flags & __SCLE)
@@ -113,10 +114,12 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
if (c == EOF && s == buf)
{
_funlockfile (fp);
+ __sfp_lock_release ();
return NULL;
}
*s = 0;
_funlockfile (fp);
+ __sfp_lock_release ();
return buf;
}
#endif
@@ -135,6 +138,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
if (s == buf)
{
_funlockfile (fp);
+ __sfp_lock_release ();
return 0;
}
break;
@@ -160,6 +164,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
_CAST_VOID memcpy ((_PTR) s, (_PTR) p, len);
s[len] = 0;
_funlockfile (fp);
+ __sfp_lock_release ();
return (buf);
}
fp->_r -= len;
@@ -170,6 +175,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
while ((n -= len) != 0);
*s = 0;
_funlockfile (fp);
+ __sfp_lock_release ();
return buf;
}
diff --git a/newlib/libc/stdio/fgetwc.c b/newlib/libc/stdio/fgetwc.c
index 38a79bc7c..f4c81ddb9 100644
--- a/newlib/libc/stdio/fgetwc.c
+++ b/newlib/libc/stdio/fgetwc.c
@@ -164,10 +164,12 @@ _DEFUN(_fgetwc_r, (ptr, fp),
{
wint_t r;
+ __sfp_lock_acquire ();
_flockfile (fp);
ORIENT(fp, 1);
r = __fgetwc (ptr, fp);
_funlockfile (fp);
+ __sfp_lock_release ();
return r;
}
diff --git a/newlib/libc/stdio/fgetws.c b/newlib/libc/stdio/fgetws.c
index 2784f1513..3dbae06cb 100644
--- a/newlib/libc/stdio/fgetws.c
+++ b/newlib/libc/stdio/fgetws.c
@@ -93,6 +93,7 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
const char *src;
unsigned char *nl;
+ __sfp_lock_acquire ();
_flockfile (fp);
ORIENT (fp, 1);
@@ -143,10 +144,12 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
goto error;
*wsp++ = L'\0';
_funlockfile (fp);
+ __sfp_lock_release ();
return ws;
error:
_funlockfile (fp);
+ __sfp_lock_release ();
return NULL;
}
diff --git a/newlib/libc/stdio/fread.c b/newlib/libc/stdio/fread.c
index a39e9d85f..dda2044fe 100644
--- a/newlib/libc/stdio/fread.c
+++ b/newlib/libc/stdio/fread.c
@@ -146,6 +146,7 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
CHECK_INIT(ptr, fp);
+ __sfp_lock_acquire ();
_flockfile (fp);
ORIENT (fp, -1);
if (fp->_r < 0)
@@ -196,10 +197,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
+ __sfp_lock_release ();
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
}
#endif
_funlockfile (fp);
+ __sfp_lock_release ();
return (total - resid) / size;
}
}
@@ -221,10 +224,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
+ __sfp_lock_release ();
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
}
#endif
_funlockfile (fp);
+ __sfp_lock_release ();
return (total - resid) / size;
}
}
@@ -238,10 +243,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
if (fp->_flags & __SCLE)
{
_funlockfile (fp);
+ __sfp_lock_release ();
return crlf_r(ptr, fp, buf, total, 0) / size;
}
#endif
_funlockfile (fp);
+ __sfp_lock_release ();
return count;
}
diff --git a/newlib/libc/stdio/fseek.c b/newlib/libc/stdio/fseek.c
index 4d5fda4fe..526ae4ccb 100644
--- a/newlib/libc/stdio/fseek.c
+++ b/newlib/libc/stdio/fseek.c
@@ -138,6 +138,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
CHECK_INIT (ptr, fp);
+ __sfp_lock_acquire ();
_flockfile (fp);
/* If we've been doing some writing, and we're in append mode
@@ -155,6 +156,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
{
ptr->_errno = ESPIPE; /* ??? */
_funlockfile (fp);
+ __sfp_lock_release ();
return EOF;
}
@@ -180,6 +182,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
if (curoff == -1L)
{
_funlockfile (fp);
+ __sfp_lock_release ();
return EOF;
}
}
@@ -205,6 +208,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
default:
ptr->_errno = EINVAL;
_funlockfile (fp);
+ __sfp_lock_release ();
return (EOF);
}
@@ -263,6 +267,8 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
if ((long)target != target)
{
ptr->_errno = EOVERFLOW;
+ _funlockfile (fp);
+ __sfp_lock_release ();
return EOF;
}
@@ -319,6 +325,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
fp->_flags &= ~__SEOF;
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
+ __sfp_lock_release ();
return 0;
}
@@ -349,6 +356,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
}
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
+ __sfp_lock_release ();
return 0;
/*
@@ -361,6 +369,7 @@ dumb:
|| seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
{
_funlockfile (fp);
+ __sfp_lock_release ();
return EOF;
}
/* success: clear EOF indicator and discard ungetc() data */
@@ -379,6 +388,7 @@ dumb:
fp->_flags &= ~__SNPT;
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
_funlockfile (fp);
+ __sfp_lock_release ();
return 0;
}
diff --git a/newlib/libc/stdio/getc.c b/newlib/libc/stdio/getc.c
index 5b1fa888a..544ac734c 100644
--- a/newlib/libc/stdio/getc.c
+++ b/newlib/libc/stdio/getc.c
@@ -92,9 +92,11 @@ _DEFUN(_getc_r, (ptr, fp),
{
int result;
CHECK_INIT (ptr, fp);
+ __sfp_lock_acquire ();
_flockfile (fp);
result = __sgetc_r (ptr, fp);
_funlockfile (fp);
+ __sfp_lock_release ();
return result;
}
@@ -106,9 +108,11 @@ _DEFUN(getc, (fp),
{
int result;
CHECK_INIT (_REENT, fp);
+ __sfp_lock_acquire ();
_flockfile (fp);
result = __sgetc_r (_REENT, fp);
_funlockfile (fp);
+ __sfp_lock_release ();
return result;
}
diff --git a/newlib/libc/stdio/getdelim.c b/newlib/libc/stdio/getdelim.c
index 23fc50218..41460ab42 100644
--- a/newlib/libc/stdio/getdelim.c
+++ b/newlib/libc/stdio/getdelim.c
@@ -81,6 +81,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
CHECK_INIT (_REENT, fp);
+ __sfp_lock_acquire ();
_flockfile (fp);
numbytes = *n;
@@ -130,6 +131,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
}
_funlockfile (fp);
+ __sfp_lock_release ();
/* if no input data, return failure */
if (ptr == buf)
diff --git a/newlib/libc/stdio/gets.c b/newlib/libc/stdio/gets.c
index 17d144316..daa42e954 100644
--- a/newlib/libc/stdio/gets.c
+++ b/newlib/libc/stdio/gets.c
@@ -79,12 +79,14 @@ _DEFUN(_gets_r, (ptr, buf),
register int c;
register char *s = buf;
+ __sfp_lock_acquire ();
_flockfile (stdin);
while ((c = __sgetc_r (ptr, stdin)) != '\n')
if (c == EOF)
if (s == buf)
{
_funlockfile (stdin);
+ __sfp_lock_release ();
return NULL;
}
else
@@ -93,6 +95,7 @@ _DEFUN(_gets_r, (ptr, buf),
*s++ = c;
*s = 0;
_funlockfile (stdin);
+ __sfp_lock_release ();
return buf;
}