* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)ftell.c 8.2 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
* ftell: return current offset.
errno
= ESPIPE
; /* historic practice */
* Find offset of underlying I/O object, then
* adjust for buffered bytes.
pos
= (*fp
->_seek
)(fp
->_cookie
, (fpos_t)0, SEEK_CUR
);
if (fp
->_flags
& __SRD
) {
* Reading. Any unread characters (including
* those from ungetc) cause the position to be
* smaller than that in the underlying object.
} else if (fp
->_flags
& __SWR
&& fp
->_p
!= NULL
) {
* Writing. Any buffered characters cause the
* position to be greater than that in the
pos
+= fp
->_p
- fp
->_bf
._base
;