1
0

stdio.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. extern int snprintf(char *, size_t, const char *, ...);
  89. extern int sscanf(const char *, const char *, ...);
  90. extern int vfprintf(FILE *, const char *, va_list);
  91. extern int vprintf(const char *, va_list);
  92. extern int vsprintf(char *, const char *, va_list);
  93. extern int vsnprintf(char *, size_t, const char *, va_list);
  94. extern int vfscanf(FILE *, const char *, va_list);
  95. extern int fgetc(FILE *);
  96. extern char *fgets(char *, int, FILE *);
  97. extern int fputc(int, FILE *);
  98. extern int fputs(const char *, FILE *);
  99. extern int getc(FILE *);
  100. #define getc(f) ((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
  101. extern int _IO_getc(FILE *f);
  102. extern int getchar(void);
  103. #define getchar() getc(stdin)
  104. extern char *gets(char *);
  105. extern int putc(int, FILE *);
  106. #define putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
  107. extern int _IO_putc(int, FILE *);
  108. extern int putchar(int);
  109. #define putchar(c) putc(c, stdout)
  110. extern int puts(const char *);
  111. extern int ungetc(int, FILE *);
  112. extern size_t fread(void *, size_t, size_t, FILE *);
  113. extern size_t fwrite(const void *, size_t, size_t, FILE *);
  114. extern int fgetpos(FILE *, fpos_t *);
  115. extern int fseek(FILE *, long, int);
  116. extern int fseeko(FILE *, off_t, int);
  117. extern int fsetpos(FILE *, const fpos_t *);
  118. extern long ftell(FILE *);
  119. extern off_t ftello(FILE *);
  120. extern void rewind(FILE *);
  121. extern void clearerr(FILE *);
  122. extern int feof(FILE *);
  123. extern int ferror(FILE *);
  124. extern void perror(const char *);
  125. extern FILE _IO_stream[FOPEN_MAX];
  126. #ifdef _POSIX_SOURCE
  127. extern int fileno(FILE *);
  128. extern FILE* fdopen(int, const char*);
  129. extern char *ctermid(char *);
  130. #endif
  131. #ifdef _BSD_EXTENSION
  132. #pragma lib "/$M/lib/ape/libbsd.a"
  133. extern FILE *popen(char *, char *);
  134. extern int pclose(FILE *);
  135. #endif
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif