stdio_impl.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef _STDIO_IMPL_H
  2. #define _STDIO_IMPL_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <stddef.h>
  6. #include <stdarg.h>
  7. #include <string.h>
  8. #include <inttypes.h>
  9. #include <wchar.h>
  10. #include <unistd.h>
  11. #include <fcntl.h>
  12. #include <limits.h>
  13. #include <errno.h>
  14. #include <termios.h>
  15. #include <sys/ioctl.h>
  16. #include <ctype.h>
  17. #include <sys/wait.h>
  18. #include <math.h>
  19. #include <float.h>
  20. #include <sys/uio.h>
  21. #include "syscall.h"
  22. #include "libc.h"
  23. #define UNGET 8
  24. #define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
  25. #define FUNLOCK(f) if (__need_unlock) __unlockfile((f)); else
  26. #define F_PERM 1
  27. #define F_NORD 4
  28. #define F_NOWR 8
  29. #define F_EOF 16
  30. #define F_ERR 32
  31. #define F_SVB 64
  32. struct __FILE_s {
  33. unsigned flags;
  34. unsigned char *rpos, *rend;
  35. int (*close)(FILE *);
  36. unsigned char *wend, *wpos;
  37. unsigned char *mustbezero_1;
  38. unsigned char *wbase;
  39. size_t (*read)(FILE *, unsigned char *, size_t);
  40. size_t (*write)(FILE *, const unsigned char *, size_t);
  41. off_t (*seek)(FILE *, off_t, int);
  42. unsigned char *buf;
  43. size_t buf_size;
  44. FILE *prev, *next;
  45. int fd;
  46. int pipe_pid;
  47. long lockcount;
  48. short dummy3;
  49. signed char mode;
  50. signed char lbf;
  51. int lock;
  52. int waiters;
  53. void *cookie;
  54. off_t off;
  55. int (*flush)(FILE *);
  56. void *mustbezero_2;
  57. };
  58. size_t __stdio_read(FILE *, unsigned char *, size_t);
  59. size_t __stdio_write(FILE *, const unsigned char *, size_t);
  60. size_t __stdout_write(FILE *, const unsigned char *, size_t);
  61. off_t __stdio_seek(FILE *, off_t, int);
  62. int __stdio_close(FILE *);
  63. int __toread(FILE *);
  64. int __towrite(FILE *);
  65. int __overflow(FILE *, int);
  66. int __oflow(FILE *);
  67. int __uflow(FILE *);
  68. int __underflow(FILE *);
  69. int __fseeko(FILE *, off_t, int);
  70. int __fseeko_unlocked(FILE *, off_t, int);
  71. off_t __ftello(FILE *);
  72. off_t __ftello_unlocked(FILE *);
  73. size_t __fwritex(const unsigned char *, size_t, FILE *);
  74. int __putc_unlocked(int, FILE *);
  75. FILE *__fdopen(int, const char *);
  76. #define OFLLOCK() LOCK(&libc.ofl_lock)
  77. #define OFLUNLOCK() UNLOCK(&libc.ofl_lock)
  78. #define feof(f) ((f)->flags & F_EOF)
  79. #define ferror(f) ((f)->flags & F_ERR)
  80. #define getc_unlocked(f) \
  81. ( ((f)->rpos < (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
  82. #define putc_unlocked(c, f) ( ((c)!=(f)->lbf && (f)->wpos<(f)->wend) \
  83. ? *(f)->wpos++ = (c) : __overflow((f),(c)) )
  84. /* Caller-allocated FILE * operations */
  85. FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
  86. int __fclose_ca(FILE *);
  87. #endif