Deleted Added
full compact
fseek.c (81666) fseek.c (81730)
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[] =
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 $";
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>
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>
48#include <fcntl.h>
49#include <fcntl.h>
50#include <limits.h>
49#include <stdio.h>
50#include <stdlib.h>
51#include <stdio.h>
52#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
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
135 if (offset > 0 && offset + (off_t)curoff < 0) {
136 /* curoff always >= 0 */
137 if (offset > 0 && curoff > OFF_MAX - offset) {
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;
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;
197 if (offset > 0 && st.st_size + offset < 0) {
199 /* st.st_size always >= 0 */
200 if (offset > 0 && st.st_size > OFF_MAX - offset) {
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 ---
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 ---