Subversion Repositories Kolibri OS

Rev

Rev 6536 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  *
  17.  *      @(#)stdio.h     5.3 (Berkeley) 3/15/86
  18.  */
  19.  
  20. /*
  21.  * NB: to fit things in six character monocase externals, the
  22.  * stdio code uses the prefix `__s' for stdio objects, typically
  23.  * followed by a three-character attempt at a mnemonic.
  24.  */
  25.  
  26. #ifndef _STDIO_H_
  27. #define _STDIO_H_
  28.  
  29. #include "_ansi.h"
  30.  
  31. #define _FSTDIO                 /* ``function stdio'' */
  32.  
  33. #define __need_size_t
  34. #define __need_NULL
  35. #include <sys/cdefs.h>
  36. #include <stddef.h>
  37.  
  38. #define __need___va_list
  39. #include <stdarg.h>
  40.  
  41. /*
  42.  * <sys/reent.h> 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 <sys/reent.h>
  48. #include <sys/types.h>
  49.  
  50. _BEGIN_STD_C
  51.  
  52. #if !defined(__FILE_defined)
  53. typedef __FILE FILE;
  54. # define __FILE_defined
  55. #endif
  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 <sys/stdio.h>
  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 */
  89. #define __SNLK  0x0001          /* stdio functions do not lock streams themselves */
  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
  110. #define BUFSIZ          1024
  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. #if __BSD_VISIBLE || __XSI_VISIBLE
  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.  
  150. #ifndef _NO_STDERR
  151.   #define       stderr  (_REENT->_stderr)
  152. #else
  153.   #define stderr stdout
  154. #endif
  155.  
  156. #define _stdin_r(x)     ((x)->_stdin)
  157. #define _stdout_r(x)    ((x)->_stdout)
  158. #define _stderr_r(x)    ((x)->_stderr)
  159.  
  160.  
  161.  
  162. /*
  163.  * Functions defined in ANSI C standard.
  164.  */
  165.  
  166. #ifndef __VALIST
  167. #ifdef __GNUC__
  168. #define __VALIST __gnuc_va_list
  169. #else
  170. #define __VALIST char*
  171. #endif
  172. #endif
  173.  
  174. FILE *  _EXFUN(tmpfile, (void));
  175. char *  _EXFUN(tmpnam, (char *));
  176. #if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
  177. char *  _EXFUN(tempnam, (const char *, const char *));
  178. #endif
  179. int     _EXFUN(fclose, (FILE *));
  180. int     _EXFUN(fflush, (FILE *));
  181. FILE *  _EXFUN(freopen, (const char *__restrict, const char *__restrict, FILE *__restrict));
  182. void    _EXFUN(setbuf, (FILE *__restrict, char *__restrict));
  183. int     _EXFUN(setvbuf, (FILE *__restrict, char *__restrict, int, size_t));
  184. int     _EXFUN(fprintf, (FILE *__restrict, const char *__restrict, ...)
  185.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  186. int     _EXFUN(fscanf, (FILE *__restrict, const char *__restrict, ...)
  187.                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
  188. int     _EXFUN(printf, (const char *__restrict, ...)
  189.                _ATTRIBUTE ((__format__ (__printf__, 1, 2))));
  190. int     _EXFUN(scanf, (const char *__restrict, ...)
  191.                _ATTRIBUTE ((__format__ (__scanf__, 1, 2))));
  192. int     _EXFUN(sscanf, (const char *__restrict, const char *__restrict, ...)
  193.                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
  194. int     _EXFUN(vfprintf, (FILE *__restrict, const char *__restrict, __VALIST)
  195.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  196. int     _EXFUN(vprintf, (const char *, __VALIST)
  197.                _ATTRIBUTE ((__format__ (__printf__, 1, 0))));
  198. int     _EXFUN(vsprintf, (char *__restrict, const char *__restrict, __VALIST)
  199.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  200. int     _EXFUN(fgetc, (FILE *));
  201. char *  _EXFUN(fgets, (char *__restrict, int, FILE *__restrict));
  202. int     _EXFUN(fputc, (int, FILE *));
  203. int     _EXFUN(fputs, (const char *__restrict, FILE *__restrict));
  204. int     _EXFUN(getc, (FILE *));
  205. int     _EXFUN(getchar, (void));
  206. char *  _EXFUN(gets, (char *));
  207. int     _EXFUN(putc, (int, FILE *));
  208. int     _EXFUN(putchar, (int));
  209. int     _EXFUN(puts, (const char *));
  210. int     _EXFUN(ungetc, (int, FILE *));
  211. size_t  _EXFUN(fread, (_PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
  212. size_t  _EXFUN(fwrite, (const _PTR __restrict , size_t _size, size_t _n, FILE *));
  213. #ifdef _COMPILING_NEWLIB
  214. int     _EXFUN(fgetpos, (FILE *, _fpos_t *));
  215. #else
  216. int     _EXFUN(fgetpos, (FILE *__restrict, fpos_t *__restrict));
  217. #endif
  218. int     _EXFUN(fseek, (FILE *, long, int));
  219. #ifdef _COMPILING_NEWLIB
  220. int     _EXFUN(fsetpos, (FILE *, const _fpos_t *));
  221. #else
  222. int     _EXFUN(fsetpos, (FILE *, const fpos_t *));
  223. #endif
  224. long    _EXFUN(ftell, ( FILE *));
  225. void    _EXFUN(rewind, (FILE *));
  226. void    _EXFUN(clearerr, (FILE *));
  227. int     _EXFUN(feof, (FILE *));
  228. int     _EXFUN(ferror, (FILE *));
  229. void    _EXFUN(perror, (const char *));
  230. #ifndef _REENT_ONLY
  231. FILE *  _EXFUN(fopen, (const char *__restrict _name, const char *__restrict _type));
  232. int     _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
  233.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  234. int     _EXFUN(remove, (const char *));
  235. int     _EXFUN(rename, (const char *, const char *));
  236. #ifdef _COMPILING_NEWLIB
  237. int     _EXFUN(_rename, (const char *, const char *));
  238. #endif
  239. #endif
  240. #if __LARGEFILE_VISIBLE || __POSIX_VISIBLE >= 200112
  241. #ifdef _COMPILING_NEWLIB
  242. int     _EXFUN(fseeko, (FILE *, _off_t, int));
  243. _off_t  _EXFUN(ftello, ( FILE *));
  244. #else
  245. int     _EXFUN(fseeko, (FILE *, off_t, int));
  246. off_t   _EXFUN(ftello, ( FILE *));
  247. #endif
  248. #endif
  249. #if __GNU_VISIBLE
  250. int     _EXFUN(fcloseall, (_VOID));
  251. #endif
  252. #ifndef _REENT_ONLY
  253. #if __ISO_C_VISIBLE >= 1999
  254. int     _EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...)
  255.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  256. int     _EXFUN(vsnprintf, (char *__restrict, size_t, const char *__restrict, __VALIST)
  257.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  258. int     _EXFUN(vfscanf, (FILE *__restrict, const char *__restrict, __VALIST)
  259.                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
  260. int     _EXFUN(vscanf, (const char *, __VALIST)
  261.                _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
  262. int     _EXFUN(vsscanf, (const char *__restrict, const char *__restrict, __VALIST)
  263.                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
  264. #endif
  265. #if __GNU_VISIBLE
  266. int     _EXFUN(asprintf, (char **__restrict, const char *__restrict, ...)
  267.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  268. int     _EXFUN(vasprintf, (char **, const char *, __VALIST)
  269.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  270. #endif
  271. #if __MISC_VISIBLE /* Newlib-specific */
  272. int     _EXFUN(asiprintf, (char **, const char *, ...)
  273.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  274. char *  _EXFUN(asniprintf, (char *, size_t *, const char *, ...)
  275.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  276. char *  _EXFUN(asnprintf, (char *__restrict, size_t *__restrict, const char *__restrict, ...)
  277.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  278. #ifndef diprintf
  279. int     _EXFUN(diprintf, (int, const char *, ...)
  280.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  281. #endif
  282. int     _EXFUN(fiprintf, (FILE *, const char *, ...)
  283.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  284. int     _EXFUN(fiscanf, (FILE *, const char *, ...)
  285.                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
  286. int     _EXFUN(iprintf, (const char *, ...)
  287.                _ATTRIBUTE ((__format__ (__printf__, 1, 2))));
  288. int     _EXFUN(iscanf, (const char *, ...)
  289.                _ATTRIBUTE ((__format__ (__scanf__, 1, 2))));
  290. int     _EXFUN(siprintf, (char *, const char *, ...)
  291.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  292. int     _EXFUN(siscanf, (const char *, const char *, ...)
  293.                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
  294. int     _EXFUN(sniprintf, (char *, size_t, const char *, ...)
  295.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  296. int     _EXFUN(vasiprintf, (char **, const char *, __VALIST)
  297.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  298. char *  _EXFUN(vasniprintf, (char *, size_t *, const char *, __VALIST)
  299.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  300. char *  _EXFUN(vasnprintf, (char *, size_t *, const char *, __VALIST)
  301.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  302. int     _EXFUN(vdiprintf, (int, const char *, __VALIST)
  303.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  304. int     _EXFUN(vfiprintf, (FILE *, const char *, __VALIST)
  305.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  306. int     _EXFUN(vfiscanf, (FILE *, const char *, __VALIST)
  307.                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
  308. int     _EXFUN(viprintf, (const char *, __VALIST)
  309.                _ATTRIBUTE ((__format__ (__printf__, 1, 0))));
  310. int     _EXFUN(viscanf, (const char *, __VALIST)
  311.                _ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
  312. int     _EXFUN(vsiprintf, (char *, const char *, __VALIST)
  313.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  314. int     _EXFUN(vsiscanf, (const char *, const char *, __VALIST)
  315.                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
  316. int     _EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST)
  317.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  318. #endif /* __MISC_VISIBLE */
  319. #endif /* !_REENT_ONLY */
  320.  
  321. /*
  322.  * Routines in POSIX 1003.1:2001.
  323.  */
  324.  
  325. #if __POSIX_VISIBLE
  326. #ifndef _REENT_ONLY
  327. FILE *  _EXFUN(fdopen, (int, const char *));
  328. #endif
  329. int     _EXFUN(fileno, (FILE *));
  330. #endif
  331. #if __MISC_VISIBLE || __POSIX_VISIBLE >= 199209
  332. int     _EXFUN(pclose, (FILE *));
  333. FILE *  _EXFUN(popen, (const char *, const char *));
  334. #endif
  335.  
  336. #if __BSD_VISIBLE
  337. void    _EXFUN(setbuffer, (FILE *, char *, int));
  338. int     _EXFUN(setlinebuf, (FILE *));
  339. #endif
  340.  
  341. #if __MISC_VISIBLE || (__XSI_VISIBLE && __POSIX_VISIBLE < 200112)
  342. int     _EXFUN(getw, (FILE *));
  343. int     _EXFUN(putw, (int, FILE *));
  344. #endif
  345. #if __MISC_VISIBLE || __POSIX_VISIBLE
  346. int     _EXFUN(getc_unlocked, (FILE *));
  347. int     _EXFUN(getchar_unlocked, (void));
  348. void    _EXFUN(flockfile, (FILE *));
  349. int     _EXFUN(ftrylockfile, (FILE *));
  350. void    _EXFUN(funlockfile, (FILE *));
  351. int     _EXFUN(putc_unlocked, (int, FILE *));
  352. int     _EXFUN(putchar_unlocked, (int));
  353. #endif
  354.  
  355. /*
  356.  * Routines in POSIX 1003.1:200x.
  357.  */
  358.  
  359. #if __POSIX_VISIBLE >= 200809
  360. # ifndef _REENT_ONLY
  361. #  ifndef dprintf
  362. int     _EXFUN(dprintf, (int, const char *__restrict, ...)
  363.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  364. #  endif
  365. FILE *  _EXFUN(fmemopen, (void *__restrict, size_t, const char *__restrict));
  366. /* getdelim - see __getdelim for now */
  367. /* getline - see __getline for now */
  368. FILE *  _EXFUN(open_memstream, (char **, size_t *));
  369. int     _EXFUN(vdprintf, (int, const char *__restrict, __VALIST)
  370.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  371. # endif
  372. #endif
  373. #if __ATFILE_VISIBLE
  374. int     _EXFUN(renameat, (int, const char *, int, const char *));
  375. #endif
  376.  
  377. /*
  378.  * Recursive versions of the above.
  379.  */
  380.  
  381. int     _EXFUN(_asiprintf_r, (struct _reent *, char **, const char *, ...)
  382.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  383. char *  _EXFUN(_asniprintf_r, (struct _reent *, char *, size_t *, const char *, ...)
  384.                _ATTRIBUTE ((__format__ (__printf__, 4, 5))));
  385. char *  _EXFUN(_asnprintf_r, (struct _reent *, char *__restrict, size_t *__restrict, const char *__restrict, ...)
  386.                _ATTRIBUTE ((__format__ (__printf__, 4, 5))));
  387. int     _EXFUN(_asprintf_r, (struct _reent *, char **__restrict, const char *__restrict, ...)
  388.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  389. int     _EXFUN(_diprintf_r, (struct _reent *, int, const char *, ...)
  390.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  391. int     _EXFUN(_dprintf_r, (struct _reent *, int, const char *__restrict, ...)
  392.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  393. int     _EXFUN(_fclose_r, (struct _reent *, FILE *));
  394. int     _EXFUN(_fcloseall_r, (struct _reent *));
  395. FILE *  _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
  396. int     _EXFUN(_fflush_r, (struct _reent *, FILE *));
  397. int     _EXFUN(_fgetc_r, (struct _reent *, FILE *));
  398. int     _EXFUN(_fgetc_unlocked_r, (struct _reent *, FILE *));
  399. char *  _EXFUN(_fgets_r, (struct _reent *, char *__restrict, int, FILE *__restrict));
  400. char *  _EXFUN(_fgets_unlocked_r, (struct _reent *, char *__restrict, int, FILE *__restrict));
  401. #ifdef _COMPILING_NEWLIB
  402. int     _EXFUN(_fgetpos_r, (struct _reent *, FILE *__restrict, _fpos_t *__restrict));
  403. int     _EXFUN(_fsetpos_r, (struct _reent *, FILE *, const _fpos_t *));
  404. #else
  405. int     _EXFUN(_fgetpos_r, (struct _reent *, FILE *, fpos_t *));
  406. int     _EXFUN(_fsetpos_r, (struct _reent *, FILE *, const fpos_t *));
  407. #endif
  408. int     _EXFUN(_fiprintf_r, (struct _reent *, FILE *, const char *, ...)
  409.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  410. int     _EXFUN(_fiscanf_r, (struct _reent *, FILE *, const char *, ...)
  411.                _ATTRIBUTE ((__format__ (__scanf__, 3, 4))));
  412. FILE *  _EXFUN(_fmemopen_r, (struct _reent *, void *__restrict, size_t, const char *__restrict));
  413. FILE *  _EXFUN(_fopen_r, (struct _reent *, const char *__restrict, const char *__restrict));
  414. FILE *  _EXFUN(_freopen_r, (struct _reent *, const char *__restrict, const char *__restrict, FILE *__restrict));
  415. int     _EXFUN(_fprintf_r, (struct _reent *, FILE *__restrict, const char *__restrict, ...)
  416.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  417. int     _EXFUN(_fpurge_r, (struct _reent *, FILE *));
  418. int     _EXFUN(_fputc_r, (struct _reent *, int, FILE *));
  419. int     _EXFUN(_fputc_unlocked_r, (struct _reent *, int, FILE *));
  420. int     _EXFUN(_fputs_r, (struct _reent *, const char *__restrict, FILE *__restrict));
  421. int     _EXFUN(_fputs_unlocked_r, (struct _reent *, const char *__restrict, FILE *__restrict));
  422. size_t  _EXFUN(_fread_r, (struct _reent *, _PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
  423. size_t  _EXFUN(_fread_unlocked_r, (struct _reent *, _PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
  424. int     _EXFUN(_fscanf_r, (struct _reent *, FILE *__restrict, const char *__restrict, ...)
  425.                _ATTRIBUTE ((__format__ (__scanf__, 3, 4))));
  426. int     _EXFUN(_fseek_r, (struct _reent *, FILE *, long, int));
  427. int     _EXFUN(_fseeko_r,(struct _reent *, FILE *, _off_t, int));
  428. long    _EXFUN(_ftell_r, (struct _reent *, FILE *));
  429. _off_t  _EXFUN(_ftello_r,(struct _reent *, FILE *));
  430. void    _EXFUN(_rewind_r, (struct _reent *, FILE *));
  431. size_t  _EXFUN(_fwrite_r, (struct _reent *, const _PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
  432. size_t  _EXFUN(_fwrite_unlocked_r, (struct _reent *, const _PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
  433. int     _EXFUN(_getc_r, (struct _reent *, FILE *));
  434. int     _EXFUN(_getc_unlocked_r, (struct _reent *, FILE *));
  435. int     _EXFUN(_getchar_r, (struct _reent *));
  436. int     _EXFUN(_getchar_unlocked_r, (struct _reent *));
  437. char *  _EXFUN(_gets_r, (struct _reent *, char *));
  438. int     _EXFUN(_iprintf_r, (struct _reent *, const char *, ...)
  439.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  440. int     _EXFUN(_iscanf_r, (struct _reent *, const char *, ...)
  441.                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
  442. FILE *  _EXFUN(_open_memstream_r, (struct _reent *, char **, size_t *));
  443. void    _EXFUN(_perror_r, (struct _reent *, const char *));
  444. int     _EXFUN(_printf_r, (struct _reent *, const char *__restrict, ...)
  445.                _ATTRIBUTE ((__format__ (__printf__, 2, 3))));
  446. int     _EXFUN(_putc_r, (struct _reent *, int, FILE *));
  447. int     _EXFUN(_putc_unlocked_r, (struct _reent *, int, FILE *));
  448. int     _EXFUN(_putchar_unlocked_r, (struct _reent *, int));
  449. int     _EXFUN(_putchar_r, (struct _reent *, int));
  450. int     _EXFUN(_puts_r, (struct _reent *, const char *));
  451. int     _EXFUN(_remove_r, (struct _reent *, const char *));
  452. int     _EXFUN(_rename_r, (struct _reent *,
  453.                            const char *_old, const char *_new));
  454. int     _EXFUN(_scanf_r, (struct _reent *, const char *__restrict, ...)
  455.                _ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
  456. int     _EXFUN(_siprintf_r, (struct _reent *, char *, const char *, ...)
  457.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  458. int     _EXFUN(_siscanf_r, (struct _reent *, const char *, const char *, ...)
  459.                _ATTRIBUTE ((__format__ (__scanf__, 3, 4))));
  460. int     _EXFUN(_sniprintf_r, (struct _reent *, char *, size_t, const char *, ...)
  461.                _ATTRIBUTE ((__format__ (__printf__, 4, 5))));
  462. int     _EXFUN(_snprintf_r, (struct _reent *, char *__restrict, size_t, const char *__restrict, ...)
  463.                _ATTRIBUTE ((__format__ (__printf__, 4, 5))));
  464. int     _EXFUN(_sprintf_r, (struct _reent *, char *__restrict, const char *__restrict, ...)
  465.                _ATTRIBUTE ((__format__ (__printf__, 3, 4))));
  466. int     _EXFUN(_sscanf_r, (struct _reent *, const char *__restrict, const char *__restrict, ...)
  467.                _ATTRIBUTE ((__format__ (__scanf__, 3, 4))));
  468. char *  _EXFUN(_tempnam_r, (struct _reent *, const char *, const char *));
  469. FILE *  _EXFUN(_tmpfile_r, (struct _reent *));
  470. char *  _EXFUN(_tmpnam_r, (struct _reent *, char *));
  471. int     _EXFUN(_ungetc_r, (struct _reent *, int, FILE *));
  472. int     _EXFUN(_vasiprintf_r, (struct _reent *, char **, const char *, __VALIST)
  473.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  474. char *  _EXFUN(_vasniprintf_r, (struct _reent*, char *, size_t *, const char *, __VALIST)
  475.                _ATTRIBUTE ((__format__ (__printf__, 4, 0))));
  476. char *  _EXFUN(_vasnprintf_r, (struct _reent*, char *, size_t *, const char *, __VALIST)
  477.                _ATTRIBUTE ((__format__ (__printf__, 4, 0))));
  478. int     _EXFUN(_vasprintf_r, (struct _reent *, char **, const char *, __VALIST)
  479.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  480. int     _EXFUN(_vdiprintf_r, (struct _reent *, int, const char *, __VALIST)
  481.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  482. int     _EXFUN(_vdprintf_r, (struct _reent *, int, const char *__restrict, __VALIST)
  483.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  484. int     _EXFUN(_vfiprintf_r, (struct _reent *, FILE *, const char *, __VALIST)
  485.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  486. int     _EXFUN(_vfiscanf_r, (struct _reent *, FILE *, const char *, __VALIST)
  487.                _ATTRIBUTE ((__format__ (__scanf__, 3, 0))));
  488. int     _EXFUN(_vfprintf_r, (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
  489.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  490. int     _EXFUN(_vfscanf_r, (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
  491.                _ATTRIBUTE ((__format__ (__scanf__, 3, 0))));
  492. int     _EXFUN(_viprintf_r, (struct _reent *, const char *, __VALIST)
  493.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  494. int     _EXFUN(_viscanf_r, (struct _reent *, const char *, __VALIST)
  495.                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
  496. int     _EXFUN(_vprintf_r, (struct _reent *, const char *__restrict, __VALIST)
  497.                _ATTRIBUTE ((__format__ (__printf__, 2, 0))));
  498. int     _EXFUN(_vscanf_r, (struct _reent *, const char *__restrict, __VALIST)
  499.                _ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
  500. int     _EXFUN(_vsiprintf_r, (struct _reent *, char *, const char *, __VALIST)
  501.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  502. int     _EXFUN(_vsiscanf_r, (struct _reent *, const char *, const char *, __VALIST)
  503.                _ATTRIBUTE ((__format__ (__scanf__, 3, 0))));
  504. int     _EXFUN(_vsniprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST)
  505.                _ATTRIBUTE ((__format__ (__printf__, 4, 0))));
  506. int     _EXFUN(_vsnprintf_r, (struct _reent *, char *__restrict, size_t, const char *__restrict, __VALIST)
  507.                _ATTRIBUTE ((__format__ (__printf__, 4, 0))));
  508. int     _EXFUN(_vsprintf_r, (struct _reent *, char *__restrict, const char *__restrict, __VALIST)
  509.                _ATTRIBUTE ((__format__ (__printf__, 3, 0))));
  510. int     _EXFUN(_vsscanf_r, (struct _reent *, const char *__restrict, const char *__restrict, __VALIST)
  511.                _ATTRIBUTE ((__format__ (__scanf__, 3, 0))));
  512.  
  513. /* Other extensions.  */
  514.  
  515. int     _EXFUN(fpurge, (FILE *));
  516. ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *));
  517. ssize_t _EXFUN(__getline, (char **, size_t *, FILE *));
  518.  
  519. #if __MISC_VISIBLE
  520. void    _EXFUN(clearerr_unlocked, (FILE *));
  521. int     _EXFUN(feof_unlocked, (FILE *));
  522. int     _EXFUN(ferror_unlocked, (FILE *));
  523. int     _EXFUN(fileno_unlocked, (FILE *));
  524. int     _EXFUN(fflush_unlocked, (FILE *));
  525. int     _EXFUN(fgetc_unlocked, (FILE *));
  526. int     _EXFUN(fputc_unlocked, (int, FILE *));
  527. size_t  _EXFUN(fread_unlocked, (_PTR __restrict, size_t _size, size_t _n, FILE *__restrict));
  528. size_t  _EXFUN(fwrite_unlocked, (const _PTR __restrict , size_t _size, size_t _n, FILE *));
  529. #endif
  530.  
  531. #if __GNU_VISIBLE
  532. char *  _EXFUN(fgets_unlocked, (char *__restrict, int, FILE *__restrict));
  533. int     _EXFUN(fputs_unlocked, (const char *__restrict, FILE *__restrict));
  534. #endif
  535.  
  536. #ifdef __LARGE64_FILES
  537. #if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB)
  538. FILE *  _EXFUN(fdopen64, (int, const char *));
  539. FILE *  _EXFUN(fopen64, (const char *, const char *));
  540. FILE *  _EXFUN(freopen64, (_CONST char *, _CONST char *, FILE *));
  541. _off64_t _EXFUN(ftello64, (FILE *));
  542. _off64_t _EXFUN(fseeko64, (FILE *, _off64_t, int));
  543. int     _EXFUN(fgetpos64, (FILE *, _fpos64_t *));
  544. int     _EXFUN(fsetpos64, (FILE *, const _fpos64_t *));
  545. FILE *  _EXFUN(tmpfile64, (void));
  546.  
  547. FILE *  _EXFUN(_fdopen64_r, (struct _reent *, int, const char *));
  548. FILE *  _EXFUN(_fopen64_r, (struct _reent *,const char *, const char *));
  549. FILE *  _EXFUN(_freopen64_r, (struct _reent *, _CONST char *, _CONST char *, FILE *));
  550. _off64_t _EXFUN(_ftello64_r, (struct _reent *, FILE *));
  551. _off64_t _EXFUN(_fseeko64_r, (struct _reent *, FILE *, _off64_t, int));
  552. int     _EXFUN(_fgetpos64_r, (struct _reent *, FILE *, _fpos64_t *));
  553. int     _EXFUN(_fsetpos64_r, (struct _reent *, FILE *, const _fpos64_t *));
  554. FILE *  _EXFUN(_tmpfile64_r, (struct _reent *));
  555. #endif /* !__CYGWIN__ */
  556. #endif /* __LARGE64_FILES */
  557.  
  558. /*
  559.  * Routines internal to the implementation.
  560.  */
  561.  
  562. int     _EXFUN(__srget_r, (struct _reent *, FILE *));
  563. int     _EXFUN(__swbuf_r, (struct _reent *, int, FILE *));
  564.  
  565. /*
  566.  * Stdio function-access interface.
  567.  */
  568.  
  569. #if __BSD_VISIBLE
  570. # ifdef __LARGE64_FILES
  571. FILE    *_EXFUN(funopen,(const _PTR __cookie,
  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),
  576.                 _fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence),
  577.                 int (*__closefn)(_PTR __c)));
  578. FILE    *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie,
  579.                 int (*__readfn)(_PTR __c, char *__buf,
  580.                                 _READ_WRITE_BUFSIZE_TYPE __n),
  581.                 int (*__writefn)(_PTR __c, const char *__buf,
  582.                                  _READ_WRITE_BUFSIZE_TYPE __n),
  583.                 _fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence),
  584.                 int (*__closefn)(_PTR __c)));
  585. # else
  586. FILE    *_EXFUN(funopen,(const _PTR __cookie,
  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),
  591.                 fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence),
  592.                 int (*__closefn)(_PTR __cookie)));
  593. FILE    *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie,
  594.                 int (*__readfn)(_PTR __cookie, char *__buf,
  595.                                 _READ_WRITE_BUFSIZE_TYPE __n),
  596.                 int (*__writefn)(_PTR __cookie, const char *__buf,
  597.                                  _READ_WRITE_BUFSIZE_TYPE __n),
  598.                 fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence),
  599.                 int (*__closefn)(_PTR __cookie)));
  600. # endif /* !__LARGE64_FILES */
  601.  
  602. # define        fropen(__cookie, __fn) funopen(__cookie, __fn, (int (*)())0, \
  603.                                                (fpos_t (*)())0, (int (*)())0)
  604. # define        fwopen(__cookie, __fn) funopen(__cookie, (int (*)())0, __fn, \
  605.                                                (fpos_t (*)())0, (int (*)())0)
  606. #endif /* __BSD_VISIBLE */
  607.  
  608. #if __GNU_VISIBLE
  609. typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
  610. typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
  611.                                         size_t __n);
  612. # ifdef __LARGE64_FILES
  613. typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,
  614.                                    int __whence);
  615. # else
  616. typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);
  617. # endif /* !__LARGE64_FILES */
  618. typedef int cookie_close_function_t(void *__cookie);
  619. typedef struct
  620. {
  621.   /* These four struct member names are dictated by Linux; hopefully,
  622.      they don't conflict with any macros.  */
  623.   cookie_read_function_t  *read;
  624.   cookie_write_function_t *write;
  625.   cookie_seek_function_t  *seek;
  626.   cookie_close_function_t *close;
  627. } cookie_io_functions_t;
  628. FILE *_EXFUN(fopencookie,(void *__cookie,
  629.                 const char *__mode, cookie_io_functions_t __functions));
  630. FILE *_EXFUN(_fopencookie_r,(struct _reent *, void *__cookie,
  631.                 const char *__mode, cookie_io_functions_t __functions));
  632. #endif /* __GNU_VISIBLE */
  633.  
  634. #ifndef __CUSTOM_FILE_IO__
  635. /*
  636.  * The __sfoo macros are here so that we can
  637.  * define function versions in the C library.
  638.  */
  639. #define       __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++))
  640.  
  641. #ifdef __SCLE
  642. /*  For a platform with CR/LF, additional logic is required by
  643.   __sgetc_r which would otherwise simply be a macro; therefore we
  644.   use an inlined function.  The function is only meant to be inlined
  645.   in place as used and the function body should never be emitted.  
  646.  
  647.   There are two possible means to this end when compiling with GCC,
  648.   one when compiling with a standard C99 compiler, and for other
  649.   compilers we're just stuck.  At the moment, this issue only
  650.   affects the Cygwin target, so we'll most likely be using GCC. */
  651.  
  652. _ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p);
  653.  
  654. _ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p)
  655.   {
  656.     int __c = __sgetc_raw_r(__ptr, __p);
  657.     if ((__p->_flags & __SCLE) && (__c == '\r'))
  658.       {
  659.       int __c2 = __sgetc_raw_r(__ptr, __p);
  660.       if (__c2 == '\n')
  661.         __c = __c2;
  662.       else
  663.         ungetc(__c2, __p);
  664.       }
  665.     return __c;
  666.   }
  667. #else
  668. #define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
  669. #endif
  670.  
  671. #ifdef __GNUC__
  672. _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
  673. #ifdef __SCLE
  674.         if ((_p->_flags & __SCLE) && _c == '\n')
  675.           __sputc_r (_ptr, '\r', _p);
  676. #endif
  677.         if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
  678.                 return (*_p->_p++ = _c);
  679.         else
  680.                 return (__swbuf_r(_ptr, _c, _p));
  681. }
  682. #else
  683. /*
  684.  * This has been tuned to generate reasonable code on the vax using pcc
  685.  */
  686. #define       __sputc_raw_r(__ptr, __c, __p) \
  687.         (--(__p)->_w < 0 ? \
  688.                 (__p)->_w >= (__p)->_lbfsize ? \
  689.                         (*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \
  690.                                 (int)*(__p)->_p++ : \
  691.                                 __swbuf_r(__ptr, '\n', __p) : \
  692.                         __swbuf_r(__ptr, (int)(__c), __p) : \
  693.                 (*(__p)->_p = (__c), (int)*(__p)->_p++))
  694. #ifdef __SCLE
  695. #define __sputc_r(__ptr, __c, __p) \
  696.         ((((__p)->_flags & __SCLE) && ((__c) == '\n')) \
  697.           ? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \
  698.         __sputc_raw_r((__ptr), (__c), (__p)))
  699. #else
  700. #define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p)
  701. #endif
  702. #endif
  703.  
  704. #define __sfeof(p)      ((int)(((p)->_flags & __SEOF) != 0))
  705. #define __sferror(p)    ((int)(((p)->_flags & __SERR) != 0))
  706. #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
  707. #define __sfileno(p)    ((p)->_file)
  708.  
  709. #ifndef _REENT_SMALL
  710. #define feof(p)         __sfeof(p)
  711. #define ferror(p)       __sferror(p)
  712. #define clearerr(p)     __sclearerr(p)
  713.  
  714. #if __MISC_VISIBLE
  715. #define feof_unlocked(p)        __sfeof(p)
  716. #define ferror_unlocked(p)      __sferror(p)
  717. #define clearerr_unlocked(p)    __sclearerr(p)
  718. #endif /* __MISC_VISIBLE */
  719. #endif /* _REENT_SMALL */
  720.  
  721. #if 0 /* __POSIX_VISIBLE - FIXME: must initialize stdio first, use fn */
  722. #define fileno(p)       __sfileno(p)
  723. #endif
  724.  
  725. #ifndef __CYGWIN__
  726. #ifndef lint
  727. #define getc(fp)        __sgetc_r(_REENT, fp)
  728. #define putc(x, fp)     __sputc_r(_REENT, x, fp)
  729. #endif /* lint */
  730. #endif /* __CYGWIN__ */
  731.  
  732. #if __MISC_VISIBLE
  733. /* fast always-buffered version, true iff error */
  734. #define fast_putc(x,p) (--(p)->_w < 0 ? \
  735.         __swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
  736. #endif
  737.  
  738. #if __XSI_VISIBLE
  739. #define L_cuserid       9               /* posix says it goes in stdio.h :( */
  740. #ifdef __CYGWIN__
  741. #define L_ctermid       16
  742. #endif
  743. #endif
  744.  
  745. #endif /* !__CUSTOM_FILE_IO__ */
  746.  
  747. #define getchar()       getc(stdin)
  748. #define putchar(x)      putc(x, stdout)
  749.  
  750. #if __MISC_VISIBLE || __POSIX_VISIBLE
  751. #define getchar_unlocked()      getc_unlocked(stdin)
  752. #define putchar_unlocked(x)     putc_unlocked(x, stdout)
  753. #endif
  754.  
  755. _END_STD_C
  756.  
  757. #endif /* _STDIO_H_ */
  758.