Deleted Added
sdiff udiff text old ( 165903 ) new ( 170907 )
full compact
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/lib/libc/stdio/fseek.c 165903 2007-01-09 00:28:16Z imp $");
38
39#include "namespace.h"
40#include <sys/types.h>
41#include <sys/stat.h>
42#include <errno.h>
43#include <fcntl.h>
44#include <limits.h>
45#include <stdio.h>

--- 232 unchanged lines hidden (view full) ---

278 n = target - curoff;
279 if (n) {
280 if (__srefill(fp) || fp->_r < n)
281 goto dumb;
282 fp->_p += n;
283 fp->_r -= n;
284 }
285 fp->_flags &= ~__SEOF;
286 return (0);
287
288 /*
289 * We get here if we cannot optimise the seek ... just
290 * do it. Allow the seek function to change fp->_bf._base.
291 */
292dumb:
293 if (__sflush(fp) ||
294 (ret = _sseek(fp, (fpos_t)offset, whence)) == POS_ERR)
295 return (-1);
296 /* success: clear EOF indicator and discard ungetc() data */
297 if (HASUB(fp))
298 FREEUB(fp);
299 fp->_p = fp->_bf._base;
300 fp->_r = 0;
301 /* fp->_w = 0; */ /* unnecessary (I think...) */
302 fp->_flags &= ~__SEOF;
303 memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
304 if (ltest && ret > LONG_MAX) {
305 fp->_flags |= __SERR;
306 errno = EOVERFLOW;
307 return (-1);
308 }
309 return (0);
310}