2 * Copyright (c) 1990 The Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * and/or other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 <<ftello64>>---return position in a stream or file
29 _off64_t ftello64(FILE *<[fp]>);
30 _off64_t _ftello64_r(struct _reent *<[ptr]>, FILE *<[fp]>);
33 Objects of type <<FILE>> can have a ``position'' that records how much
34 of the file your program has already read. Many of the <<stdio>> functions
35 depend on this position, and many change it as a side effect.
37 The result of <<ftello64>> is the current position for a large file
38 identified by <[fp]>. If you record this result, you can later
39 use it with <<fseeko64>> to return the file to this
40 position. The difference between <<ftello>> and <<ftello64>> is that
41 <<ftello>> returns <<off_t>> and <<ftello64>> is designed to work
42 for large files (>2GB) and returns <<_off64_t>>.
44 In the current implementation, <<ftello64>> simply uses a character
45 count to represent the file position; this is the same number that
46 would be recorded by <<fgetpos64>>.
48 The function exists only if the __LARGE64_FILES flag is defined.
49 An error occurs if the <[fp]> was not opened via <<fopen64>>.
52 <<ftello64>> returns the file position, if possible. If it cannot do
53 this, it returns <<-1>>. Failure occurs on streams that do not support
54 positioning or not opened via <<fopen64>>; the global <<errno>> indicates
55 this condition with the value <<ESPIPE>>.
58 <<ftello64>> is a glibc extension.
60 No supporting OS subroutines are required.
63 #if defined(LIBC_SCCS) && !defined(lint)
64 static char sccsid
[] = "%W% (Berkeley) %G%";
65 #endif /* LIBC_SCCS and not lint */
68 * ftello64: return current offset.
76 #ifdef __LARGE64_FILES
79 _ftello64_r (struct _reent
*ptr
,
84 /* Only do 64-bit tell on large file. */
85 if (!(fp
->_flags
& __SL64
))
86 return (_off64_t
) _ftello_r (ptr
, fp
);
88 /* Ensure stdio is set up. */
92 _newlib_flockfile_start(fp
);
94 if (fp
->_seek64
== NULL
)
96 _REENT_ERRNO(ptr
) = ESPIPE
;
97 _newlib_flockfile_exit(fp
);
101 /* Find offset of underlying I/O object, then adjust for buffered bytes. */
102 if (!(fp
->_flags
& __SRD
) && (fp
->_flags
& __SWR
) &&
103 fp
->_p
!= NULL
&& fp
->_p
- fp
->_bf
._base
> 0 &&
104 (fp
->_flags
& __SAPP
))
106 pos
= fp
->_seek64 (ptr
, fp
->_cookie
, (_fpos64_t
) 0, SEEK_END
);
107 if (pos
== (_fpos64_t
) -1)
109 _newlib_flockfile_exit (fp
);
110 return (_off64_t
) -1;
113 else if (fp
->_flags
& __SOFF
)
117 pos
= fp
->_seek64 (ptr
, fp
->_cookie
, (_fpos64_t
) 0, SEEK_CUR
);
118 if (pos
== (_fpos64_t
) -1)
120 _newlib_flockfile_exit(fp
);
121 return (_off64_t
) pos
;
124 if (fp
->_flags
& __SRD
)
127 * Reading. Any unread characters (including
128 * those from ungetc) cause the position to be
129 * smaller than that in the underlying object.
135 else if (fp
->_flags
& __SWR
&& fp
->_p
!= NULL
)
138 * Writing. Any buffered characters cause the
139 * position to be greater than that in the
142 pos
+= fp
->_p
- fp
->_bf
._base
;
145 _newlib_flockfile_end(fp
);
146 return (_off64_t
) pos
;
152 ftello64 (register FILE * fp
)
154 return _ftello64_r (_REENT
, fp
);
157 #endif /* !_REENT_ONLY */
159 #endif /* __LARGE64_FILES */