ftell.c (7e546392b5fe3a496acff53ac7aadd1c57b2a4cf) | ftell.c (662909a7800d5634772b89ca1509765dda837508) |
---|---|
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 --- 21 unchanged lines hidden (view full) --- 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) | 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 --- 21 unchanged lines hidden (view full) --- 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) |
38#if 0 39static char sccsid[] = "@(#)ftell.c 8.1 (Berkeley) 6/4/93"; 40#endif 41static const char rcsid[] = 42 "$Id$"; | 38static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; |
43#endif /* LIBC_SCCS and not lint */ 44 45#include <stdio.h> 46#include <errno.h> 47#include "local.h" | 39#endif /* LIBC_SCCS and not lint */ 40 41#include <stdio.h> 42#include <errno.h> 43#include "local.h" |
48#ifdef _THREAD_SAFE 49#include <pthread.h> 50#include "pthread_private.h" 51#endif | |
52 53/* 54 * ftell: return current offset. 55 */ 56long 57ftell(fp) 58 register FILE *fp; 59{ 60 register fpos_t pos; 61 62 if (fp->_seek == NULL) { 63 errno = ESPIPE; /* historic practice */ 64 return (-1L); 65 } 66 | 44 45/* 46 * ftell: return current offset. 47 */ 48long 49ftell(fp) 50 register FILE *fp; 51{ 52 register fpos_t pos; 53 54 if (fp->_seek == NULL) { 55 errno = ESPIPE; /* historic practice */ 56 return (-1L); 57 } 58 |
67#ifdef _THREAD_SAFE 68 _thread_flockfile(fp, __FILE__, __LINE__); 69#endif | |
70 /* 71 * Find offset of underlying I/O object, then 72 * adjust for buffered bytes. 73 */ 74 if (fp->_flags & __SOFF) 75 pos = fp->_offset; 76 else { 77 pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); | 59 /* 60 * Find offset of underlying I/O object, then 61 * adjust for buffered bytes. 62 */ 63 if (fp->_flags & __SOFF) 64 pos = fp->_offset; 65 else { 66 pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); |
78 if (pos == -1) { 79#ifdef _THREAD_SAFE 80 _thread_funlockfile(fp); 81#endif | 67 if (pos == -1L) |
82 return (pos); | 68 return (pos); |
83 } | |
84 } 85 if (fp->_flags & __SRD) { 86 /* 87 * Reading. Any unread characters (including 88 * those from ungetc) cause the position to be 89 * smaller than that in the underlying object. 90 */ 91 pos -= fp->_r; 92 if (HASUB(fp)) 93 pos -= fp->_ur; 94 } else if (fp->_flags & __SWR && fp->_p != NULL) { 95 /* 96 * Writing. Any buffered characters cause the 97 * position to be greater than that in the 98 * underlying object. 99 */ 100 pos += fp->_p - fp->_bf._base; 101 } | 69 } 70 if (fp->_flags & __SRD) { 71 /* 72 * Reading. Any unread characters (including 73 * those from ungetc) cause the position to be 74 * smaller than that in the underlying object. 75 */ 76 pos -= fp->_r; 77 if (HASUB(fp)) 78 pos -= fp->_ur; 79 } else if (fp->_flags & __SWR && fp->_p != NULL) { 80 /* 81 * Writing. Any buffered characters cause the 82 * position to be greater than that in the 83 * underlying object. 84 */ 85 pos += fp->_p - fp->_bf._base; 86 } |
102#ifdef _THREAD_SAFE 103 _thread_funlockfile(fp); 104#endif | |
105 return (pos); 106} | 87 return (pos); 88} |