ftell.c (268992) | ftell.c (268997) |
---|---|
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 268992 2014-07-22 20:13:46Z ache $"); | 37__FBSDID("$FreeBSD: head/lib/libc/stdio/ftell.c 268997 2014-07-22 22:49:37Z ache $"); |
38 39#include "namespace.h" 40#include <sys/types.h> 41#include <errno.h> | 38 39#include "namespace.h" 40#include <sys/types.h> 41#include <errno.h> |
42#include <fcntl.h> |
|
42#include <limits.h> 43#include <stdio.h> 44#include "un-namespace.h" 45#include "local.h" 46#include "libc_private.h" 47 48/* 49 * standard ftell function. --- 32 unchanged lines hidden (view full) --- 82 return (rv); 83} 84 85int 86_ftello(FILE *fp, fpos_t *offset) 87{ 88 fpos_t pos; 89 size_t n; | 43#include <limits.h> 44#include <stdio.h> 45#include "un-namespace.h" 46#include "local.h" 47#include "libc_private.h" 48 49/* 50 * standard ftell function. --- 32 unchanged lines hidden (view full) --- 83 return (rv); 84} 85 86int 87_ftello(FILE *fp, fpos_t *offset) 88{ 89 fpos_t pos; 90 size_t n; |
91 int dflags; |
|
90 91 if (fp->_seek == NULL) { 92 errno = ESPIPE; /* historic practice */ 93 return (1); 94 } 95 96 /* 97 * Find offset of underlying I/O object, then --- 15 unchanged lines hidden (view full) --- 113 if ((pos -= (HASUB(fp) ? fp->_ur : fp->_r)) < 0) { 114 fp->_flags |= __SERR; 115 errno = EIO; 116 return (1); 117 } 118 if (HASUB(fp)) 119 pos -= fp->_r; /* Can be negative at this point. */ 120 } else if ((fp->_flags & __SWR) && fp->_p != NULL) { | 92 93 if (fp->_seek == NULL) { 94 errno = ESPIPE; /* historic practice */ 95 return (1); 96 } 97 98 /* 99 * Find offset of underlying I/O object, then --- 15 unchanged lines hidden (view full) --- 115 if ((pos -= (HASUB(fp) ? fp->_ur : fp->_r)) < 0) { 116 fp->_flags |= __SERR; 117 errno = EIO; 118 return (1); 119 } 120 if (HASUB(fp)) 121 pos -= fp->_r; /* Can be negative at this point. */ 122 } else if ((fp->_flags & __SWR) && fp->_p != NULL) { |
123 dflags = 0; 124 if (fp->_flags & __SAPP) 125 dflags = O_APPEND; 126 else if (fp->_file != -1 && 127 (dflags = _fcntl(fp->_file, F_GETFL)) < 0) 128 return (1); 129 if ((dflags & O_APPEND) && 130 (pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) { 131 if ((fp->_flags & __SOPT) || __sflush(fp) || 132 (pos = _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1) 133 return (1); 134 else { 135 *offset = pos; 136 return (0); 137 } 138 } |
|
121 /* 122 * Writing. Any buffered characters cause the 123 * position to be greater than that in the 124 * underlying object. 125 */ 126 n = fp->_p - fp->_bf._base; 127 if (pos > OFF_MAX - n) { 128 errno = EOVERFLOW; 129 return (1); 130 } 131 pos += n; 132 } 133 *offset = pos; 134 return (0); 135} | 139 /* 140 * Writing. Any buffered characters cause the 141 * position to be greater than that in the 142 * underlying object. 143 */ 144 n = fp->_p - fp->_bf._base; 145 if (pos > OFF_MAX - n) { 146 errno = EOVERFLOW; 147 return (1); 148 } 149 pos += n; 150 } 151 *offset = pos; 152 return (0); 153} |