diff options
Diffstat (limited to 'newlib/libc/stdio/ftell.c')
-rw-r--r-- | newlib/libc/stdio/ftell.c | 75 |
1 files changed, 16 insertions, 59 deletions
diff --git a/newlib/libc/stdio/ftell.c b/newlib/libc/stdio/ftell.c index 74d6d906c..6a8061816 100644 --- a/newlib/libc/stdio/ftell.c +++ b/newlib/libc/stdio/ftell.c @@ -17,58 +17,37 @@ /* FUNCTION -<<ftell>>, <<ftello>>---return position in a stream or file +<<ftell>>---return position in a stream or file INDEX ftell -INDEX - ftello -INDEX - _ftell_r -INDEX - _ftello_r ANSI_SYNOPSIS #include <stdio.h> long ftell(FILE *<[fp]>); - off_t ftello(FILE *<[fp]>); - long _ftell_r(struct _reent *<[ptr]>, FILE *<[fp]>); - off_t _ftello_r(struct _reent *<[ptr]>, FILE *<[fp]>); TRAD_SYNOPSIS #include <stdio.h> long ftell(<[fp]>) FILE *<[fp]>; - off_t ftello(<[fp]>) - FILE *<[fp]>; - - long _ftell_r(<[ptr]>, <[fp]>) - struct _reent *<[ptr]>; - FILE *<[fp]>; - - off_t _ftello_r(<[ptr]>, <[fp]>) - struct _reent *<[ptr]>; - FILE *<[fp]>; - DESCRIPTION Objects of type <<FILE>> can have a ``position'' that records how much of the file your program has already read. Many of the <<stdio>> functions depend on this position, and many change it as a side effect. -The result of <<ftell>>/<<ftello>> is the current position for a file +The result of <<ftell>> is the current position for a file identified by <[fp]>. If you record this result, you can later -use it with <<fseek>>/<<fseeko>> to return the file to this -position. The difference between <<ftell>> and <<ftello>> is that -<<ftell>> returns <<long>> and <<ftello>> returns <<off_t>>. +use it with <<fseek>> to return the file to this +position. -In the current implementation, <<ftell>>/<<ftello>> simply uses a character +In the current implementation, <<ftell>> simply uses a character count to represent the file position; this is the same number that would be recorded by <<fgetpos>>. RETURNS -<<ftell>>/<<ftello>> return the file position, if possible. If they cannot do -this, they return <<-1L>>. Failure occurs on streams that do not support +<<ftell>> returns the file position, if possible. If it cannot do +this, it returns <<-1L>>. Failure occurs on streams that do not support positioning; the global <<errno>> indicates this condition with the value <<ESPIPE>>. @@ -79,8 +58,6 @@ acceptable as an argument to <<fseek>>. In particular, other conforming C implementations may return a different result from <<ftell>> than what <<fgetpos>> records. -<<ftello>> is defined by the Single Unix specification. - No supporting OS subroutines are required. */ @@ -92,29 +69,24 @@ static char sccsid[] = "%W% (Berkeley) %G%"; * ftell: return current offset. */ -#include <_ansi.h> -#include <reent.h> #include <stdio.h> #include <errno.h> + #include "local.h" long -_DEFUN(_ftell_r, (ptr, fp), - struct _reent *ptr _AND - register FILE * fp) +_DEFUN (ftell, (fp), + register FILE * fp) { - _fpos_t pos; + fpos_t pos; /* Ensure stdio is set up. */ - CHECK_INIT (ptr); - - _flockfile (fp); + CHECK_INIT (fp); if (fp->_seek == NULL) { - ptr->_errno = ESPIPE; - _funlockfile (fp); + fp->_data->_errno = ESPIPE; return -1L; } @@ -125,12 +97,9 @@ _DEFUN(_ftell_r, (ptr, fp), pos = fp->_offset; else { - pos = (*fp->_seek) (fp->_cookie, (_fpos_t) 0, SEEK_CUR); + pos = (*fp->_seek) (fp->_cookie, (fpos_t) 0, SEEK_CUR); if (pos == -1L) - { - _funlockfile (fp); - return pos; - } + return pos; } if (fp->_flags & __SRD) { @@ -143,7 +112,7 @@ _DEFUN(_ftell_r, (ptr, fp), if (HASUB (fp)) pos -= fp->_ur; } - else if ((fp->_flags & __SWR) && fp->_p != NULL) + else if (fp->_flags & __SWR && fp->_p != NULL) { /* * Writing. Any buffered characters cause the @@ -153,17 +122,5 @@ _DEFUN(_ftell_r, (ptr, fp), pos += fp->_p - fp->_bf._base; } - _funlockfile (fp); return pos; } - -#ifndef _REENT_ONLY - -long -_DEFUN(ftell, (fp), - register FILE * fp) -{ - return _ftell_r (_REENT, fp); -} - -#endif /* !_REENT_ONLY */ |