Subversion Repositories Kolibri OS

Rev

Rev 5963 | 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
 
131
#ifndef __STRICT_ANSI__
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
4349 Serge 233
#if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K)
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
245
#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
4349 Serge 246
#ifndef _REENT_ONLY
247
int	_EXFUN(asiprintf, (char **, const char *, ...)
248
               _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
249
char *	_EXFUN(asniprintf, (char *, size_t *, const char *, ...)
250
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
4921 Serge 251
char *	_EXFUN(asnprintf, (char *__restrict, size_t *__restrict, const char *__restrict, ...)
4349 Serge 252
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
4921 Serge 253
int	_EXFUN(asprintf, (char **__restrict, const char *__restrict, ...)
4349 Serge 254
               _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
255
#ifndef diprintf
256
int	_EXFUN(diprintf, (int, const char *, ...)
257
               _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
258
#endif
259
int	_EXFUN(fiprintf, (FILE *, const char *, ...)
260
               _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
261
int	_EXFUN(fiscanf, (FILE *, const char *, ...)
262
               _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
263
int	_EXFUN(iprintf, (const char *, ...)
264
               _ATTRIBUTE ((__format__ (__printf__, 1, 2))));
265
int	_EXFUN(iscanf, (const char *, ...)
266
               _ATTRIBUTE ((__format__ (__scanf__, 1, 2))));
267
int	_EXFUN(siprintf, (char *, const char *, ...)
268
               _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
269
int	_EXFUN(siscanf, (const char *, const char *, ...)
270
               _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
4921 Serge 271
int	_EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...)
4349 Serge 272
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
6099 serge 273
int	_EXFUN(sniprintf, (char *, size_t, const char *, ...)
4349 Serge 274
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
275
int	_EXFUN(vasiprintf, (char **, const char *, __VALIST)
276
               _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
277
char *	_EXFUN(vasniprintf, (char *, size_t *, const char *, __VALIST)
278
               _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
279
char *	_EXFUN(vasnprintf, (char *, size_t *, const char *, __VALIST)
280
               _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
281
int	_EXFUN(vasprintf, (char **, const char *, __VALIST)
282
               _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
283
int	_EXFUN(vdiprintf, (int, const char *, __VALIST)
284
               _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
285
int	_EXFUN(vfiprintf, (FILE *, const char *, __VALIST)
286
               _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
287
int	_EXFUN(vfiscanf, (FILE *, const char *, __VALIST)
288
               _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
4921 Serge 289
int	_EXFUN(vfscanf, (FILE *__restrict, const char *__restrict, __VALIST)
4349 Serge 290
               _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
291
int	_EXFUN(viprintf, (const char *, __VALIST)
292
               _ATTRIBUTE ((__format__ (__printf__, 1, 0))));
293
int	_EXFUN(viscanf, (const char *, __VALIST)
294
               _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
295
int	_EXFUN(vscanf, (const char *, __VALIST)
296
               _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
297
int	_EXFUN(vsiprintf, (char *, const char *, __VALIST)
298
               _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
299
int	_EXFUN(vsiscanf, (const char *, const char *, __VALIST)
300
               _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
301
int	_EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST)
302
               _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
4921 Serge 303
int	_EXFUN(vsnprintf, (char *__restrict, size_t, const char *__restrict, __VALIST)
4349 Serge 304
               _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
4921 Serge 305
int	_EXFUN(vsscanf, (const char *__restrict, const char *__restrict, __VALIST)
4349 Serge 306
               _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
307
#endif /* !_REENT_ONLY */
308
#endif /* !__STRICT_ANSI__ */
309
 
310
/*
311
 * Routines in POSIX 1003.1:2001.
312
 */
313
 
314
#ifndef __STRICT_ANSI__
315
#ifndef _REENT_ONLY
316
FILE *	_EXFUN(fdopen, (int, const char *));
317
#endif
318
int	_EXFUN(fileno, (FILE *));
319
int	_EXFUN(getw, (FILE *));
320
int	_EXFUN(pclose, (FILE *));
321
FILE *  _EXFUN(popen, (const char *, const char *));
322
int	_EXFUN(putw, (int, FILE *));
323
void    _EXFUN(setbuffer, (FILE *, char *, int));
324
int	_EXFUN(setlinebuf, (FILE *));
325
int	_EXFUN(getc_unlocked, (FILE *));
326
int	_EXFUN(getchar_unlocked, (void));
327
void	_EXFUN(flockfile, (FILE *));
328
int	_EXFUN(ftrylockfile, (FILE *));
329
void	_EXFUN(funlockfile, (FILE *));
330
int	_EXFUN(putc_unlocked, (int, FILE *));
331
int	_EXFUN(putchar_unlocked, (int));
332
#endif /* ! __STRICT_ANSI__ */
333
 
334
/*
335
 * Routines in POSIX 1003.1:200x.
336
 */
337
 
338
#ifndef __STRICT_ANSI__
339
# ifndef _REENT_ONLY
340
#  ifndef dprintf
4921 Serge 341
int	_EXFUN(dprintf, (int, const char *__restrict, ...)
4349 Serge 342
               _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
343
#  endif
4921 Serge 344
FILE *	_EXFUN(fmemopen, (void *__restrict, size_t, const char *__restrict));
4349 Serge 345
/* getdelim - see __getdelim for now */
346
/* getline - see __getline for now */
347
FILE *	_EXFUN(open_memstream, (char **, size_t *));
6099 serge 348
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
4349 Serge 349
int	_EXFUN(renameat, (int, const char *, int, const char *));
350
#endif
4921 Serge 351
int	_EXFUN(vdprintf, (int, const char *__restrict, __VALIST)
4349 Serge 352
               _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
353
# endif
354
#endif
355
 
356
/*
357
 * Recursive versions of the above.
358
 */
359
 
360
int	_EXFUN(_asiprintf_r, (struct _reent *, char **, const char *, ...)
361
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
362
char *	_EXFUN(_asniprintf_r, (struct _reent *, char *, size_t *, const char *, ...)
363
               _ATTRIBUTE ((__format__ (__printf__, 4, 5))));
4921 Serge 364
char *	_EXFUN(_asnprintf_r, (struct _reent *, char *__restrict, size_t *__restrict, const char *__restrict, ...)
4349 Serge 365
               _ATTRIBUTE ((__format__ (__printf__, 4, 5))));
4921 Serge 366
int	_EXFUN(_asprintf_r, (struct _reent *, char **__restrict, const char *__restrict, ...)
4349 Serge 367
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
368
int	_EXFUN(_diprintf_r, (struct _reent *, int, const char *, ...)
369
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
4921 Serge 370
int	_EXFUN(_dprintf_r, (struct _reent *, int, const char *__restrict, ...)
4349 Serge 371
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
372
int	_EXFUN(_fclose_r, (struct _reent *, FILE *));
373
int	_EXFUN(_fcloseall_r, (struct _reent *));
374
FILE *	_EXFUN(_fdopen_r, (struct _reent *, int, const char *));
375
int	_EXFUN(_fflush_r, (struct _reent *, FILE *));
376
int	_EXFUN(_fgetc_r, (struct _reent *, FILE *));
6099 serge 377
int	_EXFUN(_fgetc_unlocked_r, (struct _reent *, FILE *));
4921 Serge 378
char *  _EXFUN(_fgets_r, (struct _reent *, char *__restrict, int, FILE *__restrict));
6099 serge 379
char *  _EXFUN(_fgets_unlocked_r, (struct _reent *, char *__restrict, int, FILE *__restrict));
4349 Serge 380
#ifdef _COMPILING_NEWLIB
4921 Serge 381
int	_EXFUN(_fgetpos_r, (struct _reent *, FILE *__restrict, _fpos_t *__restrict));
4349 Serge 382
int	_EXFUN(_fsetpos_r, (struct _reent *, FILE *, const _fpos_t *));
383
#else
384
int	_EXFUN(_fgetpos_r, (struct _reent *, FILE *, fpos_t *));
385
int	_EXFUN(_fsetpos_r, (struct _reent *, FILE *, const fpos_t *));
386
#endif
387
int	_EXFUN(_fiprintf_r, (struct _reent *, FILE *, const char *, ...)
388
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
389
int	_EXFUN(_fiscanf_r, (struct _reent *, FILE *, const char *, ...)
390
               _ATTRIBUTE ((__format__ (__scanf__, 3, 4))));
4921 Serge 391
FILE *	_EXFUN(_fmemopen_r, (struct _reent *, void *__restrict, size_t, const char *__restrict));
392
FILE *	_EXFUN(_fopen_r, (struct _reent *, const char *__restrict, const char *__restrict));
393
FILE *	_EXFUN(_freopen_r, (struct _reent *, const char *__restrict, const char *__restrict, FILE *__restrict));
394
int	_EXFUN(_fprintf_r, (struct _reent *, FILE *__restrict, const char *__restrict, ...)
4349 Serge 395
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
396
int	_EXFUN(_fpurge_r, (struct _reent *, FILE *));
397
int	_EXFUN(_fputc_r, (struct _reent *, int, FILE *));
6099 serge 398
int	_EXFUN(_fputc_unlocked_r, (struct _reent *, int, FILE *));
4921 Serge 399
int	_EXFUN(_fputs_r, (struct _reent *, const char *__restrict, FILE *__restrict));
6099 serge 400
int	_EXFUN(_fputs_unlocked_r, (struct _reent *, const char *__restrict, FILE *__restrict));
4921 Serge 401
size_t	_EXFUN(_fread_r, (struct _reent *, _PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
6099 serge 402
size_t	_EXFUN(_fread_unlocked_r, (struct _reent *, _PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
4921 Serge 403
int	_EXFUN(_fscanf_r, (struct _reent *, FILE *__restrict, const char *__restrict, ...)
4349 Serge 404
               _ATTRIBUTE ((__format__ (__scanf__, 3, 4))));
405
int	_EXFUN(_fseek_r, (struct _reent *, FILE *, long, int));
406
int	_EXFUN(_fseeko_r,(struct _reent *, FILE *, _off_t, int));
407
long	_EXFUN(_ftell_r, (struct _reent *, FILE *));
408
_off_t	_EXFUN(_ftello_r,(struct _reent *, FILE *));
409
void	_EXFUN(_rewind_r, (struct _reent *, FILE *));
4921 Serge 410
size_t	_EXFUN(_fwrite_r, (struct _reent *, const _PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
6099 serge 411
size_t	_EXFUN(_fwrite_unlocked_r, (struct _reent *, const _PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
4349 Serge 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 *));
4921 Serge 423
int	_EXFUN(_printf_r, (struct _reent *, const char *__restrict, ...)
4349 Serge 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));
4921 Serge 433
int	_EXFUN(_scanf_r, (struct _reent *, const char *__restrict, ...)
4349 Serge 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))));
4921 Serge 441
int	_EXFUN(_snprintf_r, (struct _reent *, char *__restrict, size_t, const char *__restrict, ...)
4349 Serge 442
               _ATTRIBUTE ((__format__ (__printf__, 4, 5))));
4921 Serge 443
int	_EXFUN(_sprintf_r, (struct _reent *, char *__restrict, const char *__restrict, ...)
4349 Serge 444
               _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
4921 Serge 445
int	_EXFUN(_sscanf_r, (struct _reent *, const char *__restrict, const char *__restrict, ...)
4349 Serge 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))));
4921 Serge 461
int	_EXFUN(_vdprintf_r, (struct _reent *, int, const char *__restrict, __VALIST)
4349 Serge 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))));
4921 Serge 467
int	_EXFUN(_vfprintf_r, (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
4349 Serge 468
               _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
4921 Serge 469
int	_EXFUN(_vfscanf_r, (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
4349 Serge 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))));
4921 Serge 475
int	_EXFUN(_vprintf_r, (struct _reent *, const char *__restrict, __VALIST)
4349 Serge 476
               _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
4921 Serge 477
int	_EXFUN(_vscanf_r, (struct _reent *, const char *__restrict, __VALIST)
4349 Serge 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))));
4921 Serge 485
int	_EXFUN(_vsnprintf_r, (struct _reent *, char *__restrict, size_t, const char *__restrict, __VALIST)
4349 Serge 486
               _ATTRIBUTE ((__format__ (__printf__, 4, 0))));
4921 Serge 487
int	_EXFUN(_vsprintf_r, (struct _reent *, char *__restrict, const char *__restrict, __VALIST)
4349 Serge 488
               _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
4921 Serge 489
int	_EXFUN(_vsscanf_r, (struct _reent *, const char *__restrict, const char *__restrict, __VALIST)
4349 Serge 490
               _ATTRIBUTE ((__format__ (__scanf__, 3, 0))));
491
 
492
/* Other extensions.  */
493
 
494
int	_EXFUN(fpurge, (FILE *));
495
ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *));
496
ssize_t _EXFUN(__getline, (char **, size_t *, FILE *));
497
 
6099 serge 498
#if __BSD_VISIBLE
499
void	_EXFUN(clearerr_unlocked, (FILE *));
500
int	_EXFUN(feof_unlocked, (FILE *));
501
int	_EXFUN(ferror_unlocked, (FILE *));
502
int	_EXFUN(fileno_unlocked, (FILE *));
503
int	_EXFUN(fflush_unlocked, (FILE *));
504
int	_EXFUN(fgetc_unlocked, (FILE *));
505
int	_EXFUN(fputc_unlocked, (int, FILE *));
506
size_t	_EXFUN(fread_unlocked, (_PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
507
size_t	_EXFUN(fwrite_unlocked, (const _PTR __restrict , size_t _size, size_t _n, FILE *));
508
#endif
509
 
510
#if __GNU_VISIBLE
511
char *  _EXFUN(fgets_unlocked, (char *__restrict, int, FILE *__restrict));
512
int	_EXFUN(fputs_unlocked, (const char *__restrict, FILE *__restrict));
513
#endif
514
 
4349 Serge 515
#ifdef __LARGE64_FILES
516
#if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB)
517
FILE *	_EXFUN(fdopen64, (int, const char *));
518
FILE *  _EXFUN(fopen64, (const char *, const char *));
519
FILE *  _EXFUN(freopen64, (_CONST char *, _CONST char *, FILE *));
520
_off64_t _EXFUN(ftello64, (FILE *));
521
_off64_t _EXFUN(fseeko64, (FILE *, _off64_t, int));
522
int     _EXFUN(fgetpos64, (FILE *, _fpos64_t *));
523
int     _EXFUN(fsetpos64, (FILE *, const _fpos64_t *));
524
FILE *  _EXFUN(tmpfile64, (void));
525
 
526
FILE *	_EXFUN(_fdopen64_r, (struct _reent *, int, const char *));
527
FILE *  _EXFUN(_fopen64_r, (struct _reent *,const char *, const char *));
528
FILE *  _EXFUN(_freopen64_r, (struct _reent *, _CONST char *, _CONST char *, FILE *));
529
_off64_t _EXFUN(_ftello64_r, (struct _reent *, FILE *));
530
_off64_t _EXFUN(_fseeko64_r, (struct _reent *, FILE *, _off64_t, int));
531
int     _EXFUN(_fgetpos64_r, (struct _reent *, FILE *, _fpos64_t *));
532
int     _EXFUN(_fsetpos64_r, (struct _reent *, FILE *, const _fpos64_t *));
533
FILE *  _EXFUN(_tmpfile64_r, (struct _reent *));
534
#endif /* !__CYGWIN__ */
535
#endif /* __LARGE64_FILES */
536
 
537
/*
538
 * Routines internal to the implementation.
539
 */
540
 
541
int	_EXFUN(__srget_r, (struct _reent *, FILE *));
542
int	_EXFUN(__swbuf_r, (struct _reent *, int, FILE *));
543
 
544
/*
545
 * Stdio function-access interface.
546
 */
547
 
548
#ifndef __STRICT_ANSI__
549
# ifdef __LARGE64_FILES
550
FILE	*_EXFUN(funopen,(const _PTR __cookie,
4921 Serge 551
		int (*__readfn)(_PTR __c, char *__buf,
552
				_READ_WRITE_BUFSIZE_TYPE __n),
553
		int (*__writefn)(_PTR __c, const char *__buf,
554
				 _READ_WRITE_BUFSIZE_TYPE __n),
4349 Serge 555
		_fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence),
556
		int (*__closefn)(_PTR __c)));
557
FILE	*_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie,
4921 Serge 558
		int (*__readfn)(_PTR __c, char *__buf,
559
				_READ_WRITE_BUFSIZE_TYPE __n),
560
		int (*__writefn)(_PTR __c, const char *__buf,
561
				 _READ_WRITE_BUFSIZE_TYPE __n),
4349 Serge 562
		_fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence),
563
		int (*__closefn)(_PTR __c)));
564
# else
565
FILE	*_EXFUN(funopen,(const _PTR __cookie,
4921 Serge 566
		int (*__readfn)(_PTR __cookie, char *__buf,
567
				_READ_WRITE_BUFSIZE_TYPE __n),
568
		int (*__writefn)(_PTR __cookie, const char *__buf,
569
				 _READ_WRITE_BUFSIZE_TYPE __n),
4349 Serge 570
		fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence),
571
		int (*__closefn)(_PTR __cookie)));
572
FILE	*_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie,
4921 Serge 573
		int (*__readfn)(_PTR __cookie, char *__buf,
574
				_READ_WRITE_BUFSIZE_TYPE __n),
575
		int (*__writefn)(_PTR __cookie, const char *__buf,
576
				 _READ_WRITE_BUFSIZE_TYPE __n),
4349 Serge 577
		fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence),
578
		int (*__closefn)(_PTR __cookie)));
579
# endif /* !__LARGE64_FILES */
580
 
581
# define	fropen(__cookie, __fn) funopen(__cookie, __fn, (int (*)())0, \
582
					       (fpos_t (*)())0, (int (*)())0)
583
# define	fwopen(__cookie, __fn) funopen(__cookie, (int (*)())0, __fn, \
584
					       (fpos_t (*)())0, (int (*)())0)
585
 
586
typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
587
typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
588
					size_t __n);
589
# ifdef __LARGE64_FILES
590
typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,
591
				   int __whence);
592
# else
593
typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);
594
# endif /* !__LARGE64_FILES */
595
typedef int cookie_close_function_t(void *__cookie);
596
typedef struct
597
{
598
  /* These four struct member names are dictated by Linux; hopefully,
599
     they don't conflict with any macros.  */
600
  cookie_read_function_t  *read;
601
  cookie_write_function_t *write;
602
  cookie_seek_function_t  *seek;
603
  cookie_close_function_t *close;
604
} cookie_io_functions_t;
605
FILE *_EXFUN(fopencookie,(void *__cookie,
606
		const char *__mode, cookie_io_functions_t __functions));
607
FILE *_EXFUN(_fopencookie_r,(struct _reent *, void *__cookie,
608
		const char *__mode, cookie_io_functions_t __functions));
609
#endif /* ! __STRICT_ANSI__ */
610
 
611
#ifndef __CUSTOM_FILE_IO__
612
/*
6099 serge 613
 * The __sfoo macros are here so that we can
4349 Serge 614
 * define function versions in the C library.
615
 */
616
#define       __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++))
617
 
618
#ifdef __SCLE
619
/*  For a platform with CR/LF, additional logic is required by
620
  __sgetc_r which would otherwise simply be a macro; therefore we
621
  use an inlined function.  The function is only meant to be inlined
6099 serge 622
  in place as used and the function body should never be emitted.
4349 Serge 623
 
624
  There are two possible means to this end when compiling with GCC,
625
  one when compiling with a standard C99 compiler, and for other
626
  compilers we're just stuck.  At the moment, this issue only
627
  affects the Cygwin target, so we'll most likely be using GCC. */
628
 
629
_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p);
630
 
631
_ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p)
632
  {
633
    int __c = __sgetc_raw_r(__ptr, __p);
634
    if ((__p->_flags & __SCLE) && (__c == '\r'))
635
      {
636
      int __c2 = __sgetc_raw_r(__ptr, __p);
637
      if (__c2 == '\n')
638
        __c = __c2;
639
      else
640
        ungetc(__c2, __p);
641
      }
642
    return __c;
643
  }
644
#else
645
#define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
646
#endif
647
 
648
#ifdef _never /* __GNUC__ */
649
/* If this inline is actually used, then systems using coff debugging
650
   info get hopelessly confused.  21sept93 rich@cygnus.com.  */
651
_ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
652
	if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
653
		return (*_p->_p++ = _c);
654
	else
655
		return (__swbuf_r(_ptr, _c, _p));
656
}
657
#else
658
/*
659
 * This has been tuned to generate reasonable code on the vax using pcc
660
 */
661
#define       __sputc_raw_r(__ptr, __c, __p) \
662
	(--(__p)->_w < 0 ? \
663
		(__p)->_w >= (__p)->_lbfsize ? \
664
			(*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \
665
				(int)*(__p)->_p++ : \
666
				__swbuf_r(__ptr, '\n', __p) : \
667
			__swbuf_r(__ptr, (int)(__c), __p) : \
668
		(*(__p)->_p = (__c), (int)*(__p)->_p++))
669
#ifdef __SCLE
670
#define __sputc_r(__ptr, __c, __p) \
671
        ((((__p)->_flags & __SCLE) && ((__c) == '\n')) \
672
          ? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \
673
        __sputc_raw_r((__ptr), (__c), (__p)))
674
#else
675
#define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p)
676
#endif
677
#endif
678
 
6099 serge 679
#define	__sfeof(p)	((int)(((p)->_flags & __SEOF) != 0))
680
#define	__sferror(p)	((int)(((p)->_flags & __SERR) != 0))
4349 Serge 681
#define	__sclearerr(p)	((void)((p)->_flags &= ~(__SERR|__SEOF)))
682
#define	__sfileno(p)	((p)->_file)
683
 
684
#ifndef _REENT_SMALL
685
#define	feof(p)		__sfeof(p)
686
#define	ferror(p)	__sferror(p)
687
#define	clearerr(p)	__sclearerr(p)
6099 serge 688
 
689
#if __BSD_VISIBLE
690
#define	feof_unlocked(p)	__sfeof(p)
691
#define	ferror_unlocked(p)	__sferror(p)
692
#define	clearerr_unlocked(p)	__sclearerr(p)
693
#endif /* __BSD_VISIBLE */
694
#endif /* _REENT_SMALL */
695
 
696
#if 0 /*ndef __STRICT_ANSI__ - FIXME: must initialize stdio first, use fn */
697
#define	fileno(p)	__sfileno(p)
4349 Serge 698
#endif
699
 
700
#ifndef __CYGWIN__
701
#ifndef lint
702
#define	getc(fp)	__sgetc_r(_REENT, fp)
703
#define putc(x, fp)	__sputc_r(_REENT, x, fp)
704
#endif /* lint */
705
#endif /* __CYGWIN__ */
706
 
707
#ifndef __STRICT_ANSI__
708
/* fast always-buffered version, true iff error */
709
#define	fast_putc(x,p) (--(p)->_w < 0 ? \
710
	__swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
711
 
712
#define	L_cuserid	9		/* posix says it goes in stdio.h :( */
713
#ifdef __CYGWIN__
714
#define L_ctermid       16
715
#endif
716
#endif
717
 
718
#endif /* !__CUSTOM_FILE_IO__ */
719
 
720
#define	getchar()	getc(stdin)
721
#define	putchar(x)	putc(x, stdout)
722
 
6099 serge 723
#ifndef __STRICT_ANSI__
724
#define	getchar_unlocked()	getc_unlocked(stdin)
725
#define	putchar_unlocked(x)	putc_unlocked(x, stdout)
726
#endif
727
 
4349 Serge 728
_END_STD_C
729
 
730
#endif /* _STDIO_H_ */