Loading...
--- Libc/Libc-1725.40.4/stdio/FreeBSD/fseek.c
+++ Libc/Libc-583/stdio/FreeBSD/fseek.c
@@ -13,6 +13,10 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
@@ -34,7 +38,7 @@
static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.44 2008/04/17 22:17:54 jhb Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.41 2004/05/22 15:19:41 tjr Exp $");
#include "namespace.h"
#include <sys/types.h>
@@ -51,13 +55,17 @@
#define POS_ERR (-(fpos_t)1)
int
-fseek(FILE *fp, long offset, int whence)
+fseek(fp, offset, whence)
+ FILE *fp;
+ long offset;
+ int whence;
{
int ret;
int serrno = errno;
/* make sure stdio is set up */
- pthread_once(&__sdidinit, __sinit);
+ if (!__sdidinit)
+ __sinit();
FLOCKFILE(fp);
ret = _fseeko(fp, (off_t)offset, whence, 1);
@@ -68,13 +76,17 @@
}
int
-fseeko(FILE *fp, off_t offset, int whence)
+fseeko(fp, offset, whence)
+ FILE *fp;
+ off_t offset;
+ int whence;
{
int ret;
int serrno = errno;
/* make sure stdio is set up */
- pthread_once(&__sdidinit, __sinit);
+ if (!__sdidinit)
+ __sinit();
FLOCKFILE(fp);
ret = _fseeko(fp, offset, whence, 0);
@@ -89,7 +101,11 @@
* `Whence' must be one of the three SEEK_* macros.
*/
int
-_fseeko(FILE *fp, off_t offset, int whence, int ltest)
+_fseeko(fp, offset, whence, ltest)
+ FILE *fp;
+ off_t offset;
+ int whence;
+ int ltest;
{
fpos_t (*seekfn)(void *, fpos_t, int);
fpos_t target, curoff, ret;
@@ -221,7 +237,7 @@
*/
if (HASUB(fp)) {
curoff += fp->_r; /* kill off ungetc */
- n = fp->_up - fp->_bf._base;
+ n = fp->_extra->_up - fp->_bf._base;
curoff -= n;
n += fp->_ur;
} else {
@@ -243,7 +259,7 @@
if (HASUB(fp))
FREEUB(fp);
fp->_flags &= ~__SEOF;
- memset(&fp->_mbstate, 0, sizeof(mbstate_t));
+ memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
return (0);
}
@@ -271,7 +287,6 @@
fp->_r -= n;
}
fp->_flags &= ~__SEOF;
- memset(&fp->_mbstate, 0, sizeof(mbstate_t));
return (0);
/*
@@ -282,11 +297,6 @@
if (__sflush(fp) ||
(ret = _sseek(fp, (fpos_t)offset, whence)) == POS_ERR)
return (-1);
- if (ltest && ret > LONG_MAX) {
- fp->_flags |= __SERR;
- errno = EOVERFLOW;
- return (-1);
- }
/* success: clear EOF indicator and discard ungetc() data */
if (HASUB(fp))
FREEUB(fp);
@@ -294,6 +304,11 @@
fp->_r = 0;
/* fp->_w = 0; */ /* unnecessary (I think...) */
fp->_flags &= ~__SEOF;
- memset(&fp->_mbstate, 0, sizeof(mbstate_t));
+ memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
+ if (ltest && ret > LONG_MAX) {
+ fp->_flags |= __SERR;
+ errno = EOVERFLOW;
+ return (-1);
+ }
return (0);
}