fseek.c (72529) | fseek.c (81666) |
---|---|
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 72529 2001-02-16 06:11:22Z imp $"; | 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> --- 76 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 | 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> --- 76 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 } |
|
135 offset += curoff; | 139 offset += curoff; |
140 /* Disallow negative seeks per POSIX */ 141 if (offset < 0) { 142 errno = EINVAL; 143 return (EOF); 144 } |
|
136 whence = SEEK_SET; 137 havepos = 1; 138 break; 139 140 case SEEK_SET: | 145 whence = SEEK_SET; 146 havepos = 1; 147 break; 148 149 case SEEK_SET: |
150 /* Disallow negative seeks per POSIX */ 151 if (offset < 0) { 152 errno = EINVAL; 153 return (EOF); 154 } |
|
141 case SEEK_END: 142 curoff = 0; /* XXX just to keep gcc quiet */ 143 havepos = 0; 144 break; 145 146 default: 147 errno = EINVAL; 148 return (EOF); --- 26 unchanged lines hidden (view full) --- 175 * We are reading; we can try to optimise. 176 * Figure out where we are going and where we are now. 177 */ 178 if (whence == SEEK_SET) 179 target = offset; 180 else { 181 if (_fstat(fp->_file, &st)) 182 goto dumb; | 155 case SEEK_END: 156 curoff = 0; /* XXX just to keep gcc quiet */ 157 havepos = 0; 158 break; 159 160 default: 161 errno = EINVAL; 162 return (EOF); --- 26 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 } |
|
183 target = st.st_size + offset; | 201 target = st.st_size + offset; |
202 /* Disallow negative seeks per POSIX */ 203 if ((off_t)target < 0) { 204 errno = EINVAL; 205 return (EOF); 206 } |
|
184 } 185 186 if (!havepos) { 187 if (fp->_flags & __SOFF) 188 curoff = fp->_offset; 189 else { 190 curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); 191 if (curoff == POS_ERR) --- 84 unchanged lines hidden --- | 207 } 208 209 if (!havepos) { 210 if (fp->_flags & __SOFF) 211 curoff = fp->_offset; 212 else { 213 curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); 214 if (curoff == POS_ERR) --- 84 unchanged lines hidden --- |