| 2875 |
dpurdie |
1 |
#pragma force_top_level
|
|
|
2 |
#pragma include_only_once
|
|
|
3 |
|
|
|
4 |
/* stdio.h: ANSI 'C' (X3J11 Oct 88) library header, section 4.9 */
|
|
|
5 |
/* Copyright (C) Codemist Ltd. */
|
|
|
6 |
/* Copyright (C) Acorn Computers Ltd., 1988 */
|
|
|
7 |
/* version 0.07 */
|
|
|
8 |
|
|
|
9 |
/* AM July-88 changes to all prototypes so that */
|
|
|
10 |
/* #define mode 3; #include <stdio.h> can work as ANSI require. */
|
|
|
11 |
|
|
|
12 |
/*
|
|
|
13 |
* stdio.h declares two types, several macros, and many functions for
|
|
|
14 |
* performing input and output. For a discussion on Streams and Files
|
|
|
15 |
* refer to sections 4.9.2 and 4.9.3 in the above ANSI draft, or to a
|
|
|
16 |
* modern textbook on C.
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#ifndef __stdio_h
|
|
|
20 |
#define __stdio_h
|
|
|
21 |
|
|
|
22 |
#define __LIB_VERSION 310 /* 3.10, but int for PP inequality test */
|
|
|
23 |
|
|
|
24 |
#ifndef __size_t
|
|
|
25 |
#define __size_t 1
|
|
|
26 |
typedef unsigned int size_t; /* from <stddef.h> */
|
|
|
27 |
#endif
|
|
|
28 |
|
|
|
29 |
/* ANSI forbids va_list to be defined here */
|
|
|
30 |
typedef char *__va_list[1]; /* keep in step with <stdarg.h> */
|
|
|
31 |
|
|
|
32 |
#ifndef NULL
|
|
|
33 |
# define NULL 0 /* see <stddef.h> */
|
|
|
34 |
#endif
|
|
|
35 |
|
|
|
36 |
typedef struct __fpos_t_struct
|
|
|
37 |
{ unsigned long __lo; /* add hi one day */
|
|
|
38 |
} fpos_t;
|
|
|
39 |
/*
|
|
|
40 |
* fpos_t is an object capable of recording all information needed to
|
|
|
41 |
* specify uniquely every position within a file.
|
|
|
42 |
*/
|
|
|
43 |
|
|
|
44 |
typedef struct __FILE_struct
|
|
|
45 |
{ unsigned char *__ptr;
|
|
|
46 |
int __icnt; /* two separate _cnt fields so we can police ... */
|
|
|
47 |
int __ocnt; /* ... restrictions that read/write are fseek separated */
|
|
|
48 |
int __flag;
|
|
|
49 |
#ifdef __system_io
|
|
|
50 |
/* AM: the following things do NOT need __ prefixes as they are */
|
|
|
51 |
/* are invisible in an ANSI-conforming program. */
|
|
|
52 |
unsigned char *__base; /* buffer base */
|
|
|
53 |
FILEHANDLE __file; /* RISCOS/Arthur/Brazil file handle */
|
|
|
54 |
long __pos; /* position in file */
|
|
|
55 |
int __bufsiz; /* maximum buffer size */
|
|
|
56 |
int __signature; /* used with temporary files */
|
|
|
57 |
struct __extradata *__extrap; /* pointer to information about stream */
|
|
|
58 |
#else
|
|
|
59 |
int :32,:32,:32,:32,:32,:32;
|
|
|
60 |
#endif
|
|
|
61 |
} FILE;
|
|
|
62 |
/*
|
|
|
63 |
* FILE is an object capable of recording all information needed to control
|
|
|
64 |
* a stream, such as its file position indicator, a pointer to its
|
|
|
65 |
* associated buffer, an error indicator that records whether a read/write
|
|
|
66 |
* error has occurred and an end-of-file indicator that records whether the
|
|
|
67 |
* end-of-file has been reached.
|
|
|
68 |
* N.B. the objects contained in the #ifdef __system_io clause are for
|
|
|
69 |
* system use only.
|
|
|
70 |
*/
|
|
|
71 |
|
|
|
72 |
#ifdef __system_io
|
|
|
73 |
# define _IOREAD 0x01 /* system use - open for input */
|
|
|
74 |
# define _IOWRITE 0x02 /* system use - open for output */
|
|
|
75 |
# define _IOBIN 0x04 /* system use - binary stream */
|
|
|
76 |
# define _IOSTRG 0x08 /* system use - string stream */
|
|
|
77 |
# define _IOSEEK 0x10 /* system use - physical seek required before IO */
|
|
|
78 |
# define _IOLAZY 0x20 /* system use - possible seek pending */
|
|
|
79 |
# define _IOSBF 0x800 /* system use - system allocated buffer */
|
|
|
80 |
# define _IOAPPEND 0x08000 /* system use - must seek to eof before write */
|
|
|
81 |
#endif
|
|
|
82 |
#define _IOEOF 0x40 /* end-of-file reached */
|
|
|
83 |
#define _IOERR 0x80 /* error occurred on stream */
|
|
|
84 |
#define _IOFBF 0x100 /* fully buffered IO */
|
|
|
85 |
#define _IOLBF 0x200 /* line buffered IO */
|
|
|
86 |
#define _IONBF 0x400 /* unbuffered IO */
|
|
|
87 |
|
|
|
88 |
#define BUFSIZ (4096) /* system buffer size (as used by setbuf) */
|
|
|
89 |
#define EOF (-1)
|
|
|
90 |
/*
|
|
|
91 |
* negative integral constant, indicates end-of-file, that is, no more input
|
|
|
92 |
* from a stream.
|
|
|
93 |
*/
|
|
|
94 |
/* It is not clear to me what value FOPEN_MAX should have, so I will
|
|
|
95 |
err in the cautious direction - ANSI requires it to be at least 8 */
|
|
|
96 |
#define FOPEN_MAX 8 /* check re arthur/unix/mvs */
|
|
|
97 |
/*
|
|
|
98 |
* an integral constant expression that is the minimum number of files that
|
|
|
99 |
* this implementation guarantees can be open simultaneously.
|
|
|
100 |
*/
|
|
|
101 |
/* _SYS_OPEN defines a limit on the number of open files that is imposed
|
|
|
102 |
by this C library */
|
|
|
103 |
#define _SYS_OPEN 16
|
|
|
104 |
#define FILENAME_MAX 80
|
|
|
105 |
/*
|
|
|
106 |
* an integral constant expression that is the size of an array of char
|
|
|
107 |
* large enough to hold the longest filename string
|
|
|
108 |
*/
|
|
|
109 |
#define L_tmpnam FILENAME_MAX
|
|
|
110 |
/*
|
|
|
111 |
* an integral constant expression that is the size of an array of char
|
|
|
112 |
* large enough to hold a temporary file name string generated by the
|
|
|
113 |
* tmpnam function.
|
|
|
114 |
*/
|
|
|
115 |
|
|
|
116 |
#define SEEK_SET 0 /* start of stream (see fseek) */
|
|
|
117 |
#define SEEK_CUR 1 /* current position in stream (see fseek) */
|
|
|
118 |
#define SEEK_END 2 /* end of stream (see fseek) */
|
|
|
119 |
|
|
|
120 |
#define TMP_MAX 1000000000
|
|
|
121 |
/*
|
|
|
122 |
* an integral constant expression that is the minimum number of unique
|
|
|
123 |
* file names that shall be generated by the tmpnam function.
|
|
|
124 |
*/
|
|
|
125 |
|
|
|
126 |
extern FILE __iob[];
|
|
|
127 |
/* an array of file objects for use by the system. */
|
|
|
128 |
|
|
|
129 |
#define stdin (&__iob[0])
|
|
|
130 |
/* pointer to a FILE object associated with standard input stream */
|
|
|
131 |
#define stdout (&__iob[1])
|
|
|
132 |
/* pointer to a FILE object associated with standard output stream */
|
|
|
133 |
#define stderr (&__iob[2])
|
|
|
134 |
/* pointer to a FILE object associated with standard error stream */
|
|
|
135 |
|
|
|
136 |
extern int remove(const char * /*filename*/);
|
|
|
137 |
/*
|
|
|
138 |
* causes the file whose name is the string pointed to by filename to be
|
|
|
139 |
* removed. Subsequent attempts to open the file will fail, unless it is
|
|
|
140 |
* created anew. If the file is open, the behaviour of the remove function
|
|
|
141 |
* is implementation-defined (under RISCOS/Arthur/Brazil the operation
|
|
|
142 |
* fails).
|
|
|
143 |
* Returns: zero if the operation succeeds, nonzero if it fails.
|
|
|
144 |
*/
|
|
|
145 |
extern int rename(const char * /*old*/, const char * /*new*/);
|
|
|
146 |
/*
|
|
|
147 |
* causes the file whose name is the string pointed to by old to be
|
|
|
148 |
* henceforth known by the name given by the string pointed to by new. The
|
|
|
149 |
* file named old is effectively removed. If a file named by the string
|
|
|
150 |
* pointed to by new exists prior to the call of the rename function, the
|
|
|
151 |
* behaviour is implementation-defined (under RISCOS/Arthur/Brazil, the
|
|
|
152 |
* operation fails).
|
|
|
153 |
* Returns: zero if the operation succeeds, nonzero if it fails, in which
|
|
|
154 |
* case if the file existed previously it is still known by its
|
|
|
155 |
* original name.
|
|
|
156 |
*/
|
|
|
157 |
extern FILE *tmpfile(void);
|
|
|
158 |
/*
|
|
|
159 |
* creates a temporary binary file that will be automatically removed when
|
|
|
160 |
* it is closed or at program termination. The file is opened for update.
|
|
|
161 |
* Returns: a pointer to the stream of the file that it created. If the file
|
|
|
162 |
* cannot be created, a null pointer is returned.
|
|
|
163 |
*/
|
|
|
164 |
extern char *tmpnam(char * /*s*/);
|
|
|
165 |
/*
|
|
|
166 |
* generates a string that is not the same as the name of an existing file.
|
|
|
167 |
* The tmpnam function generates a different string each time it is called,
|
|
|
168 |
* up to TMP_MAX times. If it is called more than TMP_MAX times, the
|
|
|
169 |
* behaviour is implementation-defined (under RISCOS/Arthur/Brazil the
|
|
|
170 |
* algorithm for the name generation works just as well after tmpnam has
|
|
|
171 |
* been called more than TMP_MAX times as before; a name clash is impossible
|
|
|
172 |
* in any single half year period).
|
|
|
173 |
* Returns: If the argument is a null pointer, the tmpnam function leaves
|
|
|
174 |
* its result in an internal static object and returns a pointer to
|
|
|
175 |
* that object. Subsequent calls to the tmpnam function may modify
|
|
|
176 |
* the same object. if the argument is not a null pointer, it is
|
|
|
177 |
* assumed to point to an array of at least L_tmpnam characters;
|
|
|
178 |
* the tmpnam function writes its result in that array and returns
|
|
|
179 |
* the argument as its value.
|
|
|
180 |
*/
|
|
|
181 |
|
|
|
182 |
extern int fclose(FILE * /*stream*/);
|
|
|
183 |
/*
|
|
|
184 |
* causes the stream pointed to by stream to be flushed and the associated
|
|
|
185 |
* file to be closed. Any unwritten buffered data for the stream are
|
|
|
186 |
* delivered to the host environment to be written to the file; any unread
|
|
|
187 |
* buffered data are discarded. The stream is disassociated from the file.
|
|
|
188 |
* If the associated buffer was automatically allocated, it is deallocated.
|
|
|
189 |
* Returns: zero if the stream was succesfully closed, or nonzero if any
|
|
|
190 |
* errors were detected or if the stream was already closed.
|
|
|
191 |
*/
|
|
|
192 |
extern int fflush(FILE * /*stream*/);
|
|
|
193 |
/*
|
|
|
194 |
* If the stream points to an output or update stream in which the most
|
|
|
195 |
* recent operation was output, the fflush function causes any unwritten
|
|
|
196 |
* data for that stream to be delivered to the host environment to be
|
|
|
197 |
* written to the file. If the stream points to an input or update stream,
|
|
|
198 |
* the fflush function undoes the effect of any preceding ungetc operation
|
|
|
199 |
* on the stream.
|
|
|
200 |
* Returns: nonzero if a write error occurs.
|
|
|
201 |
*/
|
|
|
202 |
extern FILE *fopen(const char * /*filename*/, const char * /*mode*/);
|
|
|
203 |
/*
|
|
|
204 |
* opens the file whose name is the string pointed to by filename, and
|
|
|
205 |
* associates a stream with it.
|
|
|
206 |
* The argument mode points to a string beginning with one of the following
|
|
|
207 |
* sequences:
|
|
|
208 |
* "r" open text file for reading
|
|
|
209 |
* "w" create text file for writing, or truncate to zero length
|
|
|
210 |
* "a" append; open text file or create for writing at eof
|
|
|
211 |
* "rb" open binary file for reading
|
|
|
212 |
* "wb" create binary file for writing, or truncate to zero length
|
|
|
213 |
* "ab" append; open binary file or create for writing at eof
|
|
|
214 |
* "r+" open text file for update (reading and writing)
|
|
|
215 |
* "w+" create text file for update, or truncate to zero length
|
|
|
216 |
* "a+" append; open text file or create for update, writing at eof
|
|
|
217 |
* "r+b"/"rb+" open binary file for update (reading and writing)
|
|
|
218 |
* "w+b"/"wb+" create binary file for update, or truncate to zero length
|
|
|
219 |
* "a+b"/"ab+" append; open binary file or create for update, writing at eof
|
|
|
220 |
*
|
|
|
221 |
* Opening a file with read mode ('r' as the first character in the mode
|
|
|
222 |
* argument) fails if the file does not exist or cannot be read.
|
|
|
223 |
* Opening a file with append mode ('a' as the first character in the mode
|
|
|
224 |
* argument) causes all subsequent writes to be forced to the current end of
|
|
|
225 |
* file, regardless of intervening calls to the fseek function. In some
|
|
|
226 |
* implementations, opening a binary file with append mode ('b' as the
|
|
|
227 |
* second or third character in the mode argument) may initially position
|
|
|
228 |
* the file position indicator beyond the last data written, because of the
|
|
|
229 |
* NUL padding (but not under RISCOS/Arthur/Brazil).
|
|
|
230 |
* When a file is opened with update mode ('+' as the second or third
|
|
|
231 |
* character in the mode argument), both input and output may be performed
|
|
|
232 |
* on the associated stream. However, output may not be directly followed by
|
|
|
233 |
* input without an intervening call to the fflush fuction or to a file
|
|
|
234 |
* positioning function (fseek, fsetpos, or rewind), and input be not be
|
|
|
235 |
* directly followed by output without an intervening call to the fflush
|
|
|
236 |
* fuction or to a file positioning function, unless the input operation
|
|
|
237 |
* encounters end-of-file. Opening a file with update mode may open or
|
|
|
238 |
* create a binary stream in some implementations (but not under RISCOS/
|
|
|
239 |
* Arthur/Brazil). When opened, a stream is fully buffered if and only if
|
|
|
240 |
* it does not refer to an interactive device. The error and end-of-file
|
|
|
241 |
* indicators for the stream are cleared.
|
|
|
242 |
* Returns: a pointer to the object controlling the stream. If the open
|
|
|
243 |
* operation fails, fopen returns a null pointer.
|
|
|
244 |
*/
|
|
|
245 |
extern FILE *freopen(const char * /*filename*/, const char * /*mode*/,
|
|
|
246 |
FILE * /*stream*/);
|
|
|
247 |
/*
|
|
|
248 |
* opens the file whose name is the string pointed to by filename and
|
|
|
249 |
* associates the stream pointed to by stream with it. The mode argument is
|
|
|
250 |
* used just as in the fopen function.
|
|
|
251 |
* The freopen function first attempts to close any file that is associated
|
|
|
252 |
* with the specified stream. Failure to close the file successfully is
|
|
|
253 |
* ignored. The error and end-of-file indicators for the stream are cleared.
|
|
|
254 |
* Returns: a null pointer if the operation fails. Otherwise, freopen
|
|
|
255 |
* returns the value of the stream.
|
|
|
256 |
*/
|
|
|
257 |
extern void setbuf(FILE * /*stream*/, char * /*buf*/);
|
|
|
258 |
/*
|
|
|
259 |
* Except that it returns no value, the setbuf function is equivalent to the
|
|
|
260 |
* setvbuf function invoked with the values _IOFBF for mode and BUFSIZ for
|
|
|
261 |
* size, or (if buf is a null pointer), with the value _IONBF for mode.
|
|
|
262 |
* Returns: no value.
|
|
|
263 |
*/
|
|
|
264 |
extern int setvbuf(FILE * /*stream*/, char * /*buf*/,
|
|
|
265 |
int /*mode*/, size_t /*size*/);
|
|
|
266 |
/*
|
|
|
267 |
* may be used after the stream pointed to by stream has been associated
|
|
|
268 |
* with an open file but before it is read or written. The argument mode
|
|
|
269 |
* determines how stream will be buffered, as follows: _IOFBF causes
|
|
|
270 |
* input/output to be fully buffered; _IOLBF causes output to be line
|
|
|
271 |
* buffered (the buffer will be flushed when a new-line character is
|
|
|
272 |
* written, when the buffer is full, or when input is requested); _IONBF
|
|
|
273 |
* causes input/output to be completely unbuffered. If buf is not the null
|
|
|
274 |
* pointer, the array it points to may be used instead of an automatically
|
|
|
275 |
* allocated buffer (the buffer must have a lifetime at least as great as
|
|
|
276 |
* the open stream, so the stream should be closed before a buffer that has
|
|
|
277 |
* automatic storage duration is deallocated upon block exit). The argument
|
|
|
278 |
* size specifies the size of the array. The contents of the array at any
|
|
|
279 |
* time are indeterminate.
|
|
|
280 |
* Returns: zero on success, or nonzero if an invalid value is given for
|
|
|
281 |
* mode or size, or if the request cannot be honoured.
|
|
|
282 |
*/
|
|
|
283 |
|
|
|
284 |
#pragma -v1 /* hint to the compiler to check f/s/printf format */
|
|
|
285 |
extern int fprintf(FILE * /*stream*/, const char * /*format*/, ...);
|
|
|
286 |
/*
|
|
|
287 |
* writes output to the stream pointed to by stream, under control of the
|
|
|
288 |
* string pointed to by format that specifies how subsequent arguments are
|
|
|
289 |
* converted for output. If there are insufficient arguments for the format,
|
|
|
290 |
* the behaviour is undefined. If the format is exhausted while arguments
|
|
|
291 |
* remain, the excess arguments are evaluated but otherwise ignored. The
|
|
|
292 |
* fprintf function returns when the end of the format string is reached.
|
|
|
293 |
* The format shall be a multibyte character sequence, beginning and ending
|
|
|
294 |
* in its initial shift state. The format is composed of zero or more
|
|
|
295 |
* directives: ordinary multibyte characters (not %), which are copied
|
|
|
296 |
* unchanged to the output stream; and conversion specifiers, each of which
|
|
|
297 |
* results in fetching zero or more subsequent arguments. Each conversion
|
|
|
298 |
* specification is introduced by the character %. For a description of the
|
|
|
299 |
* available conversion specifiers refer to section 4.9.6.1 in the ANSI
|
|
|
300 |
* draft mentioned at the start of this file or to any modern textbook on C.
|
|
|
301 |
* The minimum value for the maximum number of characters producable by any
|
|
|
302 |
* single conversion is at least 509.
|
|
|
303 |
* Returns: the number of characters transmitted, or a negative value if an
|
|
|
304 |
* output error occurred.
|
|
|
305 |
*/
|
|
|
306 |
extern int printf(const char * /*format*/, ...);
|
|
|
307 |
/*
|
|
|
308 |
* is equivalent to fprintf with the argument stdout interposed before the
|
|
|
309 |
* arguments to printf.
|
|
|
310 |
* Returns: the number of characters transmitted, or a negative value if an
|
|
|
311 |
* output error occurred.
|
|
|
312 |
*/
|
|
|
313 |
extern int sprintf(char * /*s*/, const char * /*format*/, ...);
|
|
|
314 |
/*
|
|
|
315 |
* is equivalent to fprintf, except that the argument s specifies an array
|
|
|
316 |
* into which the generated output is to be written, rather than to a
|
|
|
317 |
* stream. A null character is written at the end of the characters written;
|
|
|
318 |
* it is not counted as part of the returned sum.
|
|
|
319 |
* Returns: the number of characters written to the array, not counting the
|
|
|
320 |
* terminating null character.
|
|
|
321 |
*/
|
|
|
322 |
#pragma -v2 /* hint to the compiler to check f/s/scanf format */
|
|
|
323 |
extern int fscanf(FILE * /*stream*/, const char * /*format*/, ...);
|
|
|
324 |
/*
|
|
|
325 |
* reads input from the stream pointed to by stream, under control of the
|
|
|
326 |
* string pointed to by format that specifies the admissible input sequences
|
|
|
327 |
* and how thay are to be converted for assignment, using subsequent
|
|
|
328 |
* arguments as pointers to the objects to receive the converted input. If
|
|
|
329 |
* there are insufficient arguments for the format, the behaviour is
|
|
|
330 |
* undefined. If the format is exhausted while arguments remain, the excess
|
|
|
331 |
* arguments are evaluated but otherwise ignored.
|
|
|
332 |
* The format is composed of zero or more directives: one or more
|
|
|
333 |
* white-space characters; an ordinary character (not %); or a conversion
|
|
|
334 |
* specification. Each conversion specification is introduced by the
|
|
|
335 |
* character %. For a description of the available conversion specifiers
|
|
|
336 |
* refer to section 4.9.6.2 in the ANSI draft mentioned at the start of this
|
|
|
337 |
* file, or to any modern textbook on C.
|
|
|
338 |
* If end-of-file is encountered during input, conversion is terminated. If
|
|
|
339 |
* end-of-file occurs before any characters matching the current directive
|
|
|
340 |
* have been read (other than leading white space, where permitted),
|
|
|
341 |
* execution of the current directive terminates with an input failure;
|
|
|
342 |
* otherwise, unless execution of the current directive is terminated with a
|
|
|
343 |
* matching failure, execution of the following directive (if any) is
|
|
|
344 |
* terminated with an input failure.
|
|
|
345 |
* If conversions terminates on a conflicting input character, the offending
|
|
|
346 |
* input character is left unread in the input strem. Trailing white space
|
|
|
347 |
* (including new-line characters) is left unread unless matched by a
|
|
|
348 |
* directive. The success of literal matches and suppressed asignments is
|
|
|
349 |
* not directly determinable other than via the %n directive.
|
|
|
350 |
* Returns: the value of the macro EOF if an input failure occurs before any
|
|
|
351 |
* conversion. Otherwise, the fscanf function returns the number of
|
|
|
352 |
* input items assigned, which can be fewer than provided for, or
|
|
|
353 |
* even zero, in the event of an early conflict between an input
|
|
|
354 |
* character and the format.
|
|
|
355 |
*/
|
|
|
356 |
extern int scanf(const char * /*format*/, ...);
|
|
|
357 |
/*
|
|
|
358 |
* is equivalent to fscanf with the argument stdin interposed before the
|
|
|
359 |
* arguments to scanf.
|
|
|
360 |
* Returns: the value of the macro EOF if an input failure occurs before any
|
|
|
361 |
* conversion. Otherwise, the scanf function returns the number of
|
|
|
362 |
* input items assigned, which can be fewer than provided for, or
|
|
|
363 |
* even zero, in the event of an early matching failure.
|
|
|
364 |
*/
|
|
|
365 |
extern int sscanf(const char * /*s*/, const char * /*format*/, ...);
|
|
|
366 |
/*
|
|
|
367 |
* is equivalent to fscanf except that the argument s specifies a string
|
|
|
368 |
* from which the input is to be obtained, rather than from a stream.
|
|
|
369 |
* Reaching the end of the string is equivalent to encountering end-of-file
|
|
|
370 |
* for the fscanf function.
|
|
|
371 |
* Returns: the value of the macro EOF if an input failure occurs before any
|
|
|
372 |
* conversion. Otherwise, the scanf function returns the number of
|
|
|
373 |
* input items assigned, which can be fewer than provided for, or
|
|
|
374 |
* even zero, in the event of an early matching failure.
|
|
|
375 |
*/
|
|
|
376 |
#pragma -v0 /* back to default */
|
|
|
377 |
extern int vprintf(const char * /*format*/, __va_list /*arg*/);
|
|
|
378 |
/*
|
|
|
379 |
* is equivalent to printf, with the variable argument list replaced by arg,
|
|
|
380 |
* which has been initialised by the va_start macro (and possibly subsequent
|
|
|
381 |
* va_arg calls). The vprintf function does not invoke the va_end function.
|
|
|
382 |
* Returns: the number of characters transmitted, or a negative value if an
|
|
|
383 |
* output error occurred.
|
|
|
384 |
*/
|
|
|
385 |
extern int vfprintf(FILE * /*stream*/,
|
|
|
386 |
const char * /*format*/, __va_list /*arg*/);
|
|
|
387 |
/*
|
|
|
388 |
* is equivalent to fprintf, with the variable argument list replaced by
|
|
|
389 |
* arg, which has been initialised by the va_start macro (and possibly
|
|
|
390 |
* subsequent va_arg calls). The vfprintf function does not invoke the
|
|
|
391 |
* va_end function.
|
|
|
392 |
* Returns: the number of characters transmitted, or a negative value if an
|
|
|
393 |
* output error occurred.
|
|
|
394 |
*/
|
|
|
395 |
extern int vsprintf(char * /*s*/, const char * /*format*/, __va_list /*arg*/);
|
|
|
396 |
/*
|
|
|
397 |
* is equivalent to sprintf, with the variable argument list replaced by
|
|
|
398 |
* arg, which has been initialised by the va_start macro (and possibly
|
|
|
399 |
* subsequent va_arg calls). The vsprintf function does not invoke the
|
|
|
400 |
* va_end function.
|
|
|
401 |
* Returns: the number of characters written in the array, not counting the
|
|
|
402 |
* terminating null character.
|
|
|
403 |
*/
|
|
|
404 |
|
|
|
405 |
extern int fgetc(FILE * /*stream*/);
|
|
|
406 |
/*
|
|
|
407 |
* obtains the next character (if present) as an unsigned char converted to
|
|
|
408 |
* an int, from the input stream pointed to by stream, and advances the
|
|
|
409 |
* associated file position indicator (if defined).
|
|
|
410 |
* Returns: the next character from the input stream pointed to by stream.
|
|
|
411 |
* If the stream is at end-of-file, the end-of-file indicator is
|
|
|
412 |
* set and fgetc returns EOF. If a read error occurs, the error
|
|
|
413 |
* indicator is set and fgetc returns EOF.
|
|
|
414 |
*/
|
|
|
415 |
extern char *fgets(char * /*s*/, int /*n*/, FILE * /*stream*/);
|
|
|
416 |
/*
|
|
|
417 |
* reads at most one less than the number of characters specified by n from
|
|
|
418 |
* the stream pointed to by stream into the array pointed to by s. No
|
|
|
419 |
* additional characters are read after a new-line character (which is
|
|
|
420 |
* retained) or after end-of-file. A null character is written immediately
|
|
|
421 |
* after the last character read into the array.
|
|
|
422 |
* Returns: s if successful. If end-of-file is encountered and no characters
|
|
|
423 |
* have been read into the array, the contents of the array remain
|
|
|
424 |
* unchanged and a null pointer is returned. If a read error occurs
|
|
|
425 |
* during the operation, the array contents are indeterminate and a
|
|
|
426 |
* null pointer is returned.
|
|
|
427 |
*/
|
|
|
428 |
extern int fputc(int /*c*/, FILE * /*stream*/);
|
|
|
429 |
/*
|
|
|
430 |
* writes the character specified by c (converted to an unsigned char) to
|
|
|
431 |
* the output stream pointed to by stream, at the position indicated by the
|
|
|
432 |
* asociated file position indicator (if defined), and advances the
|
|
|
433 |
* indicator appropriately. If the file position indicator is not defined,
|
|
|
434 |
* the character is appended to the output stream.
|
|
|
435 |
* Returns: the character written. If a write error occurs, the error
|
|
|
436 |
* indicator is set and fputc returns EOF.
|
|
|
437 |
*/
|
|
|
438 |
extern int fputs(const char * /*s*/, FILE * /*stream*/);
|
|
|
439 |
/*
|
|
|
440 |
* writes the string pointed to by s to the stream pointed to by stream.
|
|
|
441 |
* The terminating null character is not written.
|
|
|
442 |
* Returns: EOF if a write error occurs; otherwise it returns a nonnegative
|
|
|
443 |
* value.
|
|
|
444 |
*/
|
|
|
445 |
extern int __filbuf(FILE * /*stream*/);
|
|
|
446 |
/*
|
|
|
447 |
* SYSTEM USE ONLY, called by getc to refill buffer and or sort out flags.
|
|
|
448 |
* Returns: first character put into buffer or EOF on error.
|
|
|
449 |
*/
|
|
|
450 |
#define getc(p) \
|
|
|
451 |
(--((p)->__icnt) >= 0 ? *((p)->__ptr)++ : __filbuf(p))
|
|
|
452 |
extern int (getc)(FILE * /*stream*/);
|
|
|
453 |
/*
|
|
|
454 |
* is equivalent to fgetc except that it may be (and is under
|
|
|
455 |
* RISCOS/Arthur/Brazil) implemented as a macro. stream may be evaluated
|
|
|
456 |
* more than once, so the argument should never be an expression with side
|
|
|
457 |
* effects.
|
|
|
458 |
* Returns: the next character from the input stream pointed to by stream.
|
|
|
459 |
* If the stream is at end-of-file, the end-of-file indicator is
|
|
|
460 |
* set and getc returns EOF. If a read error occurs, the error
|
|
|
461 |
* indicator is set and getc returns EOF.
|
|
|
462 |
*/
|
|
|
463 |
#define getchar() getc(stdin)
|
|
|
464 |
extern int (getchar)(void);
|
|
|
465 |
/*
|
|
|
466 |
* is equivalent to getc with the argument stdin.
|
|
|
467 |
* Returns: the next character from the input stream pointed to by stdin.
|
|
|
468 |
* If the stream is at end-of-file, the end-of-file indicator is
|
|
|
469 |
* set and getchar returns EOF. If a read error occurs, the error
|
|
|
470 |
* indicator is set and getchar returns EOF.
|
|
|
471 |
*/
|
|
|
472 |
extern char *gets(char * /*s*/);
|
|
|
473 |
/*
|
|
|
474 |
* reads characters from the input stream pointed to by stdin into the array
|
|
|
475 |
* pointed to by s, until end-of-file is encountered or a new-line character
|
|
|
476 |
* is read. Any new-line character is discarded, and a null character is
|
|
|
477 |
* written immediately after the last character read into the array.
|
|
|
478 |
* Returns: s if successful. If end-of-file is encountered and no characters
|
|
|
479 |
* have been read into the array, the contents of the array remain
|
|
|
480 |
* unchanged and a null pointer is returned. If a read error occurs
|
|
|
481 |
* during the operation, the array contents are indeterminate and a
|
|
|
482 |
* null pointer is returned.
|
|
|
483 |
*/
|
|
|
484 |
extern int __flsbuf(int /*c*/, FILE * /*stream*/);
|
|
|
485 |
/*
|
|
|
486 |
* SYSTEM USE ONLY, called by putc to flush buffer and or sort out flags.
|
|
|
487 |
* Returns: character put into buffer or EOF on error.
|
|
|
488 |
*/
|
|
|
489 |
#define putc(ch, p) \
|
|
|
490 |
(--((p)->__ocnt) >= 0 ? (*((p)->__ptr)++ = (ch)) : __flsbuf(ch,p))
|
|
|
491 |
extern int (putc)(int /*c*/, FILE * /*stream*/);
|
|
|
492 |
/*
|
|
|
493 |
* is equivalent to fputc except that it may be (and is under
|
|
|
494 |
* RISCOS/Arthur/Brazil) implemented as a macro. stream may be evaluated
|
|
|
495 |
* more than once, so the argument should never be an expression with side
|
|
|
496 |
* effects.
|
|
|
497 |
* Returns: the character written. If a write error occurs, the error
|
|
|
498 |
* indicator is set and putc returns EOF.
|
|
|
499 |
*/
|
|
|
500 |
#define putchar(ch) putc(ch, stdout)
|
|
|
501 |
extern int (putchar)(int /*c*/);
|
|
|
502 |
/*
|
|
|
503 |
* is equivalent to putc with the second argument stdout.
|
|
|
504 |
* Returns: the character written. If a write error occurs, the error
|
|
|
505 |
* indicator is set and putc returns EOF.
|
|
|
506 |
*/
|
|
|
507 |
extern int puts(const char * /*s*/);
|
|
|
508 |
/*
|
|
|
509 |
* writes the string pointed to by s to the stream pointed to by stdout, and
|
|
|
510 |
* appends a new-line character to the output. The terminating null
|
|
|
511 |
* character is not written.
|
|
|
512 |
* Returns: EOF if a write error occurs; otherwise it returns a nonnegative
|
|
|
513 |
* value.
|
|
|
514 |
*/
|
|
|
515 |
extern int ungetc(int /*c*/, FILE * /*stream*/);
|
|
|
516 |
/*
|
|
|
517 |
* pushes the character specified by c (converted to an unsigned char) back
|
|
|
518 |
* onto the input stream pointed to by stream. The character will be
|
|
|
519 |
* returned by the next read on that stream. An intervening call to the
|
|
|
520 |
* fflush function or to a file positioning function (fseek, fsetpos,
|
|
|
521 |
* rewind) discards any pushed-back characters. The external storage
|
|
|
522 |
* corresponding to the stream is unchanged.
|
|
|
523 |
* One character pushback is guaranteed. If the unget function is called too
|
|
|
524 |
* many times on the same stream without an intervening read or file
|
|
|
525 |
* positioning operation on that stream, the operation may fail.
|
|
|
526 |
* If the value of c equals that of the macro EOF, the operation fails and
|
|
|
527 |
* the input stream is unchanged.
|
|
|
528 |
* A successful call to the ungetc function clears the end-of-file
|
|
|
529 |
* indicator. The value of the file position indicator after reading or
|
|
|
530 |
* discarding all pushed-back characters shall be the same as it was before
|
|
|
531 |
* the characters were pushed back. For a text stream, the value of the file
|
|
|
532 |
* position indicator after a successful call to the ungetc function is
|
|
|
533 |
* unspecified until all pushed-back characters are read or discarded. For a
|
|
|
534 |
* binary stream, the file position indicator is decremented by each
|
|
|
535 |
* successful call to the ungetc function; if its value was zero before a
|
|
|
536 |
* call, it is indeterminate after the call.
|
|
|
537 |
* Returns: the character pushed back after conversion, or EOF if the
|
|
|
538 |
* operation fails.
|
|
|
539 |
*/
|
|
|
540 |
|
|
|
541 |
extern size_t fread(void * /*ptr*/,
|
|
|
542 |
size_t /*size*/, size_t /*nmemb*/, FILE * /*stream*/);
|
|
|
543 |
/*
|
|
|
544 |
* reads into the array pointed to by ptr, up to nmemb members whose size is
|
|
|
545 |
* specified by size, from the stream pointed to by stream. The file
|
|
|
546 |
* position indicator (if defined) is advanced by the number of characters
|
|
|
547 |
* successfully read. If an error occurs, the resulting value of the file
|
|
|
548 |
* position indicator is indeterminate. If a partial member is read, its
|
|
|
549 |
* value is indeterminate. The ferror or feof function shall be used to
|
|
|
550 |
* distinguish between a read error and end-of-file.
|
|
|
551 |
* Returns: the number of members successfully read, which may be less than
|
|
|
552 |
* nmemb if a read error or end-of-file is encountered. If size or
|
|
|
553 |
* nmemb is zero, fread returns zero and the contents of the array
|
|
|
554 |
* and the state of the stream remain unchanged.
|
|
|
555 |
*/
|
|
|
556 |
extern size_t fwrite(const void * /*ptr*/,
|
|
|
557 |
size_t /*size*/, size_t /*nmemb*/, FILE * /*stream*/);
|
|
|
558 |
/*
|
|
|
559 |
* writes, from the array pointed to by ptr up to nmemb members whose size
|
|
|
560 |
* is specified by size, to the stream pointed to by stream. The file
|
|
|
561 |
* position indicator (if defined) is advanced by the number of characters
|
|
|
562 |
* successfully written. If an error occurs, the resulting value of the file
|
|
|
563 |
* position indicator is indeterminate.
|
|
|
564 |
* Returns: the number of members successfully written, which will be less
|
|
|
565 |
* than nmemb only if a write error is encountered.
|
|
|
566 |
*/
|
|
|
567 |
|
|
|
568 |
extern int fgetpos(FILE * /*stream*/, fpos_t * /*pos*/);
|
|
|
569 |
/*
|
|
|
570 |
* stores the current value of the file position indicator for the stream
|
|
|
571 |
* pointed to by stream in the object pointed to by pos. The value stored
|
|
|
572 |
* contains unspecified information usable by the fsetpos function for
|
|
|
573 |
* repositioning the stream to its position at the time of the call to the
|
|
|
574 |
* fgetpos function.
|
|
|
575 |
* Returns: zero, if successful. Otherwise nonzero is returned and the
|
|
|
576 |
* integer expression errno is set to an implementation-defined
|
|
|
577 |
* nonzero value (under RISCOS/Arthur/Brazil fgetpos cannot fail).
|
|
|
578 |
*/
|
|
|
579 |
extern int fseek(FILE * /*stream*/, long int /*offset*/, int /*whence*/);
|
|
|
580 |
/*
|
|
|
581 |
* sets the file position indicator for the stream pointed to by stream.
|
|
|
582 |
* For a binary stream, the new position is at the signed number of
|
|
|
583 |
* characters specified by offset away from the point specified by whence.
|
|
|
584 |
* The specified point is the beginning of the file for SEEK_SET, the
|
|
|
585 |
* current position in the file for SEEK_CUR, or end-of-file for SEEK_END.
|
|
|
586 |
* A binary stream need not meaningfully support fseek calls with a whence
|
|
|
587 |
* value of SEEK_END.
|
|
|
588 |
* For a text stream, either offset shall be zero, or offset shall be a
|
|
|
589 |
* value returned by an earlier call to the ftell function on the same
|
|
|
590 |
* stream and whence shall be SEEK_SET.
|
|
|
591 |
* The fseek function clears the end-of-file indicator and undoes any
|
|
|
592 |
* effects of the ungetc function on the same stream. After an fseek call,
|
|
|
593 |
* the next operation on an update stream may be either input or output.
|
|
|
594 |
* Returns: nonzero only for a request that cannot be satisfied.
|
|
|
595 |
*/
|
|
|
596 |
extern int fsetpos(FILE * /*stream*/, const fpos_t * /*pos*/);
|
|
|
597 |
/*
|
|
|
598 |
* sets the file position indicator for the stream pointed to by stream
|
|
|
599 |
* according to the value of the object pointed to by pos, which shall be a
|
|
|
600 |
* value returned by an earlier call to the fgetpos function on the same
|
|
|
601 |
* stream.
|
|
|
602 |
* The fsetpos function clears the end-of-file indicator and undoes any
|
|
|
603 |
* effects of the ungetc function on the same stream. After an fsetpos call,
|
|
|
604 |
* the next operation on an update stream may be either input or output.
|
|
|
605 |
* Returns: zero, if successful. Otherwise nonzero is returned and the
|
|
|
606 |
* integer expression errno is set to an implementation-defined
|
|
|
607 |
* nonzero value (under RISCOS/Arthur/Brazil the value that of EDOM
|
|
|
608 |
* in math.h).
|
|
|
609 |
*/
|
|
|
610 |
extern long int ftell(FILE * /*stream*/);
|
|
|
611 |
/*
|
|
|
612 |
* obtains the current value of the file position indicator for the stream
|
|
|
613 |
* pointed to by stream. For a binary stream, the value is the number of
|
|
|
614 |
* characters from the beginning of the file. For a text stream, the file
|
|
|
615 |
* position indicator contains unspecified information, usable by the fseek
|
|
|
616 |
* function for returning the file position indicator to its position at the
|
|
|
617 |
* time of the ftell call; the difference between two such return values is
|
|
|
618 |
* not necessarily a meaningful measure of the number of characters written
|
|
|
619 |
* or read.
|
|
|
620 |
* Returns: if successful, the current value of the file position indicator.
|
|
|
621 |
* On failure, the ftell function returns -1L and sets the integer
|
|
|
622 |
* expression errno to an implementation-defined nonzero value
|
|
|
623 |
* (under RISCOS/Arthur/Brazil ftell cannot fail).
|
|
|
624 |
*/
|
|
|
625 |
extern void rewind(FILE * /*stream*/);
|
|
|
626 |
/*
|
|
|
627 |
* sets the file position indicator for the stream pointed to by stream to
|
|
|
628 |
* the beginning of the file. It is equivalent to
|
|
|
629 |
* (void)fseek(stream, 0L, SEEK_SET)
|
|
|
630 |
* except that the error indicator for the stream is also cleared.
|
|
|
631 |
* Returns: no value.
|
|
|
632 |
*/
|
|
|
633 |
|
|
|
634 |
extern void clearerr(FILE * /*stream*/);
|
|
|
635 |
/*
|
|
|
636 |
* clears the end-of-file and error indicators for the stream pointed to by
|
|
|
637 |
* stream. These indicators are cleared only when the file is opened or by
|
|
|
638 |
* an explicit call to the clearerr function or to the rewind function.
|
|
|
639 |
* Returns: no value.
|
|
|
640 |
*/
|
|
|
641 |
|
|
|
642 |
#define feof(stream) ((stream)->__flag & _IOEOF)
|
|
|
643 |
extern int (feof)(FILE * /*stream*/);
|
|
|
644 |
/*
|
|
|
645 |
* tests the end-of-file indicator for the stream pointed to by stream.
|
|
|
646 |
* Returns: nonzero iff the end-of-file indicator is set for stream.
|
|
|
647 |
*/
|
|
|
648 |
#define ferror(stream) ((stream)->__flag & _IOERR)
|
|
|
649 |
extern int (ferror)(FILE * /*stream*/);
|
|
|
650 |
/*
|
|
|
651 |
* tests the error indicator for the stream pointed to by stream.
|
|
|
652 |
* Returns: nonzero iff the error indicator is set for stream.
|
|
|
653 |
*/
|
|
|
654 |
extern void perror(const char * /*s*/);
|
|
|
655 |
/*
|
|
|
656 |
* maps the error number in the integer expression errno to an error
|
|
|
657 |
* message. It writes a sequence of characters to the standard error stream
|
|
|
658 |
* thus: first (if s is not a null pointer and the character pointed to by
|
|
|
659 |
* s is not the null character), the string pointed to by s followed by a
|
|
|
660 |
* colon and a space; then an appropriate error message string followed by
|
|
|
661 |
* a new-line character. The contents of the error message strings are the
|
|
|
662 |
* same as those returned by the strerror function with argument errno,
|
|
|
663 |
* which are implementation-defined.
|
|
|
664 |
* Returns: no value.
|
|
|
665 |
*/
|
|
|
666 |
|
|
|
667 |
#endif
|
|
|
668 |
|
|
|
669 |
/* end of stdio.h */
|