stdio.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef _STDIO_H_
  2. #define _STDIO_H_
  3. #pragma lib "/$M/lib/ape/libap.a"
  4. /*
  5. * pANS stdio.h
  6. */
  7. #include <stdarg.h>
  8. #include <stddef.h>
  9. #include <sys/types.h>
  10. /*
  11. * According to X3J11, there is only one i/o buffer
  12. * and it must not be occupied by both input and output data.
  13. * If rp<wp, we must have state==RD and
  14. * if wp<rp, we must have state==WR, so that getc and putc work correctly.
  15. * On open, rp, wp and buf are set to 0, so first getc or putc will call _IO_getc
  16. * or _IO_putc, which will allocate the buffer.
  17. * If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
  18. * buf, rp and wp are pointed at unbuf.
  19. * If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at the
  20. * end of the buffer so that it can be called on each putc to check whether it's got
  21. * a newline. This nonsense is in order to avoid impacting performance of the other
  22. * buffering modes more than necessary -- putting the test in putc adds many
  23. * instructions that are wasted in non-_IOLBF mode:
  24. * #define putc(c, f) (_IO_ctmp=(c),\
  25. * (f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'\
  26. * ?_IO_putc(_IO_ctmp, f)\
  27. * :*(f)->wp++=_IO_ctmp)
  28. *
  29. */
  30. typedef struct{
  31. int fd; /* UNIX file pointer */
  32. char flags; /* bits for must free buffer on close, line-buffered */
  33. char state; /* last operation was read, write, position, error, eof */
  34. char *buf; /* pointer to i/o buffer */
  35. char *rp; /* read pointer (or write end-of-buffer) */
  36. char *wp; /* write pointer (or read end-of-buffer) */
  37. char *lp; /* actual write pointer used when line-buffering */
  38. size_t bufl; /* actual length of buffer */
  39. char unbuf[1]; /* tiny buffer for unbuffered io (used for ungetc?) */
  40. }FILE;
  41. typedef long long fpos_t;
  42. #ifndef NULL
  43. #ifdef __cplusplus
  44. #define NULL 0
  45. #else
  46. #define NULL ((void*)0)
  47. #endif
  48. #endif
  49. /*
  50. * Third arg of setvbuf
  51. */
  52. #define _IOFBF 1 /* block-buffered */
  53. #define _IOLBF 2 /* line-buffered */
  54. #define _IONBF 3 /* unbuffered */
  55. #define BUFSIZ 4096 /* size of setbuf buffer */
  56. #define EOF (-1) /* returned on end of file */
  57. #define FOPEN_MAX 90 /* max files open */
  58. #define FILENAME_MAX BUFSIZ /* silly filename length */
  59. #define L_tmpnam 20 /* sizeof "/tmp/abcdefghij9999 */
  60. #define L_cuserid 32 /* maximum size user name */
  61. #define L_ctermid 32 /* size of name of controlling tty */
  62. #define SEEK_CUR 1
  63. #define SEEK_END 2
  64. #define SEEK_SET 0
  65. #define TMP_MAX 64 /* very hard to set correctly */
  66. #define stderr (&_IO_stream[2])
  67. #define stdin (&_IO_stream[0])
  68. #define stdout (&_IO_stream[1])
  69. #define _IO_CHMASK 0377 /* mask for 8 bit characters */
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. extern int remove(const char *);
  74. extern int rename(const char *, const char *);
  75. extern FILE *tmpfile(void);
  76. extern char *tmpnam(char *);
  77. extern int fclose(FILE *);
  78. extern int fflush(FILE *);
  79. extern FILE *fopen(const char *, const char *);
  80. extern FILE *freopen(const char *, const char *, FILE *);
  81. extern void setbuf(FILE *, char *);
  82. extern int setvbuf(FILE *, char *, int, size_t);
  83. extern int fprintf(FILE *, const char *, ...);
  84. extern int fscanf(FILE *, const char *, ...);
  85. extern int printf(const char *, ...);
  86. extern int scanf(const char *, ...);
  87. extern int sprintf(char *, const char *, ...);
  88. #ifdef _C99_SNPRINTF_EXTENSION /* user knows about c99 out-of-bounds returns */
  89. extern int snprintf(char *, size_t, const char *, ...);
  90. extern int vsnprintf(char *, size_t, const char *, va_list);
  91. #else
  92. /* draw errors on any attempt to use *snprintf value so old code gets changed */
  93. extern void snprintf(char *, size_t, const char *, ...);
  94. extern void vsnprintf(char *, size_t, const char *, va_list);
  95. #endif
  96. extern int sscanf(const char *, const char *, ...);
  97. extern int vfprintf(FILE *, const char *, va_list);
  98. extern int vprintf(const char *, va_list);
  99. extern int vsprintf(char *, const char *, va_list);
  100. extern int vfscanf(FILE *, const char *, va_list);
  101. extern int fgetc(FILE *);
  102. extern char *fgets(char *, int, FILE *);
  103. extern int fputc(int, FILE *);
  104. extern int fputs(const char *, FILE *);
  105. extern int getc(FILE *);
  106. #define getc(f) ((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
  107. extern int _IO_getc(FILE *f);
  108. extern int getchar(void);
  109. #define getchar() getc(stdin)
  110. extern char *gets(char *);
  111. extern int putc(int, FILE *);
  112. #define putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
  113. extern int _IO_putc(int, FILE *);
  114. extern int putchar(int);
  115. #define putchar(c) putc(c, stdout)
  116. extern int puts(const char *);
  117. extern int ungetc(int, FILE *);
  118. extern size_t fread(void *, size_t, size_t, FILE *);
  119. extern size_t fwrite(const void *, size_t, size_t, FILE *);
  120. extern int fgetpos(FILE *, fpos_t *);
  121. extern int fseek(FILE *, long, int);
  122. extern int fseeko(FILE *, off_t, int);
  123. extern int fsetpos(FILE *, const fpos_t *);
  124. extern long ftell(FILE *);
  125. extern off_t ftello(FILE *);
  126. extern void rewind(FILE *);
  127. extern void clearerr(FILE *);
  128. extern int feof(FILE *);
  129. extern int ferror(FILE *);
  130. extern void perror(const char *);
  131. extern FILE _IO_stream[FOPEN_MAX];
  132. #ifdef _POSIX_SOURCE
  133. extern int fileno(FILE *);
  134. extern FILE* fdopen(int, const char*);
  135. extern char *ctermid(char *);
  136. #endif
  137. #ifdef _REENTRANT_SOURCE
  138. extern char *tmpnam_r(char *);
  139. extern char *ctermid_r(char *);
  140. #endif
  141. #ifdef _BSD_EXTENSION
  142. #pragma lib "/$M/lib/ape/libbsd.a"
  143. extern FILE *popen(char *, char *);
  144. extern int pclose(FILE *);
  145. #endif
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif