diff options
Diffstat (limited to 'lib/libc/stdio/ftell.c')
-rw-r--r-- | lib/libc/stdio/ftell.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 724e543..271490a 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -41,6 +41,10 @@ static char sccsid[] = "@(#)ftell.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <errno.h> #include "local.h" +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" +#endif /* * ftell: return current offset. @@ -56,6 +60,9 @@ ftell(fp) return (-1L); } +#ifdef _THREAD_SAFE + _thread_flockfile((FILE *) fp,__FILE__,__LINE__); +#endif /* * Find offset of underlying I/O object, then * adjust for buffered bytes. @@ -64,8 +71,12 @@ ftell(fp) pos = fp->_offset; else { pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (pos == -1L) + if (pos == -1L) { +#ifdef _THREAD_SAFE + _thread_funlockfile((FILE *) fp); +#endif return (pos); + } } if (fp->_flags & __SRD) { /* @@ -84,5 +95,8 @@ ftell(fp) */ pos += fp->_p - fp->_bf._base; } +#ifdef _THREAD_SAFE + _thread_funlockfile((FILE *) fp); +#endif return (pos); } |