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