source: trunk/libs/newlib/src/newlib/libc/include/stdio.h @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 29.0 KB
Line 
1/*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
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.
16 *
17 *      @(#)stdio.h     5.3 (Berkeley) 3/15/86
18 */
19
20/*
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.
24 */
25
26#ifndef _STDIO_H_
27#define _STDIO_H_
28
29#include "_ansi.h"
30
31#define _FSTDIO                 /* ``function stdio'' */
32
33#define __need_size_t
34#define __need_NULL
35#include <sys/cdefs.h>
36#include <stddef.h>
37
38/* typedef only __gnuc_va_list, used throughout the header */
39#define __need___va_list
40#include <stdarg.h>
41
42/* typedef va_list only when required */
43#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
44#ifdef __GNUC__
45#ifndef _VA_LIST_DEFINED
46typedef __gnuc_va_list va_list;
47#define _VA_LIST_DEFINED
48#endif
49#else /* !__GNUC__ */
50#include <stdarg.h>
51#endif
52#endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */
53
54/*
55 * <sys/reent.h> defines __FILE, _fpos_t.
56 * They must be defined there because struct _reent needs them (and we don't
57 * want reent.h to include this file.
58 */
59
60#include <sys/reent.h>
61#include <sys/types.h>
62
63_BEGIN_STD_C
64
65#if !defined(__FILE_defined)
66typedef __FILE FILE;
67# define __FILE_defined
68#endif
69
70#ifdef __CYGWIN__
71typedef _fpos64_t fpos_t;
72#else
73typedef _fpos_t fpos_t;
74#ifdef __LARGE64_FILES
75typedef _fpos64_t fpos64_t;
76#endif
77#endif /* !__CYGWIN__ */
78
79#include <sys/stdio.h>
80
81#define __SLBF  0x0001          /* line buffered */
82#define __SNBF  0x0002          /* unbuffered */
83#define __SRD   0x0004          /* OK to read */
84#define __SWR   0x0008          /* OK to write */
85        /* RD and WR are never simultaneously asserted */
86#define __SRW   0x0010          /* open for reading & writing */
87#define __SEOF  0x0020          /* found EOF */
88#define __SERR  0x0040          /* found error */
89#define __SMBF  0x0080          /* _buf is from malloc */
90#define __SAPP  0x0100          /* fdopen()ed in append mode - so must  write to end */
91#define __SSTR  0x0200          /* this is an sprintf/snprintf string */
92#define __SOPT  0x0400          /* do fseek() optimisation */
93#define __SNPT  0x0800          /* do not do fseek() optimisation */
94#define __SOFF  0x1000          /* set iff _offset is in fact correct */
95#define __SORD  0x2000          /* true => stream orientation (byte/wide) decided */
96#if defined(__CYGWIN__)
97#  define __SCLE  0x4000        /* convert line endings CR/LF <-> NL */
98#endif
99#define __SL64  0x8000          /* is 64-bit offset large file */
100
101/* _flags2 flags */
102#define __SNLK  0x0001          /* stdio functions do not lock streams themselves */
103#define __SWID  0x2000          /* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */
104
105/*
106 * The following three definitions are for ANSI C, which took them
107 * from System V, which stupidly took internal interface macros and
108 * made them official arguments to setvbuf(), without renaming them.
109 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
110 *
111 * Although these happen to match their counterparts above, the
112 * implementation does not rely on that (so these could be renumbered).
113 */
114#define _IOFBF  0               /* setvbuf should set fully buffered */
115#define _IOLBF  1               /* setvbuf should set line buffered */
116#define _IONBF  2               /* setvbuf should set unbuffered */
117
118#define EOF     (-1)
119
120#ifdef __BUFSIZ__
121#define BUFSIZ          __BUFSIZ__
122#else
123#define BUFSIZ          1024
124#endif
125
126#ifdef __FOPEN_MAX__
127#define FOPEN_MAX       __FOPEN_MAX__
128#else
129#define FOPEN_MAX       20
130#endif
131
132#ifdef __FILENAME_MAX__
133#define FILENAME_MAX    __FILENAME_MAX__
134#else
135#define FILENAME_MAX    1024
136#endif
137
138#ifdef __L_tmpnam__
139#define L_tmpnam        __L_tmpnam__
140#else
141#define L_tmpnam        FILENAME_MAX
142#endif
143
144#if __BSD_VISIBLE || __XSI_VISIBLE
145#define P_tmpdir        "/tmp"
146#endif
147
148#ifndef SEEK_SET
149#define SEEK_SET        0       /* set file offset to offset */
150#endif
151#ifndef SEEK_CUR
152#define SEEK_CUR        1       /* set file offset to current plus offset */
153#endif
154#ifndef SEEK_END
155#define SEEK_END        2       /* set file offset to EOF plus offset */
156#endif
157
158#define TMP_MAX         26
159
160#define stdin   (_REENT->_stdin)
161#define stdout  (_REENT->_stdout)
162#define stderr  (_REENT->_stderr)
163
164#define _stdin_r(x)     ((x)->_stdin)
165#define _stdout_r(x)    ((x)->_stdout)
166#define _stderr_r(x)    ((x)->_stderr)
167
168/*
169 * Functions defined in ANSI C standard.
170 */
171
172#ifndef __VALIST
173#ifdef __GNUC__
174#define __VALIST __gnuc_va_list
175#else
176#define __VALIST char*
177#endif
178#endif
179
180#if __POSIX_VISIBLE
181char *  ctermid (char *);
182#endif
183#if __XSI_VISIBLE && __XSI_VISIBLE < 600
184char *  cuserid (char *);
185#endif
186FILE *  tmpfile (void);
187char *  tmpnam (char *);
188#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
189char *  tempnam (const char *, const char *);
190#endif
191int     fclose (FILE *);
192int     fflush (FILE *);
193FILE *  freopen (const char *__restrict, const char *__restrict, FILE *__restrict);
194void    setbuf (FILE *__restrict, char *__restrict);
195int     setvbuf (FILE *__restrict, char *__restrict, int, size_t);
196int     fprintf (FILE *__restrict, const char *__restrict, ...)
197               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
198int     fscanf (FILE *__restrict, const char *__restrict, ...)
199               _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
200int     printf (const char *__restrict, ...)
201               _ATTRIBUTE ((__format__ (__printf__, 1, 2)));
202int     scanf (const char *__restrict, ...)
203               _ATTRIBUTE ((__format__ (__scanf__, 1, 2)));
204int     sscanf (const char *__restrict, const char *__restrict, ...)
205               _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
206int     vfprintf (FILE *__restrict, const char *__restrict, __VALIST)
207               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
208int     vprintf (const char *, __VALIST)
209               _ATTRIBUTE ((__format__ (__printf__, 1, 0)));
210int     vsprintf (char *__restrict, const char *__restrict, __VALIST)
211               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
212int     fgetc (FILE *);
213char *  fgets (char *__restrict, int, FILE *__restrict);
214int     fputc (int, FILE *);
215int     fputs (const char *__restrict, FILE *__restrict);
216int     getc (FILE *);
217int     getchar (void);
218char *  gets (char *);
219int     putc (int, FILE *);
220int     putchar (int);
221int     puts (const char *);
222int     ungetc (int, FILE *);
223size_t  fread (void *__restrict, size_t _size, size_t _n, FILE *__restrict);
224size_t  fwrite (const void *__restrict , size_t _size, size_t _n, FILE *);
225#ifdef _COMPILING_NEWLIB
226int     fgetpos (FILE *, _fpos_t *);
227#else
228int     fgetpos (FILE *__restrict, fpos_t *__restrict);
229#endif
230int     fseek (FILE *, long, int);
231#ifdef _COMPILING_NEWLIB
232int     fsetpos (FILE *, const _fpos_t *);
233#else
234int     fsetpos (FILE *, const fpos_t *);
235#endif
236long    ftell ( FILE *);
237void    rewind (FILE *);
238void    clearerr (FILE *);
239int     feof (FILE *);
240int     ferror (FILE *);
241void    perror (const char *);
242#ifndef _REENT_ONLY
243FILE *  fopen (const char *__restrict _name, const char *__restrict _type);
244int     sprintf (char *__restrict, const char *__restrict, ...)
245               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
246int     remove (const char *);
247int     rename (const char *, const char *);
248#ifdef _COMPILING_NEWLIB
249int     _rename (const char *, const char *);
250#endif
251#endif
252#if __LARGEFILE_VISIBLE || __POSIX_VISIBLE >= 200112
253#ifdef _COMPILING_NEWLIB
254int     fseeko (FILE *, _off_t, int);
255_off_t  ftello (FILE *);
256#else
257int     fseeko (FILE *, off_t, int);
258off_t   ftello (FILE *);
259#endif
260#endif
261#if __GNU_VISIBLE
262int     fcloseall (void);
263#endif
264#ifndef _REENT_ONLY
265#if __ISO_C_VISIBLE >= 1999
266int     snprintf (char *__restrict, size_t, const char *__restrict, ...)
267               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
268int     vsnprintf (char *__restrict, size_t, const char *__restrict, __VALIST)
269               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
270int     vfscanf (FILE *__restrict, const char *__restrict, __VALIST)
271               _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
272int     vscanf (const char *, __VALIST)
273               _ATTRIBUTE ((__format__ (__scanf__, 1, 0)));
274int     vsscanf (const char *__restrict, const char *__restrict, __VALIST)
275               _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
276#endif
277#if __GNU_VISIBLE
278int     asprintf (char **__restrict, const char *__restrict, ...)
279               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
280int     vasprintf (char **, const char *, __VALIST)
281               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
282#endif
283#if __MISC_VISIBLE /* Newlib-specific */
284int     asiprintf (char **, const char *, ...)
285               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
286char *  asniprintf (char *, size_t *, const char *, ...)
287               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
288char *  asnprintf (char *__restrict, size_t *__restrict, const char *__restrict, ...)
289               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
290#ifndef diprintf
291int     diprintf (int, const char *, ...)
292               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
293#endif
294int     fiprintf (FILE *, const char *, ...)
295               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
296int     fiscanf (FILE *, const char *, ...)
297               _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
298int     iprintf (const char *, ...)
299               _ATTRIBUTE ((__format__ (__printf__, 1, 2)));
300int     iscanf (const char *, ...)
301               _ATTRIBUTE ((__format__ (__scanf__, 1, 2)));
302int     siprintf (char *, const char *, ...)
303               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
304int     siscanf (const char *, const char *, ...)
305               _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
306int     sniprintf (char *, size_t, const char *, ...)
307               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
308int     vasiprintf (char **, const char *, __VALIST)
309               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
310char *  vasniprintf (char *, size_t *, const char *, __VALIST)
311               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
312char *  vasnprintf (char *, size_t *, const char *, __VALIST)
313               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
314int     vdiprintf (int, const char *, __VALIST)
315               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
316int     vfiprintf (FILE *, const char *, __VALIST)
317               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
318int     vfiscanf (FILE *, const char *, __VALIST)
319               _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
320int     viprintf (const char *, __VALIST)
321               _ATTRIBUTE ((__format__ (__printf__, 1, 0)));
322int     viscanf (const char *, __VALIST)
323               _ATTRIBUTE ((__format__ (__scanf__, 1, 0)));
324int     vsiprintf (char *, const char *, __VALIST)
325               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
326int     vsiscanf (const char *, const char *, __VALIST)
327               _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
328int     vsniprintf (char *, size_t, const char *, __VALIST)
329               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
330#endif /* __MISC_VISIBLE */
331#endif /* !_REENT_ONLY */
332
333/*
334 * Routines in POSIX 1003.1:2001.
335 */
336
337#if __POSIX_VISIBLE
338#ifndef _REENT_ONLY
339FILE *  fdopen (int, const char *);
340#endif
341int     fileno (FILE *);
342#endif
343#if __MISC_VISIBLE || __POSIX_VISIBLE >= 199209
344int     pclose (FILE *);
345FILE *  popen (const char *, const char *);
346#endif
347
348#if __BSD_VISIBLE
349void    setbuffer (FILE *, char *, int);
350int     setlinebuf (FILE *);
351#endif
352
353#if __MISC_VISIBLE || (__XSI_VISIBLE && __POSIX_VISIBLE < 200112)
354int     getw (FILE *);
355int     putw (int, FILE *);
356#endif
357#if __MISC_VISIBLE || __POSIX_VISIBLE
358int     getc_unlocked (FILE *);
359int     getchar_unlocked (void);
360void    flockfile (FILE *);
361int     ftrylockfile (FILE *);
362void    funlockfile (FILE *);
363int     putc_unlocked (int, FILE *);
364int     putchar_unlocked (int);
365#endif
366
367/*
368 * Routines in POSIX 1003.1:200x.
369 */
370
371#if __POSIX_VISIBLE >= 200809
372# ifndef _REENT_ONLY
373#  ifndef dprintf
374int     dprintf (int, const char *__restrict, ...)
375               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
376#  endif
377FILE *  fmemopen (void *__restrict, size_t, const char *__restrict);
378/* getdelim - see __getdelim for now */
379/* getline - see __getline for now */
380FILE *  open_memstream (char **, size_t *);
381int     vdprintf (int, const char *__restrict, __VALIST)
382               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
383# endif
384#endif
385#if __ATFILE_VISIBLE
386int     renameat (int, const char *, int, const char *);
387# ifdef __CYGWIN__
388int     renameat2 (int, const char *, int, const char *, unsigned int);
389# endif
390#endif
391
392/*
393 * Recursive versions of the above.
394 */
395
396int     _asiprintf_r (struct _reent *, char **, const char *, ...)
397               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
398char *  _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...)
399               _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
400char *  _asnprintf_r (struct _reent *, char *__restrict, size_t *__restrict, const char *__restrict, ...)
401               _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
402int     _asprintf_r (struct _reent *, char **__restrict, const char *__restrict, ...)
403               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
404int     _diprintf_r (struct _reent *, int, const char *, ...)
405               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
406int     _dprintf_r (struct _reent *, int, const char *__restrict, ...)
407               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
408int     _fclose_r (struct _reent *, FILE *);
409int     _fcloseall_r (struct _reent *);
410FILE *  _fdopen_r (struct _reent *, int, const char *);
411int     _fflush_r (struct _reent *, FILE *);
412int     _fgetc_r (struct _reent *, FILE *);
413int     _fgetc_unlocked_r (struct _reent *, FILE *);
414char *  _fgets_r (struct _reent *, char *__restrict, int, FILE *__restrict);
415char *  _fgets_unlocked_r (struct _reent *, char *__restrict, int, FILE *__restrict);
416#ifdef _COMPILING_NEWLIB
417int     _fgetpos_r (struct _reent *, FILE *__restrict, _fpos_t *__restrict);
418int     _fsetpos_r (struct _reent *, FILE *, const _fpos_t *);
419#else
420int     _fgetpos_r (struct _reent *, FILE *, fpos_t *);
421int     _fsetpos_r (struct _reent *, FILE *, const fpos_t *);
422#endif
423int     _fiprintf_r (struct _reent *, FILE *, const char *, ...)
424               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
425int     _fiscanf_r (struct _reent *, FILE *, const char *, ...)
426               _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
427FILE *  _fmemopen_r (struct _reent *, void *__restrict, size_t, const char *__restrict);
428FILE *  _fopen_r (struct _reent *, const char *__restrict, const char *__restrict);
429FILE *  _freopen_r (struct _reent *, const char *__restrict, const char *__restrict, FILE *__restrict);
430int     _fprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)
431               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
432int     _fpurge_r (struct _reent *, FILE *);
433int     _fputc_r (struct _reent *, int, FILE *);
434int     _fputc_unlocked_r (struct _reent *, int, FILE *);
435int     _fputs_r (struct _reent *, const char *__restrict, FILE *__restrict);
436int     _fputs_unlocked_r (struct _reent *, const char *__restrict, FILE *__restrict);
437size_t  _fread_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
438size_t  _fread_unlocked_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
439int     _fscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)
440               _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
441int     _fseek_r (struct _reent *, FILE *, long, int);
442int     _fseeko_r (struct _reent *, FILE *, _off_t, int);
443long    _ftell_r (struct _reent *, FILE *);
444_off_t  _ftello_r (struct _reent *, FILE *);
445void    _rewind_r (struct _reent *, FILE *);
446size_t  _fwrite_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
447size_t  _fwrite_unlocked_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
448int     _getc_r (struct _reent *, FILE *);
449int     _getc_unlocked_r (struct _reent *, FILE *);
450int     _getchar_r (struct _reent *);
451int     _getchar_unlocked_r (struct _reent *);
452char *  _gets_r (struct _reent *, char *);
453int     _iprintf_r (struct _reent *, const char *, ...)
454               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
455int     _iscanf_r (struct _reent *, const char *, ...)
456               _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
457FILE *  _open_memstream_r (struct _reent *, char **, size_t *);
458void    _perror_r (struct _reent *, const char *);
459int     _printf_r (struct _reent *, const char *__restrict, ...)
460               _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
461int     _putc_r (struct _reent *, int, FILE *);
462int     _putc_unlocked_r (struct _reent *, int, FILE *);
463int     _putchar_unlocked_r (struct _reent *, int);
464int     _putchar_r (struct _reent *, int);
465int     _puts_r (struct _reent *, const char *);
466int     _remove_r (struct _reent *, const char *);
467int     _rename_r (struct _reent *,
468                           const char *_old, const char *_new);
469int     _scanf_r (struct _reent *, const char *__restrict, ...)
470               _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
471int     _siprintf_r (struct _reent *, char *, const char *, ...)
472               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
473int     _siscanf_r (struct _reent *, const char *, const char *, ...)
474               _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
475int     _sniprintf_r (struct _reent *, char *, size_t, const char *, ...)
476               _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
477int     _snprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, ...)
478               _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
479int     _sprintf_r (struct _reent *, char *__restrict, const char *__restrict, ...)
480               _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
481int     _sscanf_r (struct _reent *, const char *__restrict, const char *__restrict, ...)
482               _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
483char *  _tempnam_r (struct _reent *, const char *, const char *);
484FILE *  _tmpfile_r (struct _reent *);
485char *  _tmpnam_r (struct _reent *, char *);
486int     _ungetc_r (struct _reent *, int, FILE *);
487int     _vasiprintf_r (struct _reent *, char **, const char *, __VALIST)
488               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
489char *  _vasniprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST)
490               _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
491char *  _vasnprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST)
492               _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
493int     _vasprintf_r (struct _reent *, char **, const char *, __VALIST)
494               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
495int     _vdiprintf_r (struct _reent *, int, const char *, __VALIST)
496               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
497int     _vdprintf_r (struct _reent *, int, const char *__restrict, __VALIST)
498               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
499int     _vfiprintf_r (struct _reent *, FILE *, const char *, __VALIST)
500               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
501int     _vfiscanf_r (struct _reent *, FILE *, const char *, __VALIST)
502               _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
503int     _vfprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
504               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
505int     _vfscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
506               _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
507int     _viprintf_r (struct _reent *, const char *, __VALIST)
508               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
509int     _viscanf_r (struct _reent *, const char *, __VALIST)
510               _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
511int     _vprintf_r (struct _reent *, const char *__restrict, __VALIST)
512               _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
513int     _vscanf_r (struct _reent *, const char *__restrict, __VALIST)
514               _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
515int     _vsiprintf_r (struct _reent *, char *, const char *, __VALIST)
516               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
517int     _vsiscanf_r (struct _reent *, const char *, const char *, __VALIST)
518               _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
519int     _vsniprintf_r (struct _reent *, char *, size_t, const char *, __VALIST)
520               _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
521int     _vsnprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, __VALIST)
522               _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
523int     _vsprintf_r (struct _reent *, char *__restrict, const char *__restrict, __VALIST)
524               _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
525int     _vsscanf_r (struct _reent *, const char *__restrict, const char *__restrict, __VALIST)
526               _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
527
528/* Other extensions.  */
529
530int     fpurge (FILE *);
531ssize_t __getdelim (char **, size_t *, int, FILE *);
532ssize_t __getline (char **, size_t *, FILE *);
533
534#if __MISC_VISIBLE
535void    clearerr_unlocked (FILE *);
536int     feof_unlocked (FILE *);
537int     ferror_unlocked (FILE *);
538int     fileno_unlocked (FILE *);
539int     fflush_unlocked (FILE *);
540int     fgetc_unlocked (FILE *);
541int     fputc_unlocked (int, FILE *);
542size_t  fread_unlocked (void *__restrict, size_t _size, size_t _n, FILE *__restrict);
543size_t  fwrite_unlocked (const void *__restrict , size_t _size, size_t _n, FILE *);
544#endif
545
546#if __GNU_VISIBLE
547char *  fgets_unlocked (char *__restrict, int, FILE *__restrict);
548int     fputs_unlocked (const char *__restrict, FILE *__restrict);
549#endif
550
551#ifdef __LARGE64_FILES
552#if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB)
553FILE *  fdopen64 (int, const char *);
554FILE *  fopen64 (const char *, const char *);
555FILE *  freopen64 (const char *, const char *, FILE *);
556_off64_t ftello64 (FILE *);
557_off64_t fseeko64 (FILE *, _off64_t, int);
558int     fgetpos64 (FILE *, _fpos64_t *);
559int     fsetpos64 (FILE *, const _fpos64_t *);
560FILE *  tmpfile64 (void);
561
562FILE *  _fdopen64_r (struct _reent *, int, const char *);
563FILE *  _fopen64_r (struct _reent *,const char *, const char *);
564FILE *  _freopen64_r (struct _reent *, const char *, const char *, FILE *);
565_off64_t _ftello64_r (struct _reent *, FILE *);
566_off64_t _fseeko64_r (struct _reent *, FILE *, _off64_t, int);
567int     _fgetpos64_r (struct _reent *, FILE *, _fpos64_t *);
568int     _fsetpos64_r (struct _reent *, FILE *, const _fpos64_t *);
569FILE *  _tmpfile64_r (struct _reent *);
570#endif /* !__CYGWIN__ */
571#endif /* __LARGE64_FILES */
572
573/*
574 * Routines internal to the implementation.
575 */
576
577int     __srget_r (struct _reent *, FILE *);
578int     __swbuf_r (struct _reent *, int, FILE *);
579
580/*
581 * Stdio function-access interface.
582 */
583
584#if __BSD_VISIBLE
585# ifdef __LARGE64_FILES
586FILE    *funopen (const void *__cookie,
587                int (*__readfn)(void *__c, char *__buf,
588                                _READ_WRITE_BUFSIZE_TYPE __n),
589                int (*__writefn)(void *__c, const char *__buf,
590                                 _READ_WRITE_BUFSIZE_TYPE __n),
591                _fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence),
592                int (*__closefn)(void *__c));
593FILE    *_funopen_r (struct _reent *, const void *__cookie,
594                int (*__readfn)(void *__c, char *__buf,
595                                _READ_WRITE_BUFSIZE_TYPE __n),
596                int (*__writefn)(void *__c, const char *__buf,
597                                 _READ_WRITE_BUFSIZE_TYPE __n),
598                _fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence),
599                int (*__closefn)(void *__c));
600# else
601FILE    *funopen (const void *__cookie,
602                int (*__readfn)(void *__cookie, char *__buf,
603                                _READ_WRITE_BUFSIZE_TYPE __n),
604                int (*__writefn)(void *__cookie, const char *__buf,
605                                 _READ_WRITE_BUFSIZE_TYPE __n),
606                fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence),
607                int (*__closefn)(void *__cookie));
608FILE    *_funopen_r (struct _reent *, const void *__cookie,
609                int (*__readfn)(void *__cookie, char *__buf,
610                                _READ_WRITE_BUFSIZE_TYPE __n),
611                int (*__writefn)(void *__cookie, const char *__buf,
612                                 _READ_WRITE_BUFSIZE_TYPE __n),
613                fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence),
614                int (*__closefn)(void *__cookie));
615# endif /* !__LARGE64_FILES */
616
617# define        fropen(__cookie, __fn) funopen(__cookie, __fn, (int (*)())0, \
618                                               (fpos_t (*)())0, (int (*)())0)
619# define        fwopen(__cookie, __fn) funopen(__cookie, (int (*)())0, __fn, \
620                                               (fpos_t (*)())0, (int (*)())0)
621#endif /* __BSD_VISIBLE */
622
623#if __GNU_VISIBLE
624typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
625typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
626                                        size_t __n);
627# ifdef __LARGE64_FILES
628typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,
629                                   int __whence);
630# else
631typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);
632# endif /* !__LARGE64_FILES */
633typedef int cookie_close_function_t(void *__cookie);
634typedef struct
635{
636  /* These four struct member names are dictated by Linux; hopefully,
637     they don't conflict with any macros.  */
638  cookie_read_function_t  *read;
639  cookie_write_function_t *write;
640  cookie_seek_function_t  *seek;
641  cookie_close_function_t *close;
642} cookie_io_functions_t;
643FILE *fopencookie (void *__cookie,
644                const char *__mode, cookie_io_functions_t __functions);
645FILE *_fopencookie_r (struct _reent *, void *__cookie,
646                const char *__mode, cookie_io_functions_t __functions);
647#endif /* __GNU_VISIBLE */
648
649#ifndef __CUSTOM_FILE_IO__
650/*
651 * The __sfoo macros are here so that we can
652 * define function versions in the C library.
653 */
654#define       __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++))
655
656#ifdef __SCLE
657/*  For a platform with CR/LF, additional logic is required by
658  __sgetc_r which would otherwise simply be a macro; therefore we
659  use an inlined function.  The function is only meant to be inlined
660  in place as used and the function body should never be emitted. 
661
662  There are two possible means to this end when compiling with GCC,
663  one when compiling with a standard C99 compiler, and for other
664  compilers we're just stuck.  At the moment, this issue only
665  affects the Cygwin target, so we'll most likely be using GCC. */
666
667_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p);
668
669_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p)
670  {
671    int __c = __sgetc_raw_r(__ptr, __p);
672    if ((__p->_flags & __SCLE) && (__c == '\r'))
673      {
674      int __c2 = __sgetc_raw_r(__ptr, __p);
675      if (__c2 == '\n')
676        __c = __c2;
677      else
678        ungetc(__c2, __p);
679      }
680    return __c;
681  }
682#else
683#define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
684#endif
685
686#ifdef __GNUC__
687_ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
688#ifdef __SCLE
689        if ((_p->_flags & __SCLE) && _c == '\n')
690          __sputc_r (_ptr, '\r', _p);
691#endif
692        if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
693                return (*_p->_p++ = _c);
694        else
695                return (__swbuf_r(_ptr, _c, _p));
696}
697#else
698/*
699 * This has been tuned to generate reasonable code on the vax using pcc
700 */
701#define       __sputc_raw_r(__ptr, __c, __p) \
702        (--(__p)->_w < 0 ? \
703                (__p)->_w >= (__p)->_lbfsize ? \
704                        (*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \
705                                (int)*(__p)->_p++ : \
706                                __swbuf_r(__ptr, '\n', __p) : \
707                        __swbuf_r(__ptr, (int)(__c), __p) : \
708                (*(__p)->_p = (__c), (int)*(__p)->_p++))
709#ifdef __SCLE
710#define __sputc_r(__ptr, __c, __p) \
711        ((((__p)->_flags & __SCLE) && ((__c) == '\n')) \
712          ? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \
713        __sputc_raw_r((__ptr), (__c), (__p)))
714#else
715#define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p)
716#endif
717#endif
718
719#define __sfeof(p)      ((int)(((p)->_flags & __SEOF) != 0))
720#define __sferror(p)    ((int)(((p)->_flags & __SERR) != 0))
721#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
722#define __sfileno(p)    ((p)->_file)
723
724#ifndef __cplusplus
725#ifndef _REENT_SMALL
726#define feof(p)         __sfeof(p)
727#define ferror(p)       __sferror(p)
728#define clearerr(p)     __sclearerr(p)
729
730#if __MISC_VISIBLE
731#define feof_unlocked(p)        __sfeof(p)
732#define ferror_unlocked(p)      __sferror(p)
733#define clearerr_unlocked(p)    __sclearerr(p)
734#endif /* __MISC_VISIBLE */
735#endif /* _REENT_SMALL */
736
737#if 0 /* __POSIX_VISIBLE - FIXME: must initialize stdio first, use fn */
738#define fileno(p)       __sfileno(p)
739#endif
740
741static __inline int
742_getchar_unlocked(void)
743{
744        struct _reent *_ptr;
745
746        _ptr = _REENT;
747        return (__sgetc_r(_ptr, _stdin_r(_ptr)));
748}
749
750static __inline int
751_putchar_unlocked(int _c)
752{
753        struct _reent *_ptr;
754
755        _ptr = _REENT;
756        return (__sputc_r(_ptr, _c, _stdout_r(_ptr)));
757}
758
759#ifdef __SINGLE_THREAD__
760#define getc(_p)        __sgetc_r(_REENT, _p)
761#define putc(_c, _p)    __sputc_r(_REENT, _c, _p)
762#define getchar()       _getchar_unlocked()
763#define putchar(_c)     _putchar_unlocked(_c)
764#endif /* __SINGLE_THREAD__ */
765
766#if __MISC_VISIBLE || __POSIX_VISIBLE
767#define getchar_unlocked()      _getchar_unlocked()
768#define putchar_unlocked(_c)    _putchar_unlocked(_c)
769#endif
770#endif /* __cplusplus */
771
772#if __MISC_VISIBLE
773/* fast always-buffered version, true iff error */
774#define fast_putc(x,p) (--(p)->_w < 0 ? \
775        __swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
776#endif
777
778#if __GNU_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 600)
779#define L_cuserid       9               /* posix says it goes in stdio.h :( */
780#endif
781#if __POSIX_VISIBLE
782#define L_ctermid       16
783#endif
784
785#else /* __CUSTOM_FILE_IO__ */
786
787#define getchar()       getc(stdin)
788#define putchar(x)      putc(x, stdout)
789
790#if __MISC_VISIBLE || __POSIX_VISIBLE
791#define getchar_unlocked()      getc_unlocked(stdin)
792#define putchar_unlocked(x)     putc_unlocked(x, stdout)
793#endif
794
795#endif /* !__CUSTOM_FILE_IO__ */
796
797_END_STD_C
798
799#if __SSP_FORTIFY_LEVEL > 0
800#include <ssp/stdio.h>
801#endif
802
803#endif /* _STDIO_H_ */
Note: See TracBrowser for help on using the repository browser.