summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fseek.c
diff options
context:
space:
mode:
authorjb <jb@FreeBSD.org>1998-04-11 07:40:47 +0000
committerjb <jb@FreeBSD.org>1998-04-11 07:40:47 +0000
commit0ff63017b40dda207b2aadc9881e0c93e7fd2753 (patch)
tree4819eff8a5c9bc5ae04aaf772d0d5b4f7bfaaebc /lib/libc/stdio/fseek.c
parent525c97c21dbcb3fd61a8a530a3f8df5e901bf1ab (diff)
downloadFreeBSD-src-0ff63017b40dda207b2aadc9881e0c93e7fd2753.zip
FreeBSD-src-0ff63017b40dda207b2aadc9881e0c93e7fd2753.tar.gz
Add FILE locking stubs for libc.
Change the FILE locking to support kernel threads when linked with libpthread (which you haven't see yet). This requires that libc become thread-safe and thread-aware, testing __isthreaded before attempting to do lock/unlock calls. The impact on non-threaded programs is minor. This change works with libc_r, so it's the best compromise.
Diffstat (limited to 'lib/libc/stdio/fseek.c')
-rw-r--r--lib/libc/stdio/fseek.c36
1 files changed, 10 insertions, 26 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c
index c6707df..808d3ae 100644
--- a/lib/libc/stdio/fseek.c
+++ b/lib/libc/stdio/fseek.c
@@ -39,7 +39,7 @@
static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
#endif
static const char rcsid[] =
- "$Id$";
+ "$Id: fseek.c,v 1.6 1997/02/22 15:02:05 peter Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -49,10 +49,7 @@ static const char rcsid[] =
#include <stdlib.h>
#include <errno.h>
#include "local.h"
-#ifdef _THREAD_SAFE
-#include <pthread.h>
-#include "pthread_private.h"
-#endif
+#include "libc_private.h"
#define POS_ERR (-(fpos_t)1)
@@ -76,14 +73,13 @@ fseek(fp, offset, whence)
if (!__sdidinit)
__sinit();
-#ifdef _THREAD_SAFE
- _thread_flockfile(fp,__FILE__,__LINE__);
-#endif
+ FLOCKFILE(fp);
/*
* Have to be able to seek.
*/
if ((seekfn = fp->_seek) == NULL) {
errno = ESPIPE; /* historic practice */
+ FUNLOCKFILE(fp);
return (EOF);
}
@@ -104,9 +100,7 @@ fseek(fp, offset, whence)
else {
curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
if (curoff == -1) {
-#ifdef _THREAD_SAFE
- _thread_funlockfile(fp);
-#endif
+ FUNLOCKFILE(fp);
return (EOF);
}
}
@@ -130,9 +124,7 @@ fseek(fp, offset, whence)
default:
errno = EINVAL;
-#ifdef _THREAD_SAFE
- _thread_funlockfile(fp);
-#endif
+ FUNLOCKFILE(fp);
return (EOF);
}
@@ -216,9 +208,7 @@ fseek(fp, offset, whence)
if (HASUB(fp))
FREEUB(fp);
fp->_flags &= ~__SEOF;
-#ifdef _THREAD_SAFE
- _thread_funlockfile(fp);
-#endif
+ FUNLOCKFILE(fp);
return (0);
}
@@ -245,9 +235,7 @@ fseek(fp, offset, whence)
fp->_p += n;
fp->_r -= n;
}
-#ifdef _THREAD_SAFE
- _thread_funlockfile(fp);
-#endif
+ FUNLOCKFILE(fp);
return (0);
/*
@@ -257,9 +245,7 @@ fseek(fp, offset, whence)
dumb:
if (__sflush(fp) ||
(*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) {
-#ifdef _THREAD_SAFE
- _thread_funlockfile(fp);
-#endif
+ FUNLOCKFILE(fp);
return (EOF);
}
/* success: clear EOF indicator and discard ungetc() data */
@@ -269,8 +255,6 @@ dumb:
fp->_r = 0;
/* fp->_w = 0; */ /* unnecessary (I think...) */
fp->_flags &= ~__SEOF;
-#ifdef _THREAD_SAFE
- _thread_funlockfile(fp);
-#endif
+ FUNLOCKFILE(fp);
return (0);
}
OpenPOWER on IntegriCloud