diff options
Diffstat (limited to 'lib/libc/stdio/fseek.c')
-rw-r--r-- | lib/libc/stdio/fseek.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 9cb04ad..1e99de9 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -45,6 +45,10 @@ static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94"; #include <stdlib.h> #include <errno.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif #define POS_ERR (-(fpos_t)1) @@ -68,6 +72,9 @@ fseek(fp, offset, whence) if (!__sdidinit) __sinit(); +#ifdef _THREAD_SAFE + _thread_flockfile(fp,__FILE__,__LINE__); +#endif /* * Have to be able to seek. */ @@ -92,8 +99,12 @@ fseek(fp, offset, whence) curoff = fp->_offset; else { curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1L) + if (curoff == -1L) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); + } } if (fp->_flags & __SRD) { curoff -= fp->_r; @@ -115,6 +126,9 @@ fseek(fp, offset, whence) default: errno = EINVAL; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); } @@ -198,6 +212,9 @@ fseek(fp, offset, whence) if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (0); } @@ -224,6 +241,9 @@ fseek(fp, offset, whence) fp->_p += n; fp->_r -= n; } +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (0); /* @@ -233,6 +253,9 @@ fseek(fp, offset, whence) dumb: if (__sflush(fp) || (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (EOF); } /* success: clear EOF indicator and discard ungetc() data */ @@ -242,5 +265,8 @@ dumb: fp->_r = 0; /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; +#ifdef _THREAD_SAFE + _thread_funlockfile(fp); +#endif return (0); } |