Subversion Repositories Kolibri OS

Rev

Rev 6099 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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