ftell.c (290231) | ftell.c (290232) |
---|---|
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 290231 2015-11-01 06:47:05Z ache $"); | 37__FBSDID("$FreeBSD: head/lib/libc/stdio/ftell.c 290232 2015-11-01 08:40:15Z 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" --- 67 unchanged lines hidden (view full) --- 113 */ 114 if ((pos -= (HASUB(fp) ? fp->_ur : fp->_r)) < 0) { 115 fp->_flags |= __SERR; 116 errno = EIO; 117 return (1); 118 } 119 if (HASUB(fp)) 120 pos -= fp->_r; /* Can be negative at this point. */ | 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" --- 67 unchanged lines hidden (view full) --- 113 */ 114 if ((pos -= (HASUB(fp) ? fp->_ur : fp->_r)) < 0) { 115 fp->_flags |= __SERR; 116 errno = EIO; 117 return (1); 118 } 119 if (HASUB(fp)) 120 pos -= fp->_r; /* Can be negative at this point. */ |
121 } else if ((fp->_flags & __SWR) && fp->_p != NULL) { | 121 } else if ((fp->_flags & __SWR) && fp->_p != NULL && 122 (n = fp->_p - fp->_bf._base) > 0) { |
122 /* 123 * Writing. Any buffered characters cause the 124 * position to be greater than that in the 125 * underlying object. 126 */ | 123 /* 124 * Writing. Any buffered characters cause the 125 * position to be greater than that in the 126 * underlying object. 127 */ |
127 n = fp->_p - fp->_bf._base; 128 if (n > 0 && 129 ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) { | 128 if ((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) --- 20 unchanged lines hidden --- | 129 int serrno = errno; 130 131 errno = 0; 132 if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) { 133 if (errno == ESPIPE || 134 (fp->_flags & __SOPT) || __sflush(fp) || 135 (pos = 136 _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1) --- 20 unchanged lines hidden --- |