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 81666 2001-08-15 02:07:47Z 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 <fcntl.h>
49#include <stdio.h>
50#include <stdlib.h>
51#include <errno.h>
52#include "un-namespace.h"
53#include "local.h"
54#include "libc_private.h"
55
56#define POS_ERR (-(fpos_t)1)
57
58int
59fseek(fp, offset, whence)

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

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

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

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

--- 93 unchanged lines hidden ---