PSP2SDK  dirty-f9e4f2d
The free SDK for PSP2
include/stdio.h
00001 /*
00002  * Copyright (C) 2015 PSP2SDK Project
00003  *
00004  * This Source Code Form is subject to the terms of the Mozilla Public
00005  * License, v. 2.0. If a copy of the MPL was not distributed with this
00006  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00007  *
00008  * This file is modified for PSP2 by PSP2SDK Team
00009  *
00010  * Copyright (c) 1990 The Regents of the University of California.
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms are permitted
00014  * provided that the above copyright notice and this paragraph are
00015  * duplicated in all such forms and that any documentation,
00016  * advertising materials, and other materials related to such
00017  * distribution and use acknowledge that the software was developed
00018  * by the University of California, Berkeley.  The name of the
00019  * University may not be used to endorse or promote products derived
00020  * from this software without specific prior written permission.
00021  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
00022  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
00023  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00024  *
00025  *  @(#)stdio.h 5.3 (Berkeley) 3/15/86
00026  */
00027 
00028 /*
00029  * NB: to fit things in six character monocase externals, the
00030  * stdio code uses the prefix `__s' for stdio objects, typically
00031  * followed by a three-character attempt at a mnemonic.
00032  */
00033 
00034 #ifndef _STDIO_H_
00035 #define _STDIO_H_
00036 
00037 #include "_ansi.h"
00038 
00039 #define _FSTDIO         /* ``function stdio'' */
00040 
00041 #define __need_size_t
00042 #define __need_NULL
00043 #include <sys/cdefs.h>
00044 #include <stddef.h>
00045 
00046 #define __need___va_list
00047 #include <stdarg.h>
00048 
00049 #include <sys/types.h>
00050 
00051 _BEGIN_STD_C
00052 
00053 typedef struct __FILE FILE;
00054 
00055 #ifdef __CYGWIN__
00056 typedef _fpos64_t fpos_t;
00057 #else
00058 typedef _fpos_t fpos_t;
00059 #ifdef __LARGE64_FILES
00060 typedef _fpos64_t fpos64_t;
00061 #endif
00062 #endif /* !__CYGWIN__ */
00063 
00064 #include <sys/stdio.h>
00065 
00066 #define __SLBF  0x0001      /* line buffered */
00067 #define __SNBF  0x0002      /* unbuffered */
00068 #define __SRD   0x0004      /* OK to read */
00069 #define __SWR   0x0008      /* OK to write */
00070     /* RD and WR are never simultaneously asserted */
00071 #define __SRW   0x0010      /* open for reading & writing */
00072 #define __SEOF  0x0020      /* found EOF */
00073 #define __SERR  0x0040      /* found error */
00074 #define __SMBF  0x0080      /* _buf is from malloc */
00075 #define __SAPP  0x0100      /* fdopen()ed in append mode - so must  write to end */
00076 #define __SSTR  0x0200      /* this is an sprintf/snprintf string */
00077 #define __SOPT  0x0400      /* do fseek() optimisation */
00078 #define __SNPT  0x0800      /* do not do fseek() optimisation */
00079 #define __SOFF  0x1000      /* set iff _offset is in fact correct */
00080 #define __SORD  0x2000      /* true => stream orientation (byte/wide) decided */
00081 #if defined(__CYGWIN__)
00082 #  define __SCLE  0x4000        /* convert line endings CR/LF <-> NL */
00083 #endif
00084 #define __SL64  0x8000      /* is 64-bit offset large file */
00085 
00086 /* _flags2 flags */
00087 #define __SNLK  0x0001      /* stdio functions do not lock streams themselves */
00088 #define __SWID  0x2000      /* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */
00089 
00090 /*
00091  * The following three definitions are for ANSI C, which took them
00092  * from System V, which stupidly took internal interface macros and
00093  * made them official arguments to setvbuf(), without renaming them.
00094  * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
00095  *
00096  * Although these happen to match their counterparts above, the
00097  * implementation does not rely on that (so these could be renumbered).
00098  */
00099 #define _IOFBF  0       /* setvbuf should set fully buffered */
00100 #define _IOLBF  1       /* setvbuf should set line buffered */
00101 #define _IONBF  2       /* setvbuf should set unbuffered */
00102 
00103 #define EOF (-1)
00104 
00105 #ifdef __BUFSIZ__
00106 #define BUFSIZ      __BUFSIZ__
00107 #else
00108 #define BUFSIZ      1024
00109 #endif
00110 
00111 #ifdef __FOPEN_MAX__
00112 #define FOPEN_MAX   __FOPEN_MAX__
00113 #else
00114 #define FOPEN_MAX   20
00115 #endif
00116 
00117 #ifdef __FILENAME_MAX__
00118 #define FILENAME_MAX    __FILENAME_MAX__
00119 #else
00120 #define FILENAME_MAX    1024
00121 #endif
00122 
00123 #ifdef __L_tmpnam__
00124 #define L_tmpnam    __L_tmpnam__
00125 #else
00126 #define L_tmpnam    FILENAME_MAX
00127 #endif
00128 
00129 #ifndef __STRICT_ANSI__
00130 #define P_tmpdir        "/tmp"
00131 #endif
00132 
00133 #ifndef SEEK_SET
00134 #define SEEK_SET    0   /* set file offset to offset */
00135 #endif
00136 #ifndef SEEK_CUR
00137 #define SEEK_CUR    1   /* set file offset to current plus offset */
00138 #endif
00139 #ifndef SEEK_END
00140 #define SEEK_END    2   /* set file offset to EOF plus offset */
00141 #endif
00142 
00143 #define TMP_MAX     26
00144 
00145 extern FILE _Stdin, _Stdout, _Stderr;
00146 
00147 #define stdin   (&_Stdin)
00148 #define stdout  (&_Stdout)
00149 #define stderr  (&_Stderr)
00150 
00151 #define _stdin_r(x) (stdin)
00152 #define _stdout_r(x)    (stdout)
00153 #define _stderr_r(x)    (stderr)
00154 
00155 /*
00156  * Functions defined in ANSI C standard.
00157  */
00158 
00159 #ifndef __VALIST
00160 #ifdef __GNUC__
00161 #define __VALIST __gnuc_va_list
00162 #else
00163 #define __VALIST char*
00164 #endif
00165 #endif
00166 
00167 FILE *  _EXFUN(tmpfile, (void));
00168 char *  _EXFUN(tmpnam, (char *));
00169 #if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
00170 char *  _EXFUN(tempnam, (const char *, const char *));
00171 #endif
00172 int _EXFUN(fclose, (FILE *));
00173 int _EXFUN(fflush, (FILE *));
00174 FILE *  _EXFUN(freopen, (const char *__restrict, const char *__restrict, FILE *__restrict));
00175 void    _EXFUN(setbuf, (FILE *__restrict, char *__restrict));
00176 int _EXFUN(setvbuf, (FILE *__restrict, char *__restrict, int, size_t));
00177 int _EXFUN(fprintf, (FILE *__restrict, const char *__restrict, ...)
00178                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
00179 int _EXFUN(fscanf, (FILE *__restrict, const char *__restrict, ...)
00180                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
00181 int _EXFUN(printf, (const char *__restrict, ...)
00182                _ATTRIBUTE ((__format__ (__printf__, 1, 2))));
00183 int _EXFUN(scanf, (const char *__restrict, ...)
00184                _ATTRIBUTE ((__format__ (__scanf__, 1, 2))));
00185 int _EXFUN(sscanf, (const char *__restrict, const char *__restrict, ...)
00186                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
00187 int _EXFUN(vfprintf, (FILE *__restrict, const char *__restrict, __VALIST)
00188                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
00189 int _EXFUN(vprintf, (const char *, __VALIST)
00190                _ATTRIBUTE ((__format__ (__printf__, 1, 0))));
00191 int _EXFUN(vsprintf, (char *__restrict, const char *__restrict, __VALIST)
00192                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
00193 int _EXFUN(fgetc, (FILE *));
00194 char *  _EXFUN(fgets, (char *__restrict, int, FILE *__restrict));
00195 int _EXFUN(fputc, (int, FILE *));
00196 int _EXFUN(fputs, (const char *__restrict, FILE *__restrict));
00197 int _EXFUN(getc, (FILE *));
00198 int _EXFUN(getchar, (void));
00199 char *  _EXFUN(gets, (char *));
00200 int _EXFUN(putc, (int, FILE *));
00201 int _EXFUN(putchar, (int));
00202 int _EXFUN(puts, (const char *));
00203 int _EXFUN(ungetc, (int, FILE *));
00204 size_t  _EXFUN(fread, (_PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
00205 size_t  _EXFUN(fwrite, (const _PTR __restrict , size_t _size, size_t _n, FILE *));
00206 #ifdef _COMPILING_NEWLIB
00207 int _EXFUN(fgetpos, (FILE *, _fpos_t *));
00208 #else
00209 int _EXFUN(fgetpos, (FILE *__restrict, fpos_t *__restrict));
00210 #endif
00211 int _EXFUN(fseek, (FILE *, long, int));
00212 #ifdef _COMPILING_NEWLIB
00213 int _EXFUN(fsetpos, (FILE *, const _fpos_t *));
00214 #else
00215 int _EXFUN(fsetpos, (FILE *, const fpos_t *));
00216 #endif
00217 long    _EXFUN(ftell, ( FILE *));
00218 void    _EXFUN(rewind, (FILE *));
00219 void    _EXFUN(clearerr, (FILE *));
00220 int _EXFUN(feof, (FILE *));
00221 int _EXFUN(ferror, (FILE *));
00222 void    _EXFUN(perror, (const char *));
00223 #ifndef _REENT_ONLY
00224 FILE *  _EXFUN(fopen, (const char *__restrict _name, const char *__restrict _type));
00225 int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
00226                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
00227 int _EXFUN(remove, (const char *));
00228 int _EXFUN(rename, (const char *, const char *));
00229 #ifdef _COMPILING_NEWLIB
00230 int _EXFUN(_rename, (const char *, const char *));
00231 #endif
00232 #endif
00233 #if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K)
00234 #ifdef _COMPILING_NEWLIB
00235 int _EXFUN(fseeko, (FILE *, _off_t, int));
00236 _off_t  _EXFUN(ftello, ( FILE *));
00237 #else
00238 int _EXFUN(fseeko, (FILE *, off_t, int));
00239 off_t   _EXFUN(ftello, ( FILE *));
00240 #endif
00241 #endif
00242 #if __GNU_VISIBLE
00243 int _EXFUN(fcloseall, (_VOID));
00244 #endif
00245 #if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
00246 #ifndef _REENT_ONLY
00247 int _EXFUN(asiprintf, (char **, const char *, ...)
00248                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
00249 char *  _EXFUN(asniprintf, (char *, size_t *, const char *, ...)
00250                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
00251 char *  _EXFUN(asnprintf, (char *__restrict, size_t *__restrict, const char *__restrict, ...)
00252                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
00253 int _EXFUN(asprintf, (char **__restrict, const char *__restrict, ...)
00254                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
00255 #ifndef diprintf
00256 int _EXFUN(diprintf, (int, const char *, ...)
00257                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
00258 #endif
00259 int _EXFUN(fiprintf, (FILE *, const char *, ...)
00260                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
00261 int _EXFUN(fiscanf, (FILE *, const char *, ...)
00262                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
00263 int _EXFUN(iprintf, (const char *, ...)
00264                _ATTRIBUTE ((__format__ (__printf__, 1, 2))));
00265 int _EXFUN(iscanf, (const char *, ...)
00266                _ATTRIBUTE ((__format__ (__scanf__, 1, 2))));
00267 int _EXFUN(siprintf, (char *, const char *, ...)
00268                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
00269 int _EXFUN(siscanf, (const char *, const char *, ...)
00270                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
00271 int _EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...)
00272                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
00273 int _EXFUN(sniprintf, (char *, size_t, const char *, ...)
00274                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
00275 int _EXFUN(vasiprintf, (char **, const char *, __VALIST)
00276                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
00277 char *  _EXFUN(vasniprintf, (char *, size_t *, const char *, __VALIST)
00278                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
00279 char *  _EXFUN(vasnprintf, (char *, size_t *, const char *, __VALIST)
00280                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
00281 int _EXFUN(vasprintf, (char **, const char *, __VALIST)
00282                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
00283 int _EXFUN(vdiprintf, (int, const char *, __VALIST)
00284                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
00285 int _EXFUN(vfiprintf, (FILE *, const char *, __VALIST)
00286                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
00287 int _EXFUN(vfiscanf, (FILE *, const char *, __VALIST)
00288                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
00289 int _EXFUN(vfscanf, (FILE *__restrict, const char *__restrict, __VALIST)
00290                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
00291 int _EXFUN(viprintf, (const char *, __VALIST)
00292                _ATTRIBUTE ((__format__ (__printf__, 1, 0))));
00293 int _EXFUN(viscanf, (const char *, __VALIST)
00294                _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
00295 int _EXFUN(vscanf, (const char *, __VALIST)
00296                _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
00297 int _EXFUN(vsiprintf, (char *, const char *, __VALIST)
00298                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
00299 int _EXFUN(vsiscanf, (const char *, const char *, __VALIST)
00300                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
00301 int _EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST)
00302                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
00303 int _EXFUN(vsnprintf, (char *__restrict, size_t, const char *__restrict, __VALIST)
00304                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
00305 int _EXFUN(vsscanf, (const char *__restrict, const char *__restrict, __VALIST)
00306                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
00307 #endif /* !_REENT_ONLY */
00308 #endif /* !__STRICT_ANSI__ */
00309 
00310 /*
00311  * Routines in POSIX 1003.1:2001.
00312  */
00313 
00314 #ifndef __STRICT_ANSI__
00315 #ifndef _REENT_ONLY
00316 FILE *  _EXFUN(fdopen, (int, const char *));
00317 #endif
00318 int _EXFUN(fileno, (FILE *));
00319 int _EXFUN(getw, (FILE *));
00320 int _EXFUN(pclose, (FILE *));
00321 FILE *  _EXFUN(popen, (const char *, const char *));
00322 int _EXFUN(putw, (int, FILE *));
00323 void    _EXFUN(setbuffer, (FILE *, char *, int));
00324 int _EXFUN(setlinebuf, (FILE *));
00325 int _EXFUN(getc_unlocked, (FILE *));
00326 int _EXFUN(getchar_unlocked, (void));
00327 void    _EXFUN(flockfile, (FILE *));
00328 int _EXFUN(ftrylockfile, (FILE *));
00329 void    _EXFUN(funlockfile, (FILE *));
00330 int _EXFUN(putc_unlocked, (int, FILE *));
00331 int _EXFUN(putchar_unlocked, (int));
00332 #endif /* ! __STRICT_ANSI__ */
00333 
00334 /*
00335  * Routines in POSIX 1003.1:200x.
00336  */
00337 
00338 #ifndef __STRICT_ANSI__
00339 # ifndef _REENT_ONLY
00340 #  ifndef dprintf
00341 int _EXFUN(dprintf, (int, const char *__restrict, ...)
00342                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
00343 #  endif
00344 FILE *  _EXFUN(fmemopen, (void *__restrict, size_t, const char *__restrict));
00345 /* getdelim - see __getdelim for now */
00346 /* getline - see __getline for now */
00347 FILE *  _EXFUN(open_memstream, (char **, size_t *));
00348 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
00349 int _EXFUN(renameat, (int, const char *, int, const char *));
00350 #endif
00351 int _EXFUN(vdprintf, (int, const char *__restrict, __VALIST)
00352                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
00353 # endif
00354 #endif
00355 
00356 /* Other extensions.  */
00357 
00358 int _EXFUN(fpurge, (FILE *));
00359 ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *));
00360 ssize_t _EXFUN(__getline, (char **, size_t *, FILE *));
00361 
00362 #if __BSD_VISIBLE
00363 void    _EXFUN(clearerr_unlocked, (FILE *));
00364 int _EXFUN(feof_unlocked, (FILE *));
00365 int _EXFUN(ferror_unlocked, (FILE *));
00366 int _EXFUN(fileno_unlocked, (FILE *));
00367 int _EXFUN(fflush_unlocked, (FILE *));
00368 int _EXFUN(fgetc_unlocked, (FILE *));
00369 int _EXFUN(fputc_unlocked, (int, FILE *));
00370 size_t  _EXFUN(fread_unlocked, (_PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
00371 size_t  _EXFUN(fwrite_unlocked, (const _PTR __restrict , size_t _size, size_t _n, FILE *));
00372 #endif
00373 
00374 #if __GNU_VISIBLE
00375 char *  _EXFUN(fgets_unlocked, (char *__restrict, int, FILE *__restrict));
00376 int _EXFUN(fputs_unlocked, (const char *__restrict, FILE *__restrict));
00377 #endif
00378 
00379 #ifdef __LARGE64_FILES
00380 #if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB)
00381 FILE *  _EXFUN(fdopen64, (int, const char *));
00382 FILE *  _EXFUN(fopen64, (const char *, const char *));
00383 FILE *  _EXFUN(freopen64, (_CONST char *, _CONST char *, FILE *));
00384 _off64_t _EXFUN(ftello64, (FILE *));
00385 _off64_t _EXFUN(fseeko64, (FILE *, _off64_t, int));
00386 int     _EXFUN(fgetpos64, (FILE *, _fpos64_t *));
00387 int     _EXFUN(fsetpos64, (FILE *, const _fpos64_t *));
00388 FILE *  _EXFUN(tmpfile64, (void));
00389 #endif /* !__CYGWIN__ */
00390 #endif /* __LARGE64_FILES */
00391 
00392 /*
00393  * Stdio function-access interface.
00394  */
00395 
00396 #ifndef __STRICT_ANSI__
00397 # ifdef __LARGE64_FILES
00398 FILE    *_EXFUN(funopen,(const _PTR __cookie,
00399         int (*__readfn)(_PTR __c, char *__buf,
00400                 _READ_WRITE_BUFSIZE_TYPE __n),
00401         int (*__writefn)(_PTR __c, const char *__buf,
00402                  _READ_WRITE_BUFSIZE_TYPE __n),
00403         _fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence),
00404         int (*__closefn)(_PTR __c)));
00405 # else
00406 FILE    *_EXFUN(funopen,(const _PTR __cookie,
00407         int (*__readfn)(_PTR __cookie, char *__buf,
00408                 _READ_WRITE_BUFSIZE_TYPE __n),
00409         int (*__writefn)(_PTR __cookie, const char *__buf,
00410                  _READ_WRITE_BUFSIZE_TYPE __n),
00411         fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence),
00412         int (*__closefn)(_PTR __cookie)));
00413 # endif /* !__LARGE64_FILES */
00414 
00415 # define    fropen(__cookie, __fn) funopen(__cookie, __fn, (int (*)())0, \
00416                            (fpos_t (*)())0, (int (*)())0)
00417 # define    fwopen(__cookie, __fn) funopen(__cookie, (int (*)())0, __fn, \
00418                            (fpos_t (*)())0, (int (*)())0)
00419 
00420 typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
00421 typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
00422                     size_t __n);
00423 # ifdef __LARGE64_FILES
00424 typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,
00425                    int __whence);
00426 # else
00427 typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);
00428 # endif /* !__LARGE64_FILES */
00429 typedef int cookie_close_function_t(void *__cookie);
00430 typedef struct
00431 {
00432   /* These four struct member names are dictated by Linux; hopefully,
00433      they don't conflict with any macros.  */
00434   cookie_read_function_t  *read;
00435   cookie_write_function_t *write;
00436   cookie_seek_function_t  *seek;
00437   cookie_close_function_t *close;
00438 } cookie_io_functions_t;
00439 FILE *_EXFUN(fopencookie,(void *__cookie,
00440         const char *__mode, cookie_io_functions_t __functions));
00441 #endif /* ! __STRICT_ANSI__ */
00442 
00443 #define getchar()   getc(stdin)
00444 #define putchar(x)  putc(x, stdout)
00445 
00446 #ifndef __STRICT_ANSI__
00447 #define getchar_unlocked()  getc_unlocked(stdin)
00448 #define putchar_unlocked(x) putc_unlocked(x, stdout)
00449 #endif
00450 
00451 _END_STD_C
00452 
00453 #endif /* _STDIO_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines