stdio.h 4.7 KB

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