반응형
off_t
ftello(FILE *fp)
#include <stdio.h> #include <errno.h> #include "local.h" /* * ftello: return current offset. */ off_t ftello(FILE *fp) { fpos_t pos; if (fp->_seek == NULL) { errno = ESPIPE; /* historic practice */ return ((off_t)-1); } /* * Find offset of underlying I/O object, then * adjust for buffered bytes. */ __sflush(fp); /* may adjust seek offset on append stream */ if (fp->_flags & __SOFF) pos = fp->_offset; else { pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); if (pos == -1L) return (pos); } if (fp->_flags & __SRD) { /* * Reading. Any unread characters (including * those from ungetc) cause the position to be * smaller than that in the underlying object. */ pos -= fp->_r; if (HASUB(fp)) pos -= fp->_ur; } else if (fp->_flags & __SWR && fp->_p != NULL) { /* * Writing. Any buffered characters cause the * position to be greater than that in the * underlying object. */ pos += fp->_p - fp->_bf._base; } return (pos); } /* * ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches */ #if defined(__alpha__) && defined(__indr_reference) __indr_reference(ftello, ftell); #else long ftell(FILE *fp) { long pos; pos = (long)ftello(fp); return(pos); } #endif
반응형