fixed more binutils issues (newer gcc/libc)
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / stdio64 / ftello64.c
blobaaf0f023e87acca41dc00c0e34ca7c0eee5bf99d
1 /*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
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.
19 FUNCTION
20 <<ftello64>>---return position in a stream or file
22 INDEX
23 ftello64
24 INDEX
25 _ftello64_r
27 ANSI_SYNOPSIS
28 #include <stdio.h>
29 _off64_t ftello64(FILE *<[fp]>);
30 _off64_t _ftello64_r(struct _reent *<[ptr]>, FILE *<[fp]>);
32 TRAD_SYNOPSIS
33 #include <stdio.h>
34 _off64_t ftello64(<[fp]>)
35 FILE *<[fp]>;
37 _off64_t _ftello64_r(<[ptr]>, <[fp]>)
38 struct _reent *<[ptr]>;
39 FILE *<[fp]>;
41 DESCRIPTION
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>>.
60 RETURNS
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>>.
66 PORTABILITY
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.
80 #include <stdio.h>
81 #include <errno.h>
83 #include "local64.h"
85 #ifdef __LARGE64_FILES
87 _off64_t
88 _DEFUN (_ftello64_r, (ptr, fp),
89 struct _reent *ptr _AND
90 register FILE * fp)
92 _fpos64_t pos;
94 _flockfile(fp);
96 /* Ensure stdio is set up. */
98 CHECK_INIT (fp);
100 if (fp->_seek64 == NULL)
102 ptr->_errno = ESPIPE;
103 _funlockfile(fp);
104 return -1L;
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)
111 pos = fp->_offset;
112 else
114 pos = (*fp->_seek64) (fp->_cookie, (_fpos64_t) 0, SEEK_CUR);
115 if (pos == -1L)
117 _funlockfile(fp);
118 return pos;
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.
128 pos -= fp->_r;
129 if (HASUB (fp))
130 pos -= fp->_ur;
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
137 * underlying object.
139 pos += fp->_p - fp->_bf._base;
142 _funlockfile(fp);
143 return pos;
146 #ifndef _REENT_ONLY
148 _off64_t
149 _DEFUN (ftello64, (fp),
150 register FILE * fp)
152 return _ftello64_r (_REENT, fp);
155 #endif /* !_REENT_ONLY */
157 #endif /* __LARGE64_FILES */