Update contrib.
3 * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies).
8 * Copyright (c) 1990 The Regents of the University of California.
11 * Redistribution and use in source and binary forms are permitted
12 * provided that the above copyright notice and this paragraph are
13 * duplicated in all such forms and that any documentation,
14 * advertising materials, and other materials related to such
15 * distribution and use acknowledge that the software was developed
16 * by the University of California, Berkeley. The name of the
17 * University may not be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 <<ftell>>---return position in a stream or file
33 long ftell(FILE *<[fp]>);
41 Objects of type <<FILE>> can have a ``position'' that records how much
42 of the file your program has already read. Many of the <<stdio>> functions
43 depend on this position, and many change it as a side effect.
45 The result of <<ftell>> is the current position for a file
46 identified by <[fp]>. If you record this result, you can later
47 use it with <<fseek>> to return the file to this
50 In the current implementation, <<ftell>> simply uses a character
51 count to represent the file position; this is the same number that
52 would be recorded by <<fgetpos>>.
55 <<ftell>> returns the file position, if possible. If it cannot do
56 this, it returns <<-1L>>. Failure occurs on streams that do not support
57 positioning; the global <<errno>> indicates this condition with the
61 <<ftell>> is required by the ANSI C standard, but the meaning of its
62 result (when successful) is not specified beyond requiring that it be
63 acceptable as an argument to <<fseek>>. In particular, other
64 conforming C implementations may return a different result from
65 <<ftell>> than what <<fgetpos>> records.
67 No supporting OS subroutines are required.
71 * ftell: return current offset.
80 Return the current position in a stream.
81 Returns the current position pointed by the position indicator of the stream.
82 When a file has been opened in binary mode the value obtained corresponds to
83 the number of bytes from the beginning of the file. In files opened in
84 text-mode this is not granted because of carriage-return translations under that mode.
85 @return On success, the current file pointer position is returned.
86 If an error occurs -1 is returned.
87 @param Pointer to an open file.
94 /* Ensure stdio is set up. */
98 if (fp->_seek == NULL)
100 __errno_r(fp->_data) = ESPIPE;
104 /* Find offset of underlying I/O object, then
105 adjust for buffered bytes. */
107 if (fp->_flags & __SOFF)
111 pos = (*fp->_seek) (fp->_cookie, (fpos_t) 0, SEEK_CUR);
115 if (fp->_flags & __SRD)
118 * Reading. Any unread characters (including
119 * those from ungetc) cause the position to be
120 * smaller than that in the underlying object.
126 else if (fp->_flags & __SWR && fp->_p != NULL)
129 * Writing. Any buffered characters cause the
130 * position to be greater than that in the
133 pos += fp->_p - fp->_bf._base;