1
0

stdio.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #define NULL 0
  44. #endif
  45. /*
  46. * Third arg of setvbuf
  47. */
  48. #define _IOFBF 1 /* block-buffered */
  49. #define _IOLBF 2 /* line-buffered */
  50. #define _IONBF 3 /* unbuffered */
  51. #define BUFSIZ 4096 /* size of setbuf buffer */
  52. #define EOF (-1) /* returned on end of file */
  53. #define FOPEN_MAX 90 /* max files open */
  54. #define FILENAME_MAX BUFSIZ /* silly filename length */
  55. #define L_tmpnam 20 /* sizeof "/tmp/abcdefghij9999 */
  56. #define L_cuserid 32 /* maximum size user name */
  57. #define L_ctermid 32 /* size of name of controlling tty */
  58. #define SEEK_CUR 1
  59. #define SEEK_END 2
  60. #define SEEK_SET 0
  61. #define TMP_MAX 64 /* very hard to set correctly */
  62. #define stderr (&_IO_stream[2])
  63. #define stdin (&_IO_stream[0])
  64. #define stdout (&_IO_stream[1])
  65. #define _IO_CHMASK 0377 /* mask for 8 bit characters */
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. extern int remove(const char *);
  70. extern int rename(const char *, const char *);
  71. extern FILE *tmpfile(void);
  72. extern char *tmpnam(char *);
  73. extern int fclose(FILE *);
  74. extern int fflush(FILE *);
  75. extern FILE *fopen(const char *, const char *);
  76. extern FILE *freopen(const char *, const char *, FILE *);
  77. extern void setbuf(FILE *, char *);
  78. extern int setvbuf(FILE *, char *, int, size_t);
  79. extern int fprintf(FILE *, const char *, ...);
  80. extern int fscanf(FILE *, const char *, ...);
  81. extern int printf(const char *, ...);
  82. extern int scanf(const char *, ...);
  83. extern int sprintf(char *, const char *, ...);
  84. extern int snprintf(char *, size_t, const char *, ...);
  85. extern int sscanf(const char *, const char *, ...);
  86. extern int vfprintf(FILE *, const char *, va_list);
  87. extern int vprintf(const char *, va_list);
  88. extern int vsprintf(char *, const char *, va_list);
  89. extern int vsnprintf(char *, size_t, const char *, va_list);
  90. extern int vfscanf(FILE *, const char *, va_list);
  91. extern int fgetc(FILE *);
  92. extern char *fgets(char *, int, FILE *);
  93. extern int fputc(int, FILE *);
  94. extern int fputs(const char *, FILE *);
  95. extern int getc(FILE *);
  96. #define getc(f) ((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
  97. extern int _IO_getc(FILE *f);
  98. extern int getchar(void);
  99. #define getchar() getc(stdin)
  100. extern char *gets(char *);
  101. extern int putc(int, FILE *);
  102. #define putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
  103. extern int _IO_putc(int, FILE *);
  104. extern int putchar(int);
  105. #define putchar(c) putc(c, stdout)
  106. extern int puts(const char *);
  107. extern int ungetc(int, FILE *);
  108. extern size_t fread(void *, size_t, size_t, FILE *);
  109. extern size_t fwrite(const void *, size_t, size_t, FILE *);
  110. extern int fgetpos(FILE *, fpos_t *);
  111. extern int fseek(FILE *, long, int);
  112. extern int fseeko(FILE *, off_t, int);
  113. extern int fsetpos(FILE *, const fpos_t *);
  114. extern long ftell(FILE *);
  115. extern off_t ftello(FILE *);
  116. extern void rewind(FILE *);
  117. extern void clearerr(FILE *);
  118. extern int feof(FILE *);
  119. extern int ferror(FILE *);
  120. extern void perror(const char *);
  121. extern FILE _IO_stream[FOPEN_MAX];
  122. #ifdef _POSIX_SOURCE
  123. extern int fileno(FILE *);
  124. extern FILE* fdopen(int, const char*);
  125. extern char *ctermid(char *);
  126. #endif
  127. #ifdef _BSD_EXTENSION
  128. #pragma lib "/$M/lib/ape/libbsd.a"
  129. extern FILE *popen(char *, char *);
  130. extern int pclose(FILE *);
  131. #endif
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif