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 * advertising materials, and 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]>);
34 _off64_t ftello64(<[fp]>)
37 _off64_t _ftello64_r(<[ptr]>, <[fp]>)
38 struct _reent *<[ptr]>;
42 Objects of type <<FILE>> can have a ``position'' that records how much
43 of the file your program has already read. Many of the <<stdio>> functions
44 depend on this position, and many change it as a side effect.
46 The result of <<ftello64>> is the current position for a large file
47 identified by <[fp]>. If you record this result, you can later
48 use it with <<fseeko64>> to return the file to this
49 position. The difference between <<ftello>> and <<ftello64>> is that
50 <<ftello>> returns <<off_t>> and <<ftello64>> is designed to work
51 for large files (>2GB) and returns <<_off64_t>>.
53 In the current implementation, <<ftello64>> simply uses a character
54 count to represent the file position; this is the same number that
55 would be recorded by <<fgetpos64>>.
57 The function exists only if the __LARGE64_FILES flag is defined.
58 An error occurs if the <[fp]> was not opened via <<fopen64>>.
61 <<ftello64>> returns the file position, if possible. If it cannot do
62 this, it returns <<-1>>. Failure occurs on streams that do not support
63 positioning or not opened via <<fopen64>>; the global <<errno>> indicates
64 this condition with the value <<ESPIPE>>.
67 <<ftello64>> is a glibc extension.
69 No supporting OS subroutines are required.
72 #if defined(LIBC_SCCS) && !defined(lint)
73 static char sccsid
[] = "%W% (Berkeley) %G%";
74 #endif /* LIBC_SCCS and not lint */
77 * ftello64: return current offset.
85 #ifdef __LARGE64_FILES
88 _DEFUN (_ftello64_r
, (ptr
, fp
),
89 struct _reent
*ptr _AND
96 /* Ensure stdio is set up. */
100 if (fp
->_seek64
== NULL
)
102 ptr
->_errno
= ESPIPE
;
107 /* Find offset of underlying I/O object, then
108 adjust for buffered bytes. */
109 fflush(fp
); /* may adjust seek offset on append stream */
110 if (fp
->_flags
& __SOFF
)
114 pos
= (*fp
->_seek64
) (fp
->_cookie
, (_fpos64_t
) 0, SEEK_CUR
);
121 if (fp
->_flags
& __SRD
)
124 * Reading. Any unread characters (including
125 * those from ungetc) cause the position to be
126 * smaller than that in the underlying object.
132 else if (fp
->_flags
& __SWR
&& fp
->_p
!= NULL
)
135 * Writing. Any buffered characters cause the
136 * position to be greater than that in the
139 pos
+= fp
->_p
- fp
->_bf
._base
;
149 _DEFUN (ftello64
, (fp
),
152 return _ftello64_r (_REENT
, fp
);
155 #endif /* !_REENT_ONLY */
157 #endif /* __LARGE64_FILES */