ftell.c (290230) | ftell.c (290231) |
---|---|
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[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; 35#endif /* LIBC_SCCS and not lint */ 36#include <sys/cdefs.h> | 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[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; 35#endif /* LIBC_SCCS and not lint */ 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/lib/libc/stdio/ftell.c 290230 2015-11-01 06:15:14Z ache $"); | 37__FBSDID("$FreeBSD: head/lib/libc/stdio/ftell.c 290231 2015-11-01 06:47:05Z ache $"); |
38 39#include "namespace.h" 40#include <sys/types.h> 41#include <errno.h> 42#include <fcntl.h> 43#include <limits.h> 44#include <stdio.h> 45#include "un-namespace.h" --- 74 unchanged lines hidden (view full) --- 120 pos -= fp->_r; /* Can be negative at this point. */ 121 } else if ((fp->_flags & __SWR) && fp->_p != NULL) { 122 /* 123 * Writing. Any buffered characters cause the 124 * position to be greater than that in the 125 * underlying object. 126 */ 127 n = fp->_p - fp->_bf._base; | 38 39#include "namespace.h" 40#include <sys/types.h> 41#include <errno.h> 42#include <fcntl.h> 43#include <limits.h> 44#include <stdio.h> 45#include "un-namespace.h" --- 74 unchanged lines hidden (view full) --- 120 pos -= fp->_r; /* Can be negative at this point. */ 121 } else if ((fp->_flags & __SWR) && fp->_p != NULL) { 122 /* 123 * Writing. Any buffered characters cause the 124 * position to be greater than that in the 125 * underlying object. 126 */ 127 n = fp->_p - fp->_bf._base; |
128 if (pos > OFF_MAX - n) { 129 errno = EOVERFLOW; 130 return (1); 131 } | |
132 if (n > 0 && 133 ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) { 134 int serrno = errno; 135 136 errno = 0; 137 if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) { 138 if (errno == ESPIPE || 139 (fp->_flags & __SOPT) || __sflush(fp) || 140 (pos = 141 _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1) 142 return (1); 143 else { 144 errno = serrno; 145 *offset = pos; 146 return (0); 147 } 148 } 149 errno = serrno; | 128 if (n > 0 && 129 ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) { 130 int serrno = errno; 131 132 errno = 0; 133 if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) { 134 if (errno == ESPIPE || 135 (fp->_flags & __SOPT) || __sflush(fp) || 136 (pos = 137 _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1) 138 return (1); 139 else { 140 errno = serrno; 141 *offset = pos; 142 return (0); 143 } 144 } 145 errno = serrno; |
146 /* fp->_p can be changed in _sseek(), recalculate. */ 147 n = fp->_p - fp->_bf._base; |
|
150 } | 148 } |
149 if (pos > OFF_MAX - n) { 150 errno = EOVERFLOW; 151 return (1); 152 } |
|
151 pos += n; 152 } 153 *offset = pos; 154 return (0); 155} | 153 pos += n; 154 } 155 *offset = pos; 156 return (0); 157} |