summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fseek.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/fseek.c')
-rw-r--r--lib/libc/stdio/fseek.c48
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);
}
OpenPOWER on IntegriCloud