1
0

stdio_impl.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef _STDIO_IMPL_H
  2. #define _STDIO_IMPL_H
  3. #include <stdio.h>
  4. #include "syscall.h"
  5. #include "libc.h"
  6. #define UNGET 8
  7. #define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0)
  8. #define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
  9. #define FUNLOCK(f) if (__need_unlock) __unlockfile((f)); else
  10. #define F_PERM 1
  11. #define F_NORD 4
  12. #define F_NOWR 8
  13. #define F_EOF 16
  14. #define F_ERR 32
  15. #define F_SVB 64
  16. struct __FILE_s {
  17. unsigned flags;
  18. unsigned char *rpos, *rend;
  19. int (*close)(FILE *);
  20. unsigned char *wend, *wpos;
  21. unsigned char *mustbezero_1;
  22. unsigned char *wbase;
  23. size_t (*read)(FILE *, unsigned char *, size_t);
  24. size_t (*write)(FILE *, const unsigned char *, size_t);
  25. off_t (*seek)(FILE *, off_t, int);
  26. unsigned char *buf;
  27. size_t buf_size;
  28. FILE *prev, *next;
  29. int fd;
  30. int pipe_pid;
  31. long lockcount;
  32. short dummy3;
  33. signed char mode;
  34. signed char lbf;
  35. int lock;
  36. int waiters;
  37. void *cookie;
  38. off_t off;
  39. char *getln_buf;
  40. void *mustbezero_2;
  41. unsigned char *shend;
  42. off_t shlim, shcnt;
  43. };
  44. size_t __stdio_read(FILE *, unsigned char *, size_t);
  45. size_t __stdio_write(FILE *, const unsigned char *, size_t);
  46. size_t __stdout_write(FILE *, const unsigned char *, size_t);
  47. off_t __stdio_seek(FILE *, off_t, int);
  48. int __stdio_close(FILE *);
  49. size_t __string_read(FILE *, unsigned char *, size_t);
  50. int __toread(FILE *);
  51. int __towrite(FILE *);
  52. #if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303)
  53. __attribute__((visibility("protected")))
  54. #endif
  55. int __overflow(FILE *, int), __uflow(FILE *);
  56. int __fseeko(FILE *, off_t, int);
  57. int __fseeko_unlocked(FILE *, off_t, int);
  58. off_t __ftello(FILE *);
  59. off_t __ftello_unlocked(FILE *);
  60. size_t __fwritex(const unsigned char *, size_t, FILE *);
  61. int __putc_unlocked(int, FILE *);
  62. FILE *__fdopen(int, const char *);
  63. int __fmodeflags(const char *);
  64. #define OFLLOCK() LOCK(libc.ofl_lock)
  65. #define OFLUNLOCK() UNLOCK(libc.ofl_lock)
  66. #define feof(f) ((f)->flags & F_EOF)
  67. #define ferror(f) ((f)->flags & F_ERR)
  68. #define getc_unlocked(f) \
  69. ( ((f)->rpos < (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
  70. #define putc_unlocked(c, f) ( ((c)!=(f)->lbf && (f)->wpos<(f)->wend) \
  71. ? *(f)->wpos++ = (c) : __overflow((f),(c)) )
  72. /* Caller-allocated FILE * operations */
  73. FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
  74. int __fclose_ca(FILE *);
  75. #endif