Rev 4874 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 1990 The Regents of the University of California. |
2 | * Copyright (c) 1990 The Regents of the University of California. |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms are permitted |
5 | * Redistribution and use in source and binary forms are permitted |
6 | * provided that the above copyright notice and this paragraph are |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, |
7 | * duplicated in all such forms and that any documentation, |
8 | * advertising materials, and other materials related to such |
8 | * advertising materials, and other materials related to such |
9 | * distribution and use acknowledge that the software was developed |
9 | * distribution and use acknowledge that the software was developed |
10 | * by the University of California, Berkeley. The name of the |
10 | * by the University of California, Berkeley. The name of the |
11 | * University may not be used to endorse or promote products derived |
11 | * University may not be used to endorse or promote products derived |
12 | * from this software without specific prior written permission. |
12 | * from this software without specific prior written permission. |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
16 | */ |
16 | */ |
17 | 17 | ||
18 | /* |
18 | /* |
19 | FUNCTION |
19 | FUNCTION |
20 | < |
20 | < |
21 | 21 | ||
22 | INDEX |
22 | INDEX |
23 | ftell |
23 | ftell |
24 | INDEX |
24 | INDEX |
25 | ftello |
25 | ftello |
26 | INDEX |
26 | INDEX |
27 | _ftell_r |
27 | _ftell_r |
28 | INDEX |
28 | INDEX |
29 | _ftello_r |
29 | _ftello_r |
30 | 30 | ||
31 | ANSI_SYNOPSIS |
31 | ANSI_SYNOPSIS |
32 | #include |
32 | #include |
33 | long ftell(FILE *<[fp]>); |
33 | long ftell(FILE *<[fp]>); |
34 | off_t ftello(FILE *<[fp]>); |
34 | off_t ftello(FILE *<[fp]>); |
35 | long _ftell_r(struct _reent *<[ptr]>, FILE *<[fp]>); |
35 | long _ftell_r(struct _reent *<[ptr]>, FILE *<[fp]>); |
36 | off_t _ftello_r(struct _reent *<[ptr]>, FILE *<[fp]>); |
36 | off_t _ftello_r(struct _reent *<[ptr]>, FILE *<[fp]>); |
37 | 37 | ||
38 | TRAD_SYNOPSIS |
38 | TRAD_SYNOPSIS |
39 | #include |
39 | #include |
40 | long ftell(<[fp]>) |
40 | long ftell(<[fp]>) |
41 | FILE *<[fp]>; |
41 | FILE *<[fp]>; |
42 | 42 | ||
43 | off_t ftello(<[fp]>) |
43 | off_t ftello(<[fp]>) |
44 | FILE *<[fp]>; |
44 | FILE *<[fp]>; |
45 | 45 | ||
46 | long _ftell_r(<[ptr]>, <[fp]>) |
46 | long _ftell_r(<[ptr]>, <[fp]>) |
47 | struct _reent *<[ptr]>; |
47 | struct _reent *<[ptr]>; |
48 | FILE *<[fp]>; |
48 | FILE *<[fp]>; |
49 | 49 | ||
50 | off_t _ftello_r(<[ptr]>, <[fp]>) |
50 | off_t _ftello_r(<[ptr]>, <[fp]>) |
51 | struct _reent *<[ptr]>; |
51 | struct _reent *<[ptr]>; |
52 | FILE *<[fp]>; |
52 | FILE *<[fp]>; |
53 | 53 | ||
54 | DESCRIPTION |
54 | DESCRIPTION |
55 | Objects of type < |
55 | Objects of type < |
56 | of the file your program has already read. Many of the < |
56 | of the file your program has already read. Many of the < |
57 | depend on this position, and many change it as a side effect. |
57 | depend on this position, and many change it as a side effect. |
58 | 58 | ||
59 | The result of < |
59 | The result of < |
60 | identified by <[fp]>. If you record this result, you can later |
60 | identified by <[fp]>. If you record this result, you can later |
61 | use it with < |
61 | use it with < |
62 | position. The difference between < |
62 | position. The difference between < |
63 | < |
63 | < |
64 | 64 | ||
65 | In the current implementation, < |
65 | In the current implementation, < |
66 | count to represent the file position; this is the same number that |
66 | count to represent the file position; this is the same number that |
67 | would be recorded by < |
67 | would be recorded by < |
68 | 68 | ||
69 | RETURNS |
69 | RETURNS |
70 | < |
70 | < |
71 | this, they return <<-1L>>. Failure occurs on streams that do not support |
71 | this, they return <<-1L>>. Failure occurs on streams that do not support |
72 | positioning; the global < |
72 | positioning; the global < |
73 | value < |
73 | value < |
74 | 74 | ||
75 | PORTABILITY |
75 | PORTABILITY |
76 | < |
76 | < |
77 | result (when successful) is not specified beyond requiring that it be |
77 | result (when successful) is not specified beyond requiring that it be |
78 | acceptable as an argument to < |
78 | acceptable as an argument to < |
79 | conforming C implementations may return a different result from |
79 | conforming C implementations may return a different result from |
80 | < |
80 | < |
81 | 81 | ||
82 | < |
82 | < |
83 | 83 | ||
84 | No supporting OS subroutines are required. |
84 | No supporting OS subroutines are required. |
85 | */ |
85 | */ |
86 | 86 | ||
87 | #if defined(LIBC_SCCS) && !defined(lint) |
87 | #if defined(LIBC_SCCS) && !defined(lint) |
88 | static char sccsid[] = "%W% (Berkeley) %G%"; |
88 | static char sccsid[] = "%W% (Berkeley) %G%"; |
89 | #endif /* LIBC_SCCS and not lint */ |
89 | #endif /* LIBC_SCCS and not lint */ |
90 | 90 | ||
91 | /* |
91 | /* |
92 | * ftell: return current offset. |
92 | * ftell: return current offset. |
93 | */ |
93 | */ |
94 | 94 | ||
95 | #include <_ansi.h> |
95 | #include <_ansi.h> |
96 | #include |
96 | #include |
97 | #include |
97 | #include |
98 | #include |
98 | #include |
99 | #include "local.h" |
99 | #include "local.h" |
100 | 100 | ||
101 | long |
101 | long |
102 | _DEFUN(_ftell_r, (ptr, fp), |
102 | _DEFUN(_ftell_r, (ptr, fp), |
103 | struct _reent *ptr _AND |
103 | struct _reent *ptr _AND |
104 | register FILE * fp) |
104 | register FILE * fp) |
105 | { |
105 | { |
106 | _fpos_t pos; |
106 | _fpos_t pos; |
107 | - | ||
108 | /* Ensure stdio is set up. */ |
- | |
109 | - | ||
110 | CHECK_INIT (ptr, fp); |
- | |
111 | - | ||
112 | _flockfile (fp); |
- | |
113 | - | ||
114 | if (fp->_seek == NULL) |
- | |
115 | { |
- | |
116 | ptr->_errno = ESPIPE; |
- | |
117 | _funlockfile (fp); |
- | |
118 | return -1L; |
- | |
119 | } |
- | |
120 | - | ||
121 | /* Find offset of underlying I/O object, then adjust for buffered |
- | |
122 | bytes. Flush a write stream, since the offset may be altered if |
- | |
123 | the stream is appending. Do not flush a read stream, since we |
- | |
124 | must not lose the ungetc buffer. */ |
- | |
125 | if (fp->_flags & __SWR) |
107 | |
126 | _fflush_r (ptr, fp); |
- | |
127 | if (fp->_flags & __SOFF) |
- | |
128 | pos = fp->_offset; |
- | |
129 | else |
- | |
130 | { |
- | |
131 | pos = fp->_seek (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR); |
- | |
132 | if (pos == -1L) |
- | |
133 | { |
- | |
134 | _funlockfile (fp); |
- | |
135 | return pos; |
- | |
136 | } |
- | |
137 | } |
- | |
138 | if (fp->_flags & __SRD) |
- | |
139 | { |
- | |
140 | /* |
- | |
141 | * Reading. Any unread characters (including |
- | |
142 | * those from ungetc) cause the position to be |
- | |
143 | * smaller than that in the underlying object. |
- | |
144 | */ |
- | |
145 | pos -= fp->_r; |
- | |
146 | if (HASUB (fp)) |
- | |
147 | pos -= fp->_ur; |
- | |
148 | } |
- | |
149 | else if ((fp->_flags & __SWR) && fp->_p != NULL) |
- | |
150 | { |
- | |
151 | /* |
- | |
152 | * Writing. Any buffered characters cause the |
- | |
153 | * position to be greater than that in the |
- | |
154 | * underlying object. |
- | |
155 | */ |
- | |
156 | pos += fp->_p - fp->_bf._base; |
- | |
157 | } |
- | |
158 | - | ||
159 | _funlockfile (fp); |
108 | pos = _ftello_r (ptr, fp); |
160 | if ((long)pos != pos) |
109 | if ((long)pos != pos) |
161 | { |
110 | { |
162 | pos = -1; |
111 | pos = -1; |
163 | ptr->_errno = EOVERFLOW; |
112 | ptr->_errno = EOVERFLOW; |
164 | } |
113 | } |
165 | return pos; |
114 | return (long)pos; |
166 | } |
115 | } |
167 | 116 | ||
168 | #ifndef _REENT_ONLY |
117 | #ifndef _REENT_ONLY |
169 | 118 | ||
170 | long |
119 | long |
171 | _DEFUN(ftell, (fp), |
120 | _DEFUN(ftell, (fp), |
172 | register FILE * fp) |
121 | register FILE * fp) |
173 | { |
122 | { |
174 | return _ftell_r (_REENT, fp); |
123 | return _ftell_r (_REENT, fp); |
175 | } |
124 | } |
176 | 125 | ||
177 | #endif /* !_REENT_ONLY */ |
126 | #endif /* !_REENT_ONLY */ |