Deleted Added
sdiff udiff text old ( 81666 ) new ( 81730 )
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

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

34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38#if 0
39static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
40#endif
41static const char rcsid[] =
42 "$FreeBSD: head/lib/libc/stdio/fseek.c 81730 2001-08-15 20:10:38Z ache $";
43#endif /* LIBC_SCCS and not lint */
44
45#include "namespace.h"
46#include <sys/types.h>
47#include <sys/stat.h>
48#include <errno.h>
49#include <fcntl.h>
50#include <limits.h>
51#include <stdio.h>
52#include <stdlib.h>
53#include "un-namespace.h"
54#include "local.h"
55#include "libc_private.h"
56
57#define POS_ERR (-(fpos_t)1)
58
59int
60fseek(fp, offset, whence)

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

128 }
129 if (fp->_flags & __SRD) {
130 curoff -= fp->_r;
131 if (HASUB(fp))
132 curoff -= fp->_ur;
133 } else if (fp->_flags & __SWR && fp->_p != NULL)
134 curoff += fp->_p - fp->_bf._base;
135
136 /* curoff always >= 0 */
137 if (offset > 0 && curoff > OFF_MAX - offset) {
138 errno = EOVERFLOW;
139 return (EOF);
140 }
141 offset += curoff;
142 /* Disallow negative seeks per POSIX */
143 if (offset < 0) {
144 errno = EINVAL;
145 return (EOF);

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

191 * We are reading; we can try to optimise.
192 * Figure out where we are going and where we are now.
193 */
194 if (whence == SEEK_SET)
195 target = offset;
196 else {
197 if (_fstat(fp->_file, &st))
198 goto dumb;
199 /* st.st_size always >= 0 */
200 if (offset > 0 && st.st_size > OFF_MAX - offset) {
201 errno = EOVERFLOW;
202 return (EOF);
203 }
204 target = st.st_size + offset;
205 /* Disallow negative seeks per POSIX */
206 if ((off_t)target < 0) {
207 errno = EINVAL;
208 return (EOF);

--- 93 unchanged lines hidden ---