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.
17
* @(#)stdio.h 5.3 (Berkeley) 3/15/86
21
* NB: to fit things in six character monocase externals, the
22
* stdio code uses the prefix `__s' for stdio objects, typically
23
* followed by a three-character attempt at a mnemonic.
31
#define _FSTDIO /* ``function stdio'' */
36
#define __need___va_list
40
* <sys/reent.h> defines __FILE, _fpos_t.
41
* They must be defined there because struct _reent needs them (and we don't
42
* want reent.h to include this file.
45
#include <sys/reent.h>
46
#include <sys/types.h>
53
typedef _fpos64_t fpos_t;
55
typedef _fpos_t fpos_t;
56
#ifdef __LARGE64_FILES
57
typedef _fpos64_t fpos64_t;
59
#endif /* !__CYGWIN__ */
61
#include <sys/stdio.h>
63
#define __SLBF 0x0001 /* line buffered */
64
#define __SNBF 0x0002 /* unbuffered */
65
#define __SRD 0x0004 /* OK to read */
66
#define __SWR 0x0008 /* OK to write */
67
/* RD and WR are never simultaneously asserted */
68
#define __SRW 0x0010 /* open for reading & writing */
69
#define __SEOF 0x0020 /* found EOF */
70
#define __SERR 0x0040 /* found error */
71
#define __SMBF 0x0080 /* _buf is from malloc */
72
#define __SAPP 0x0100 /* fdopen()ed in append mode - so must write to end */
73
#define __SSTR 0x0200 /* this is an sprintf/snprintf string */
74
#define __SOPT 0x0400 /* do fseek() optimisation */
75
#define __SNPT 0x0800 /* do not do fseek() optimisation */
76
#define __SOFF 0x1000 /* set iff _offset is in fact correct */
77
#define __SORD 0x2000 /* true => stream orientation (byte/wide) decided */
78
#if defined(__CYGWIN__)
79
# define __SCLE 0x4000 /* convert line endings CR/LF <-> NL */
81
#define __SL64 0x8000 /* is 64-bit offset large file */
84
#define __SWID 0x2000 /* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */
87
* The following three definitions are for ANSI C, which took them
88
* from System V, which stupidly took internal interface macros and
89
* made them official arguments to setvbuf(), without renaming them.
90
* Hence, these ugly _IOxxx names are *supposed* to appear in user code.
92
* Although these happen to match their counterparts above, the
93
* implementation does not rely on that (so these could be renumbered).
95
#define _IOFBF 0 /* setvbuf should set fully buffered */
96
#define _IOLBF 1 /* setvbuf should set line buffered */
97
#define _IONBF 2 /* setvbuf should set unbuffered */
106
#define BUFSIZ __BUFSIZ__
112
#define FOPEN_MAX __FOPEN_MAX__
117
#ifdef __FILENAME_MAX__
118
#define FILENAME_MAX __FILENAME_MAX__
120
#define FILENAME_MAX 1024
124
#define L_tmpnam __L_tmpnam__
126
#define L_tmpnam FILENAME_MAX
129
#ifndef __STRICT_ANSI__
130
#define P_tmpdir "/tmp"
134
#define SEEK_SET 0 /* set file offset to offset */
137
#define SEEK_CUR 1 /* set file offset to current plus offset */
140
#define SEEK_END 2 /* set file offset to EOF plus offset */
145
#if 0 /* XXX Emscripten: do not use impure stuff for std*, it makes comparing to native builds harder */
147
#define stdin (_REENT->_stdin)
148
#define stdout (_REENT->_stdout)
149
#define stderr (_REENT->_stderr)
150
#else /* _REENT_ONLY */
151
#define stdin (_impure_ptr->_stdin)
152
#define stdout (_impure_ptr->_stdout)
153
#define stderr (_impure_ptr->_stderr)
154
#endif /* _REENT_ONLY */
160
#define stdout stdout
161
#define stderr stderr
164
#define _stdin_r(x) ((x)->_stdin)
165
#define _stdout_r(x) ((x)->_stdout)
166
#define _stderr_r(x) ((x)->_stderr)
169
* Functions defined in ANSI C standard.
174
#define __VALIST __gnuc_va_list
176
#define __VALIST char*
180
FILE * _EXFUN(tmpfile, (void));
181
char * _EXFUN(tmpnam, (char *));
182
int _EXFUN(fclose, (FILE *));
183
int _EXFUN(fflush, (FILE *));
184
FILE * _EXFUN(freopen, (const char *, const char *, FILE *));
185
void _EXFUN(setbuf, (FILE *, char *));
186
int _EXFUN(setvbuf, (FILE *, char *, int, size_t));
187
int _EXFUN(fprintf, (FILE *, const char *, ...)
188
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
189
int _EXFUN(fscanf, (FILE *, const char *, ...)
190
_ATTRIBUTE (__format__ (__scanf__, 2, 3)));
191
int _EXFUN(printf, (const char *, ...)
192
_ATTRIBUTE (__format__ (__printf__, 1, 2)));
193
int _EXFUN(scanf, (const char *, ...)
194
_ATTRIBUTE (__format__ (__scanf__, 1, 2)));
195
int _EXFUN(sscanf, (const char *, const char *, ...)
196
_ATTRIBUTE (__format__ (__scanf__, 2, 3)));
197
int _EXFUN(vfprintf, (FILE *, const char *, __VALIST)
198
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
199
int _EXFUN(vprintf, (const char *, __VALIST)
200
_ATTRIBUTE (__format__ (__printf__, 1, 0)));
201
int _EXFUN(vsprintf, (char *, const char *, __VALIST)
202
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
203
int _EXFUN(fgetc, (FILE *));
204
char * _EXFUN(fgets, (char *, int, FILE *));
205
int _EXFUN(fputc, (int, FILE *));
206
int _EXFUN(fputs, (const char *, FILE *));
207
int _EXFUN(getc, (FILE *));
208
int _EXFUN(getchar, (void));
209
char * _EXFUN(gets, (char *));
210
int _EXFUN(putc, (int, FILE *));
211
int _EXFUN(putchar, (int));
212
int _EXFUN(puts, (const char *));
213
int _EXFUN(ungetc, (int, FILE *));
214
size_t _EXFUN(fread, (_PTR, size_t _size, size_t _n, FILE *));
215
size_t _EXFUN(fwrite, (const _PTR , size_t _size, size_t _n, FILE *));
216
#ifdef _COMPILING_NEWLIB
217
int _EXFUN(fgetpos, (FILE *, _fpos_t *));
219
int _EXFUN(fgetpos, (FILE *, fpos_t *));
221
int _EXFUN(fseek, (FILE *, long, int));
222
#ifdef _COMPILING_NEWLIB
223
int _EXFUN(fsetpos, (FILE *, const _fpos_t *));
225
int _EXFUN(fsetpos, (FILE *, const fpos_t *));
227
long _EXFUN(ftell, ( FILE *));
228
void _EXFUN(rewind, (FILE *));
229
void _EXFUN(clearerr, (FILE *));
230
int _EXFUN(feof, (FILE *));
231
int _EXFUN(ferror, (FILE *));
232
void _EXFUN(perror, (const char *));
234
FILE * _EXFUN(fopen, (const char *_name, const char *_type));
235
int _EXFUN(sprintf, (char *, const char *, ...)
236
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
237
int _EXFUN(remove, (const char *));
238
int _EXFUN(rename, (const char *, const char *));
240
#if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K)
241
#ifdef _COMPILING_NEWLIB
242
int _EXFUN(fseeko, (FILE *, _off_t, int));
243
_off_t _EXFUN(ftello, ( FILE *));
245
int _EXFUN(fseeko, (FILE *, off_t, int));
246
off_t _EXFUN(ftello, ( FILE *));
249
#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
251
int _EXFUN(asiprintf, (char **, const char *, ...)
252
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
253
char * _EXFUN(asniprintf, (char *, size_t *, const char *, ...)
254
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
255
char * _EXFUN(asnprintf, (char *, size_t *, const char *, ...)
256
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
257
int _EXFUN(asprintf, (char **, const char *, ...)
258
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
260
int _EXFUN(diprintf, (int, const char *, ...)
261
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
263
int _EXFUN(fcloseall, (_VOID));
264
int _EXFUN(fiprintf, (FILE *, const char *, ...)
265
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
266
int _EXFUN(fiscanf, (FILE *, const char *, ...)
267
_ATTRIBUTE (__format__ (__scanf__, 2, 3)));
268
int _EXFUN(iprintf, (const char *, ...)
269
_ATTRIBUTE (__format__ (__printf__, 1, 2)));
270
int _EXFUN(iscanf, (const char *, ...)
271
_ATTRIBUTE (__format__ (__scanf__, 1, 2)));
272
int _EXFUN(siprintf, (char *, const char *, ...)
273
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
274
int _EXFUN(siscanf, (const char *, const char *, ...)
275
_ATTRIBUTE (__format__ (__scanf__, 2, 3)));
276
int _EXFUN(snprintf, (char *, size_t, const char *, ...)
277
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
278
int _EXFUN(sniprintf, (char *, size_t, const char *, ...)
279
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
280
char * _EXFUN(tempnam, (const char *, const char *));
281
int _EXFUN(vasiprintf, (char **, const char *, __VALIST)
282
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
283
char * _EXFUN(vasniprintf, (char *, size_t *, const char *, __VALIST)
284
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
285
char * _EXFUN(vasnprintf, (char *, size_t *, const char *, __VALIST)
286
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
287
int _EXFUN(vasprintf, (char **, const char *, __VALIST)
288
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
289
int _EXFUN(vdiprintf, (int, const char *, __VALIST)
290
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
291
int _EXFUN(vfiprintf, (FILE *, const char *, __VALIST)
292
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
293
int _EXFUN(vfiscanf, (FILE *, const char *, __VALIST)
294
_ATTRIBUTE (__format__ (__scanf__, 2, 0)));
295
int _EXFUN(vfscanf, (FILE *, const char *, __VALIST)
296
_ATTRIBUTE (__format__ (__scanf__, 2, 0)));
297
int _EXFUN(viprintf, (const char *, __VALIST)
298
_ATTRIBUTE (__format__ (__printf__, 1, 0)));
299
int _EXFUN(viscanf, (const char *, __VALIST)
300
_ATTRIBUTE (__format__ (__scanf__, 1, 0)));
301
int _EXFUN(vscanf, (const char *, __VALIST)
302
_ATTRIBUTE (__format__ (__scanf__, 1, 0)));
303
int _EXFUN(vsiprintf, (char *, const char *, __VALIST)
304
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
305
int _EXFUN(vsiscanf, (const char *, const char *, __VALIST)
306
_ATTRIBUTE (__format__ (__scanf__, 2, 0)));
307
int _EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST)
308
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
309
int _EXFUN(vsnprintf, (char *, size_t, const char *, __VALIST)
310
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
311
int _EXFUN(vsscanf, (const char *, const char *, __VALIST)
312
_ATTRIBUTE (__format__ (__scanf__, 2, 0)));
313
#endif /* !_REENT_ONLY */
314
#endif /* !__STRICT_ANSI__ */
317
* Routines in POSIX 1003.1:2001.
320
#ifndef __STRICT_ANSI__
322
FILE * _EXFUN(fdopen, (int, const char *));
324
int _EXFUN(fileno, (FILE *));
325
int _EXFUN(getw, (FILE *));
326
int _EXFUN(pclose, (FILE *));
327
FILE * _EXFUN(popen, (const char *, const char *));
328
int _EXFUN(putw, (int, FILE *));
329
void _EXFUN(setbuffer, (FILE *, char *, int));
330
int _EXFUN(setlinebuf, (FILE *));
331
int _EXFUN(getc_unlocked, (FILE *));
332
int _EXFUN(getchar_unlocked, (void));
333
void _EXFUN(flockfile, (FILE *));
334
int _EXFUN(ftrylockfile, (FILE *));
335
void _EXFUN(funlockfile, (FILE *));
336
int _EXFUN(putc_unlocked, (int, FILE *));
337
int _EXFUN(putchar_unlocked, (int));
338
#endif /* ! __STRICT_ANSI__ */
341
* Routines in POSIX 1003.1:200x.
344
#ifndef __STRICT_ANSI__
347
int _EXFUN(dprintf, (int, const char *, ...)
348
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
350
FILE * _EXFUN(fmemopen, (void *, size_t, const char *));
351
/* getdelim - see __getdelim for now */
352
/* getline - see __getline for now */
353
FILE * _EXFUN(open_memstream, (char **, size_t *));
354
#if defined (__CYGWIN__)
355
int _EXFUN(renameat, (int, const char *, int, const char *));
357
int _EXFUN(vdprintf, (int, const char *, __VALIST)
358
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
363
* Recursive versions of the above.
366
int _EXFUN(_asiprintf_r, (struct _reent *, char **, const char *, ...)
367
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
368
char * _EXFUN(_asniprintf_r, (struct _reent *, char *, size_t *, const char *, ...)
369
_ATTRIBUTE (__format__ (__printf__, 4, 5)));
370
char * _EXFUN(_asnprintf_r, (struct _reent *, char *, size_t *, const char *, ...)
371
_ATTRIBUTE (__format__ (__printf__, 4, 5)));
372
int _EXFUN(_asprintf_r, (struct _reent *, char **, const char *, ...)
373
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
374
int _EXFUN(_diprintf_r, (struct _reent *, int, const char *, ...)
375
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
376
int _EXFUN(_dprintf_r, (struct _reent *, int, const char *, ...)
377
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
378
int _EXFUN(_fclose_r, (struct _reent *, FILE *));
379
int _EXFUN(_fcloseall_r, (struct _reent *));
380
FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
381
int _EXFUN(_fflush_r, (struct _reent *, FILE *));
382
int _EXFUN(_fgetc_r, (struct _reent *, FILE *));
383
char * _EXFUN(_fgets_r, (struct _reent *, char *, int, FILE *));
384
#ifdef _COMPILING_NEWLIB
385
int _EXFUN(_fgetpos_r, (struct _reent *, FILE *, _fpos_t *));
386
int _EXFUN(_fsetpos_r, (struct _reent *, FILE *, const _fpos_t *));
388
int _EXFUN(_fgetpos_r, (struct _reent *, FILE *, fpos_t *));
389
int _EXFUN(_fsetpos_r, (struct _reent *, FILE *, const fpos_t *));
391
int _EXFUN(_fiprintf_r, (struct _reent *, FILE *, const char *, ...)
392
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
393
int _EXFUN(_fiscanf_r, (struct _reent *, FILE *, const char *, ...)
394
_ATTRIBUTE (__format__ (__scanf__, 3, 4)));
395
FILE * _EXFUN(_fmemopen_r, (struct _reent *, void *, size_t, const char *));
396
FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
397
FILE * _EXFUN(_freopen_r, (struct _reent *, const char *, const char *, FILE *));
398
int _EXFUN(_fprintf_r, (struct _reent *, FILE *, const char *, ...)
399
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
400
int _EXFUN(_fpurge_r, (struct _reent *, FILE *));
401
int _EXFUN(_fputc_r, (struct _reent *, int, FILE *));
402
int _EXFUN(_fputs_r, (struct _reent *, const char *, FILE *));
403
size_t _EXFUN(_fread_r, (struct _reent *, _PTR, size_t _size, size_t _n, FILE *));
404
int _EXFUN(_fscanf_r, (struct _reent *, FILE *, const char *, ...)
405
_ATTRIBUTE (__format__ (__scanf__, 3, 4)));
406
int _EXFUN(_fseek_r, (struct _reent *, FILE *, long, int));
407
int _EXFUN(_fseeko_r,(struct _reent *, FILE *, _off_t, int));
408
long _EXFUN(_ftell_r, (struct _reent *, FILE *));
409
_off_t _EXFUN(_ftello_r,(struct _reent *, FILE *));
410
void _EXFUN(_rewind_r, (struct _reent *, FILE *));
411
size_t _EXFUN(_fwrite_r, (struct _reent *, const _PTR , size_t _size, size_t _n, FILE *));
412
int _EXFUN(_getc_r, (struct _reent *, FILE *));
413
int _EXFUN(_getc_unlocked_r, (struct _reent *, FILE *));
414
int _EXFUN(_getchar_r, (struct _reent *));
415
int _EXFUN(_getchar_unlocked_r, (struct _reent *));
416
char * _EXFUN(_gets_r, (struct _reent *, char *));
417
int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...)
418
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
419
int _EXFUN(_iscanf_r, (struct _reent *, const char *, ...)
420
_ATTRIBUTE (__format__ (__scanf__, 2, 3)));
421
FILE * _EXFUN(_open_memstream_r, (struct _reent *, char **, size_t *));
422
void _EXFUN(_perror_r, (struct _reent *, const char *));
423
int _EXFUN(_printf_r, (struct _reent *, const char *, ...)
424
_ATTRIBUTE (__format__ (__printf__, 2, 3)));
425
int _EXFUN(_putc_r, (struct _reent *, int, FILE *));
426
int _EXFUN(_putc_unlocked_r, (struct _reent *, int, FILE *));
427
int _EXFUN(_putchar_unlocked_r, (struct _reent *, int));
428
int _EXFUN(_putchar_r, (struct _reent *, int));
429
int _EXFUN(_puts_r, (struct _reent *, const char *));
430
int _EXFUN(_remove_r, (struct _reent *, const char *));
431
int _EXFUN(_rename_r, (struct _reent *,
432
const char *_old, const char *_new));
433
int _EXFUN(_scanf_r, (struct _reent *, const char *, ...)
434
_ATTRIBUTE (__format__ (__scanf__, 2, 3)));
435
int _EXFUN(_siprintf_r, (struct _reent *, char *, const char *, ...)
436
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
437
int _EXFUN(_siscanf_r, (struct _reent *, const char *, const char *, ...)
438
_ATTRIBUTE (__format__ (__scanf__, 3, 4)));
439
int _EXFUN(_sniprintf_r, (struct _reent *, char *, size_t, const char *, ...)
440
_ATTRIBUTE (__format__ (__printf__, 4, 5)));
441
int _EXFUN(_snprintf_r, (struct _reent *, char *, size_t, const char *, ...)
442
_ATTRIBUTE (__format__ (__printf__, 4, 5)));
443
int _EXFUN(_sprintf_r, (struct _reent *, char *, const char *, ...)
444
_ATTRIBUTE (__format__ (__printf__, 3, 4)));
445
int _EXFUN(_sscanf_r, (struct _reent *, const char *, const char *, ...)
446
_ATTRIBUTE (__format__ (__scanf__, 3, 4)));
447
char * _EXFUN(_tempnam_r, (struct _reent *, const char *, const char *));
448
FILE * _EXFUN(_tmpfile_r, (struct _reent *));
449
char * _EXFUN(_tmpnam_r, (struct _reent *, char *));
450
int _EXFUN(_ungetc_r, (struct _reent *, int, FILE *));
451
int _EXFUN(_vasiprintf_r, (struct _reent *, char **, const char *, __VALIST)
452
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
453
char * _EXFUN(_vasniprintf_r, (struct _reent*, char *, size_t *, const char *, __VALIST)
454
_ATTRIBUTE (__format__ (__printf__, 4, 0)));
455
char * _EXFUN(_vasnprintf_r, (struct _reent*, char *, size_t *, const char *, __VALIST)
456
_ATTRIBUTE (__format__ (__printf__, 4, 0)));
457
int _EXFUN(_vasprintf_r, (struct _reent *, char **, const char *, __VALIST)
458
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
459
int _EXFUN(_vdiprintf_r, (struct _reent *, int, const char *, __VALIST)
460
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
461
int _EXFUN(_vdprintf_r, (struct _reent *, int, const char *, __VALIST)
462
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
463
int _EXFUN(_vfiprintf_r, (struct _reent *, FILE *, const char *, __VALIST)
464
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
465
int _EXFUN(_vfiscanf_r, (struct _reent *, FILE *, const char *, __VALIST)
466
_ATTRIBUTE (__format__ (__scanf__, 3, 0)));
467
int _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST)
468
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
469
int _EXFUN(_vfscanf_r, (struct _reent *, FILE *, const char *, __VALIST)
470
_ATTRIBUTE (__format__ (__scanf__, 3, 0)));
471
int _EXFUN(_viprintf_r, (struct _reent *, const char *, __VALIST)
472
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
473
int _EXFUN(_viscanf_r, (struct _reent *, const char *, __VALIST)
474
_ATTRIBUTE (__format__ (__scanf__, 2, 0)));
475
int _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST)
476
_ATTRIBUTE (__format__ (__printf__, 2, 0)));
477
int _EXFUN(_vscanf_r, (struct _reent *, const char *, __VALIST)
478
_ATTRIBUTE (__format__ (__scanf__, 2, 0)));
479
int _EXFUN(_vsiprintf_r, (struct _reent *, char *, const char *, __VALIST)
480
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
481
int _EXFUN(_vsiscanf_r, (struct _reent *, const char *, const char *, __VALIST)
482
_ATTRIBUTE (__format__ (__scanf__, 3, 0)));
483
int _EXFUN(_vsniprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST)
484
_ATTRIBUTE (__format__ (__printf__, 4, 0)));
485
int _EXFUN(_vsnprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST)
486
_ATTRIBUTE (__format__ (__printf__, 4, 0)));
487
int _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST)
488
_ATTRIBUTE (__format__ (__printf__, 3, 0)));
489
int _EXFUN(_vsscanf_r, (struct _reent *, const char *, const char *, __VALIST)
490
_ATTRIBUTE (__format__ (__scanf__, 3, 0)));
492
/* Other extensions. */
494
int _EXFUN(fpurge, (FILE *));
495
ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *));
496
ssize_t _EXFUN(__getline, (char **, size_t *, FILE *));
498
#ifdef __LARGE64_FILES
499
#if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB)
500
FILE * _EXFUN(fdopen64, (int, const char *));
501
FILE * _EXFUN(fopen64, (const char *, const char *));
502
FILE * _EXFUN(freopen64, (_CONST char *, _CONST char *, FILE *));
503
_off64_t _EXFUN(ftello64, (FILE *));
504
_off64_t _EXFUN(fseeko64, (FILE *, _off64_t, int));
505
int _EXFUN(fgetpos64, (FILE *, _fpos64_t *));
506
int _EXFUN(fsetpos64, (FILE *, const _fpos64_t *));
507
FILE * _EXFUN(tmpfile64, (void));
509
FILE * _EXFUN(_fdopen64_r, (struct _reent *, int, const char *));
510
FILE * _EXFUN(_fopen64_r, (struct _reent *,const char *, const char *));
511
FILE * _EXFUN(_freopen64_r, (struct _reent *, _CONST char *, _CONST char *, FILE *));
512
_off64_t _EXFUN(_ftello64_r, (struct _reent *, FILE *));
513
_off64_t _EXFUN(_fseeko64_r, (struct _reent *, FILE *, _off64_t, int));
514
int _EXFUN(_fgetpos64_r, (struct _reent *, FILE *, _fpos64_t *));
515
int _EXFUN(_fsetpos64_r, (struct _reent *, FILE *, const _fpos64_t *));
516
FILE * _EXFUN(_tmpfile64_r, (struct _reent *));
517
#endif /* !__CYGWIN__ */
518
#endif /* __LARGE64_FILES */
521
* Routines internal to the implementation.
524
int _EXFUN(__srget_r, (struct _reent *, FILE *));
525
int _EXFUN(__swbuf_r, (struct _reent *, int, FILE *));
528
* Stdio function-access interface.
531
#ifndef __STRICT_ANSI__
532
# ifdef __LARGE64_FILES
533
FILE *_EXFUN(funopen,(const _PTR __cookie,
534
int (*__readfn)(_PTR __c, char *__buf, int __n),
535
int (*__writefn)(_PTR __c, const char *__buf, int __n),
536
_fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence),
537
int (*__closefn)(_PTR __c)));
538
FILE *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie,
539
int (*__readfn)(_PTR __c, char *__buf, int __n),
540
int (*__writefn)(_PTR __c, const char *__buf, int __n),
541
_fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence),
542
int (*__closefn)(_PTR __c)));
544
FILE *_EXFUN(funopen,(const _PTR __cookie,
545
int (*__readfn)(_PTR __cookie, char *__buf, int __n),
546
int (*__writefn)(_PTR __cookie, const char *__buf, int __n),
547
fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence),
548
int (*__closefn)(_PTR __cookie)));
549
FILE *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie,
550
int (*__readfn)(_PTR __cookie, char *__buf, int __n),
551
int (*__writefn)(_PTR __cookie, const char *__buf, int __n),
552
fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence),
553
int (*__closefn)(_PTR __cookie)));
554
# endif /* !__LARGE64_FILES */
556
# define fropen(__cookie, __fn) funopen(__cookie, __fn, (int (*)())0, \
557
(fpos_t (*)())0, (int (*)())0)
558
# define fwopen(__cookie, __fn) funopen(__cookie, (int (*)())0, __fn, \
559
(fpos_t (*)())0, (int (*)())0)
561
typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
562
typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
564
# ifdef __LARGE64_FILES
565
typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,
568
typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);
569
# endif /* !__LARGE64_FILES */
570
typedef int cookie_close_function_t(void *__cookie);
573
/* These four struct member names are dictated by Linux; hopefully,
574
they don't conflict with any macros. */
575
cookie_read_function_t *read;
576
cookie_write_function_t *write;
577
cookie_seek_function_t *seek;
578
cookie_close_function_t *close;
579
} cookie_io_functions_t;
580
FILE *_EXFUN(fopencookie,(void *__cookie,
581
const char *__mode, cookie_io_functions_t __functions));
582
FILE *_EXFUN(_fopencookie_r,(struct _reent *, void *__cookie,
583
const char *__mode, cookie_io_functions_t __functions));
584
#endif /* ! __STRICT_ANSI__ */
586
#ifndef __CUSTOM_FILE_IO__
588
* The __sfoo macros are here so that we can
589
* define function versions in the C library.
591
#define __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++))
594
/* For a platform with CR/LF, additional logic is required by
595
__sgetc_r which would otherwise simply be a macro; therefore we
596
use an inlined function. The function is only meant to be inlined
597
in place as used and the function body should never be emitted.
599
There are two possible means to this end when compiling with GCC,
600
one when compiling with a standard C99 compiler, and for other
601
compilers we're just stuck. At the moment, this issue only
602
affects the Cygwin target, so we'll most likely be using GCC. */
604
_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p);
606
_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p)
608
int __c = __sgetc_raw_r(__ptr, __p);
609
if ((__p->_flags & __SCLE) && (__c == '\r'))
611
int __c2 = __sgetc_raw_r(__ptr, __p);
620
#define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
623
#ifdef _never /* __GNUC__ */
624
/* If this inline is actually used, then systems using coff debugging
625
info get hopelessly confused. 21sept93 rich@cygnus.com. */
626
_ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
627
if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
628
return (*_p->_p++ = _c);
630
return (__swbuf_r(_ptr, _c, _p));
634
* This has been tuned to generate reasonable code on the vax using pcc
636
#define __sputc_raw_r(__ptr, __c, __p) \
638
(__p)->_w >= (__p)->_lbfsize ? \
639
(*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \
640
(int)*(__p)->_p++ : \
641
__swbuf_r(__ptr, '\n', __p) : \
642
__swbuf_r(__ptr, (int)(__c), __p) : \
643
(*(__p)->_p = (__c), (int)*(__p)->_p++))
645
#define __sputc_r(__ptr, __c, __p) \
646
((((__p)->_flags & __SCLE) && ((__c) == '\n')) \
647
? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \
648
__sputc_raw_r((__ptr), (__c), (__p)))
650
#define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p)
654
#define __sfeof(p) (((p)->_flags & __SEOF) != 0)
655
#define __sferror(p) (((p)->_flags & __SERR) != 0)
656
#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
657
#define __sfileno(p) ((p)->_file)
659
#if 0 /* XXX Emscripten ndef _REENT_SMALL */
660
#define feof(p) __sfeof(p)
661
#define ferror(p) __sferror(p)
662
#define clearerr(p) __sclearerr(p)
665
#if 0 /*ndef __STRICT_ANSI__ - FIXME: must initialize stdio first, use fn */
666
#define fileno(p) __sfileno(p)
669
#if !defined(__CYGWIN__) && !defined(EMSCRIPTEN)
671
#define getc(fp) __sgetc_r(_REENT, fp)
672
#define putc(x, fp) __sputc_r(_REENT, x, fp)
674
#endif /* __CYGWIN__ */
676
#ifndef __STRICT_ANSI__
677
/* fast always-buffered version, true iff error */
678
#define fast_putc(x,p) (--(p)->_w < 0 ? \
679
__swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
681
#define L_cuserid 9 /* posix says it goes in stdio.h :( */
682
#if defined(__CYGWIN__) || defined(EMSCRIPTEN)
687
#endif /* !__CUSTOM_FILE_IO__ */
689
#define getchar() getc(stdin)
690
#define putchar(x) putc(x, stdout)
694
#endif /* _STDIO_H_ */