Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
3 * © Portions copyright (c) 2006 Symbian Software Ltd. All rights reserved.
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)stdio.h 8.5 (Berkeley) 4/29/95
35 * $FreeBSD: src/include/stdio.h,v 1.56 2004/06/20 10:01:30 tjr Exp $
36 * © Portions copyright (c) 2005-2006 Nokia Corporation. All rights reserved.
37 * © Portions copyright (c) 2007-2008 Symbian Software Ltd. All rights reserved.
47 #include <sys/cdefs.h>
48 #include <sys/_null.h>
49 #include <sys/_types.h>
54 #include <sys/types.h>
59 typedef __off_t fpos_t;
61 #ifndef _SIZE_T_DECLARED
62 typedef __size_t size_t;
63 #define _SIZE_T_DECLARED
68 #if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE) && !__SYMBIAN32__
69 #ifndef _VA_LIST_DECLARED
70 typedef __va_list va_list;
71 #define va_list __e32_va_list
72 #define _VA_LIST_DECLARED
75 //#endif //__DOXYGEN__
79 #endif //__SYMBIAN32__
83 #define vfscanf __vfscanf
85 #ifndef _VA_COPY_DEFINED
86 #define va_copy(dst,src) (dst = src)
87 #define _VA_COPY_DEFINED
88 #endif //_VA_COPY_DEFINED
89 #endif // __SYMBIAN32__
90 #define _FSTDIO /* Define for new stdio with functions. */
93 * NB: to fit things in six character monocase externals, the stdio
94 * code uses the prefix `__s' for stdio objects, typically followed
95 * by a three-character attempt at a mnemonic.
100 unsigned char *_base;
104 /* hold a buncha junk that would grow the ABI */
108 * stdio state variables.
110 * The following always hold:
112 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
113 * _lbfsize is -_bf._size, else _lbfsize is 0
114 * if _flags&__SRD, _w is 0
115 * if _flags&__SWR, _r is 0
117 * This ensures that the getc and putc macros (or inline functions) never
118 * try to write or read from a file that is in `read' or `write' mode.
119 * (Moreover, they can, and do, automatically switch from read mode to
120 * write mode, and back, on "r+" and "w+" files.)
122 * _lbfsize is used only to make the inline line-buffered output stream
123 * code as compact as possible.
125 * _ub, _up, and _ur are used when ungetc() pushes back more characters
126 * than fit in the current _bf, or when ungetc() pushes back a character
127 * that does not match the previous one in _bf. When this happens,
128 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
129 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
131 typedef struct __sFILE {
132 unsigned char *_p; /* current position in (some) buffer */
133 int _r; /* read space left for getc() */
134 int _w; /* write space left for putc() */
135 short _flags; /* flags, below; this FILE is free if 0 */
136 short _file; /* fileno, if Unix descriptor, else -1 */
137 struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
138 int _lbfsize; /* 0 or -_bf._size, for inline putc */
141 void *_cookie; /* cookie passed to io functions */
142 int (*_close)(void *);
143 int (*_read)(void *, char *, int);
144 fpos_t (*_seek)(void *, fpos_t, int);
145 int (*_write)(void *, const char *, int);
147 /* separate buffer for long sequences of ungetc() */
148 struct __sbuf _ub; /* ungetc buffer */
149 struct __sFILEX *_extra; /* additions to FILE to not break ABI */
150 int _ur; /* saved _r when _r is counting ungetc data */
152 /* tricks to meet minimum requirements even when malloc() fails */
153 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
154 unsigned char _nbuf[1]; /* guarantee a getc() buffer */
156 /* separate buffer for fgetln() when line crosses buffer boundary */
157 struct __sbuf _lb; /* buffer for fgetln() */
159 /* Unix stdio files get aligned to block boundaries on fseek() */
160 int _blksize; /* stat.st_blksize (may be != _bf._size) */
161 fpos_t _offset; /* current lseek offset */
164 #ifndef _STDSTREAM_DECLARED
166 #if (!defined(__SYMBIAN32__) && (!defined(__WINSCW__) || !defined(__WINS__)))
167 extern FILE *__stdinp;
168 extern FILE *__stdoutp;
169 extern FILE *__stderrp;
172 #define _STDSTREAM_DECLARED
175 #define __SLBF 0x0001 /* line buffered */
176 #define __SNBF 0x0002 /* unbuffered */
177 #define __SRD 0x0004 /* OK to read */
178 #define __SWR 0x0008 /* OK to write */
179 /* RD and WR are never simultaneously asserted */
180 #define __SRW 0x0010 /* open for reading & writing */
181 #define __SEOF 0x0020 /* found EOF */
182 #define __SERR 0x0040 /* found error */
183 #define __SMBF 0x0080 /* _buf is from malloc */
184 #define __SAPP 0x0100 /* fdopen()ed in append mode */
185 #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
186 #define __SOPT 0x0400 /* do fseek() optimization */
187 #define __SNPT 0x0800 /* do not do fseek() optimization */
188 #define __SOFF 0x1000 /* set iff _offset is in fact correct */
189 #define __SMOD 0x2000 /* true => fgetln modified _p text */
190 #define __SALC 0x4000 /* allocate string space dynamically */
191 #define __SIGN 0x8000 /* ignore this file in _fwalk */
194 * The following three definitions are for ANSI C, which took them
195 * from System V, which brilliantly took internal interface macros and
196 * made them official arguments to setvbuf(), without renaming them.
197 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
199 * Although numbered as their counterparts above, the implementation
200 * does not rely on this.
202 #define _IOFBF 0 /* setvbuf should set fully buffered */
203 #define _IOLBF 1 /* setvbuf should set line buffered */
204 #define _IONBF 2 /* setvbuf should set unbuffered */
206 #define BUFSIZ 1024 /* size of buffer used by setbuf */
210 * FOPEN_MAX is a minimum maximum, and is the number of streams that
211 * stdio can provide without attempting to allocate further resources
212 * (which could fail). Do not use this for anything.
214 /* must be == _POSIX_STREAM_MAX <limits.h> */
215 #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
216 #ifndef __SYMBIAN32__
217 #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
219 #define FILENAME_MAX 256 /* must be <= PATH_MAX <sys/syslimits.h> */
220 #endif /* __SYMBIAN32__ */
222 /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
223 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
224 #define GET_WSD_VAR_NAME(var,varprefix) _##varprefix##_##var
225 char **GET_WSD_VAR_NAME(tmpdirptr, g)();
226 #define __tmpdirptr (*GET_WSD_VAR_NAME(tmpdirptr, g)())
228 extern char* __tmpdirptr;
232 #ifndef __SYMBIAN32__
233 #define P_tmpdir "/var/tmp/"
235 #define P_tmpdir (tmpdirname())
236 #define WIDEP_tmpdir (tmpdirname())
237 #endif //__SYMBIAN32__
239 #ifndef __SYMBIAN32__
240 #define L_tmpnam 1024 /* XXX must be == PATH_MAX */
242 #define L_tmpnam 256 /* XXX must be == PATH_MAX */
243 #endif /* __SYMBIAN32__ */
244 #define TMP_MAX 308915776
247 #define SEEK_SET 0 /* set file offset to offset */
250 #define SEEK_CUR 1 /* set file offset to current plus offset */
253 #define SEEK_END 2 /* set file offset to EOF plus offset */
256 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__)))
258 #define GET_WSD_VAR_NAME(var,varprefix) _##varprefix##_##var
260 FILE **GET_WSD_VAR_NAME(__stdinp, g)();
261 FILE **GET_WSD_VAR_NAME(__stdoutp, g)();
262 FILE **GET_WSD_VAR_NAME(__stderrp, g)();
264 #define __stdinp (*GET_WSD_VAR_NAME(__stdinp, g)())
265 #define __stdoutp (*GET_WSD_VAR_NAME(__stdoutp, g)())
266 #define __stderrp (*GET_WSD_VAR_NAME(__stderrp, g)())
269 #ifndef __SYMBIAN32__
270 #define stdin __stdinp
271 #define stdout __stdoutp
272 #define stderr __stderrp
275 IMPORT_C FILE *__stdin (void);
276 IMPORT_C FILE *__stdout (void);
277 IMPORT_C FILE *__stderr (void);
278 IMPORT_C char * tmpdirname(void);
280 #define stdin (__stdin())
281 #define stdout (__stdout())
282 #define stderr (__stderr())
287 * Functions defined in ANSI C standard.
289 IMPORT_C void clearerr(FILE *);
290 IMPORT_C int fclose(FILE *);
291 IMPORT_C int feof(FILE *);
292 IMPORT_C int ferror(FILE *);
293 IMPORT_C int fflush(FILE *);
294 IMPORT_C int fgetc(FILE *);
295 IMPORT_C int fgetpos(FILE * __restrict, fpos_t * __restrict);
296 IMPORT_C char *fgets(char * __restrict, int, FILE * __restrict);
297 IMPORT_C FILE *fopen(const char * __restrict, const char * __restrict);
298 IMPORT_C int fprintf(FILE * __restrict, const char * __restrict, ...);
299 IMPORT_C int fputc(int, FILE *);
300 IMPORT_C int fputs(const char * __restrict, FILE * __restrict);
301 IMPORT_C size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
302 IMPORT_C FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict);
303 IMPORT_C int fscanf(FILE * __restrict, const char * __restrict, ...);
304 IMPORT_C int fseek(FILE *, long, int);
305 IMPORT_C int fsetpos(FILE *, const fpos_t *);
306 IMPORT_C long ftell(FILE *);
307 IMPORT_C size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
308 IMPORT_C int getc(FILE *);
309 IMPORT_C int getchar(void);
310 IMPORT_C char *gets(char *);
311 IMPORT_C void perror(const char *);
312 IMPORT_C int printf(const char * __restrict, ...);
313 IMPORT_C int putc(int, FILE *);
314 IMPORT_C int putchar(int);
315 IMPORT_C int puts(const char *);
316 IMPORT_C int remove(const char *);
317 IMPORT_C int rename(const char *, const char *);
318 IMPORT_C void rewind(FILE *);
319 IMPORT_C int scanf(const char * __restrict, ...);
320 IMPORT_C void setbuf(FILE * __restrict, char * __restrict);
321 IMPORT_C int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
322 IMPORT_C int sprintf(char * __restrict, const char * __restrict, ...);
323 IMPORT_C int sscanf(const char * __restrict, const char * __restrict, ...);
324 IMPORT_C FILE *tmpfile(void);
325 IMPORT_C char *tmpnam(char *);
326 IMPORT_C int ungetc(int, FILE *);
327 IMPORT_C int vfprintf(FILE * __restrict, const char * __restrict,
329 IMPORT_C int vprintf(const char * __restrict, va_list);
330 IMPORT_C int vsprintf(char * __restrict, const char * __restrict,
333 #if __ISO_C_VISIBLE >= 1999
334 IMPORT_C int snprintf(char * __restrict, size_t, const char * __restrict,
335 ...) __printflike(3, 4);
336 IMPORT_C int vfscanf(FILE * __restrict, const char * __restrict, va_list)
338 IMPORT_C int vscanf(const char * __restrict, va_list) __scanflike(1, 0);
339 IMPORT_C int vsnprintf(char * __restrict, size_t, const char * __restrict,
340 va_list) __printflike(3, 0);
341 IMPORT_C int vsscanf(const char * __restrict, const char * __restrict, va_list)
346 * Functions defined in all versions of POSIX 1003.1.
348 #if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506
349 /* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */
350 #define L_cuserid 17 /* legacy */
354 #ifndef __SYMBIAN32__
355 #define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */
357 #define L_ctermid 256 /* size for ctermid(3); PATH_MAX */
358 #endif /* __SYMBIAN32__ */
359 IMPORT_C FILE *fdopen(int, const char *);
360 IMPORT_C int fileno(FILE *);
361 IMPORT_C int __sfileno(FILE* p);
362 #endif /* __POSIX_VISIBLE */
364 #if __POSIX_VISIBLE >= 199209
365 IMPORT_C int pclose(FILE *);
366 IMPORT_C FILE *popen(const char *, const char *);
370 IMPORT_C int popen3(const char *file, const char *cmd, char** envp, int fds[3]);
373 #if __POSIX_VISIBLE >= 199506
374 IMPORT_C int ftrylockfile(FILE *);
375 IMPORT_C void flockfile(FILE *);
376 IMPORT_C void funlockfile(FILE *);
379 * These are normally used through macros as defined below, but POSIX
380 * requires functions as well.
382 IMPORT_C int getc_unlocked(FILE *);
383 IMPORT_C int getchar_unlocked(void);
384 IMPORT_C int putc_unlocked(int, FILE *);
385 IMPORT_C int putchar_unlocked(int);
388 #if __POSIX_VISIBLE >= 200112
389 int fseeko(FILE *, __off_t, int);
390 __off_t ftello(FILE *);
393 #if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600
394 IMPORT_C int getw(FILE *);
395 IMPORT_C int putw(int, FILE *);
396 #endif /* BSD or X/Open before issue 6 */
399 IMPORT_C char *tempnam(const char *, const char *);
403 * Routines that are purely local.
406 IMPORT_C int asprintf(char **, const char *, ...) __printflike(2, 3);
407 #if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3
408 #define __ATTR_FORMAT_ARG __attribute__((__format_arg__(2)))
410 #define __ATTR_FORMAT_ARG
412 IMPORT_C void setbuffer(FILE *, char *, int);
413 IMPORT_C int setlinebuf(FILE *);
414 IMPORT_C int vasprintf(char **, const char *, va_list)
417 #ifndef __SYMBIAN32__
419 * The system error table contains messages for the first sys_nerr
420 * positive errno values. Use strerror() or strerror_r() from <string.h>
424 /* Provide the declarations for `sys_errlist' and `sys_nerr' if they
425 * are available on this system. Even if available, these variables
426 * should not be used directly. The `strerror' function provides
427 * all the necessary functionality.
430 extern __const int sys_nerr;
431 extern __const char *__const sys_errlist[];
432 #endif /* __SYMBIAN32__ */
435 * Portability hacks. See <sys/types.h>.
437 #ifndef _FTRUNCATE_DECLARED
438 #define _FTRUNCATE_DECLARED
439 IMPORT_C int ftruncate(int, __off_t);
441 #ifndef _LSEEK_DECLARED
442 #define _LSEEK_DECLARED
443 IMPORT_C __off_t lseek(int, __off_t, int);
445 #ifndef _MMAP_DECLARED
446 #define _MMAP_DECLARED
447 IMPORT_C void *mmap(void *, size_t, int, int, int, __off_t);
449 #ifndef _TRUNCATE_DECLARED
450 #define _TRUNCATE_DECLARED
451 IMPORT_C int truncate(const char *, __off_t);
453 #endif /* __BSD_VISIBLE */
456 IMPORT_C int setecho(int fd, uint8_t echoval);
460 * Functions internal to the implementation.
463 IMPORT_C int __srget(FILE *);
464 IMPORT_C int __swbuf(int, FILE *);
467 int __swbuf(int, FILE *);
468 #endif /*__SYMBIAN32__ */
471 * The __sfoo macros are here so that we can
472 * define function versions in the C library.
474 #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
475 #if defined(__GNUC__) && defined(__STDC__)
476 static __inline int __sputc(int _c, FILE *_p) {
477 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
478 return (*_p->_p++ = _c);
480 return (__swbuf(_c, _p));
484 * This has been tuned to generate reasonable code on the vax using pcc.
486 #define __sputc(c, p) \
488 (p)->_w >= (p)->_lbfsize ? \
489 (*(p)->_p = (c)), *(p)->_p != '\n' ? \
492 __swbuf((int)(c), p) : \
493 (*(p)->_p = (c), (int)*(p)->_p++))
496 #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
497 #define __sferror(p) (((p)->_flags & __SERR) != 0)
498 #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
500 #ifndef __SYMBIAN32__
501 extern int __isthreaded;
503 #define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p))
504 #define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p))
505 #define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p))
508 #define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p))
511 #define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp))
512 #define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
514 #define getchar() getc(stdin)
515 #define putchar(x) putc(x, stdout)
518 IMPORT_C int* isthreaded(void);
519 #define __isthreaded (*isthreaded())
521 #define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p))
522 #define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p))
523 #define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p))
526 #define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p))
529 #define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp))
530 #define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
532 #define getchar() getc(stdin)
533 #define putchar(x) putc(x, stdout)
534 #endif //__SYMBIAN32__
537 #if __POSIX_VISIBLE >= 199506
538 #ifndef __SYMBIAN32__
539 #define getc_unlocked(fp) __sgetc(fp)
540 #define putc_unlocked(x, fp) __sputc(x, fp)
542 #define getchar_unlocked() getc_unlocked(stdin)
543 #define putchar_unlocked(x) putc_unlocked(x, stdout)
554 #endif /* !_STDIO_H_ */