diff options
author | deischen <deischen@FreeBSD.org> | 2001-01-24 13:01:12 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2001-01-24 13:01:12 +0000 |
commit | 1635c221b7b2678beeeb2b5fa728edd7c8c3735b (patch) | |
tree | d7d4f61b9e319a781a335702fe846592726c22b9 /lib/libc/stdio/fseek.c | |
parent | 08685e9e9fd9de1e8dc51cada55659344adaf0cc (diff) | |
download | FreeBSD-src-1635c221b7b2678beeeb2b5fa728edd7c8c3735b.zip FreeBSD-src-1635c221b7b2678beeeb2b5fa728edd7c8c3735b.tar.gz |
Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions. If the threads library is linked in, the real
pthread functions will pulled in.
Use the following convention for system calls wrapped by the
threads library:
__sys_foo - actual system call
_foo - weak definition to __sys_foo
foo - weak definition to __sys_foo
Change all libc uses of system calls wrapped by the threads
library from foo to _foo. In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde). All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes. <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.
Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE. We have recursive mutexes, but would like to avoid
using them if possible.
Remove uneeded includes of <errno.h> from a few files.
Add $FreeBSD$ to a few files in order to pass commitprep.
Approved by: -arch
Diffstat (limited to 'lib/libc/stdio/fseek.c')
-rw-r--r-- | lib/libc/stdio/fseek.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 8c2732e..f873975 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -42,12 +42,14 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> +#include "un-namespace.h" #include "local.h" #include "libc_private.h" @@ -62,13 +64,31 @@ fseek(fp, offset, whence) return (fseeko(fp, offset, whence)); } +int +fseeko(fp, offset, whence) + FILE *fp; + off_t offset; + int whence; +{ + int ret; + + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + FLOCKFILE(fp); + ret = _fseeko(fp, offset, whence); + FUNLOCKFILE(fp); + return (ret); +} + /* * Seek the given file to the given offset. * `Whence' must be one of the three SEEK_* macros. */ int -fseeko(fp, offset, whence) - register FILE *fp; +_fseeko(fp, offset, whence) + FILE *fp; off_t offset; int whence; { @@ -78,17 +98,11 @@ fseeko(fp, offset, whence) struct stat st; int havepos; - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - FLOCKFILE(fp); /* * Have to be able to seek. */ if ((seekfn = fp->_seek) == NULL) { - errno = ESPIPE; /* historic practice */ - FUNLOCKFILE(fp); + errno = ESPIPE; /* historic practice */ return (EOF); } @@ -108,10 +122,8 @@ fseeko(fp, offset, whence) curoff = fp->_offset; else { curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1) { - FUNLOCKFILE(fp); + if (curoff == -1) return (EOF); - } } if (fp->_flags & __SRD) { curoff -= fp->_r; @@ -133,7 +145,6 @@ fseeko(fp, offset, whence) default: errno = EINVAL; - FUNLOCKFILE(fp); return (EOF); } @@ -151,7 +162,7 @@ fseeko(fp, offset, whence) goto dumb; if ((fp->_flags & __SOPT) == 0) { if (seekfn != __sseek || - fp->_file < 0 || fstat(fp->_file, &st) || + fp->_file < 0 || _fstat(fp->_file, &st) || (st.st_mode & S_IFMT) != S_IFREG) { fp->_flags |= __SNPT; goto dumb; @@ -167,7 +178,7 @@ fseeko(fp, offset, whence) if (whence == SEEK_SET) target = offset; else { - if (fstat(fp->_file, &st)) + if (_fstat(fp->_file, &st)) goto dumb; target = st.st_size + offset; } @@ -217,7 +228,6 @@ fseeko(fp, offset, whence) if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; - FUNLOCKFILE(fp); return (0); } @@ -244,7 +254,6 @@ fseeko(fp, offset, whence) fp->_p += n; fp->_r -= n; } - FUNLOCKFILE(fp); return (0); /* @@ -253,10 +262,8 @@ fseeko(fp, offset, whence) */ dumb: if (__sflush(fp) || - (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { - FUNLOCKFILE(fp); + (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) return (EOF); - } /* success: clear EOF indicator and discard ungetc() data */ if (HASUB(fp)) FREEUB(fp); @@ -264,6 +271,5 @@ dumb: fp->_r = 0; /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; - FUNLOCKFILE(fp); return (0); } |