1e9159f6f2443bd0eba52598c76159d1de840ec0
[musl] / src / internal / stdio_impl.h
1 #ifndef _STDIO_IMPL_H
2 #define _STDIO_IMPL_H
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stddef.h>
7 #include <stdarg.h>
8 #include <string.h>
9 #include <inttypes.h>
10 #include <wchar.h>
11 #include <unistd.h>
12 #include <fcntl.h>
13 #include <limits.h>
14 #include <errno.h>
15 #include <termios.h>
16 #include <sys/ioctl.h>
17 #include <ctype.h>
18 #include <sys/wait.h>
19 #include <math.h>
20 #include <float.h>
21 #include "syscall.h"
22 #include "libc.h"
23
24 #define UNGET 4
25
26 #define FLOCK(f) LOCK(&f->lock)
27 #define FUNLOCK(f) UNLOCK(&f->lock)
28
29 #define F_PERM 1
30 #define F_NORD 4
31 #define F_NOWR 8
32 #define F_EOF 16
33 #define F_ERR 32
34
35 struct __FILE_s {
36         unsigned flags;
37         unsigned char *rpos, *rstop;
38         unsigned char *rend, *wend;
39         unsigned char *wpos, *wstop;
40         unsigned char *wbase;
41         unsigned char *dummy01[3];
42         unsigned char *buf;
43         size_t buf_size;
44         FILE *prev, *next;
45         int fd;
46         int pipe_pid;
47         long dummy2;
48         short dummy3;
49         char dummy4;
50         signed char lbf;
51         int lock;
52         int lockcount;
53         void *owner;
54         off_t off;
55         int (*flush)(FILE *);
56         void **wide_data; /* must be NULL */
57         size_t (*read)(FILE *, unsigned char *, size_t);
58         size_t (*write)(FILE *, const unsigned char *, size_t);
59         off_t (*seek)(FILE *, off_t, int);
60         int mode;
61         int (*close)(FILE *);
62 };
63
64 size_t __stdio_read(FILE *, unsigned char *, size_t);
65 size_t __stdio_write(FILE *, const unsigned char *, size_t);
66 off_t __stdio_seek(FILE *, off_t, int);
67 int __stdio_close(FILE *);
68
69 int __overflow(FILE *, int);
70 int __oflow(FILE *);
71 int __uflow(FILE *);
72 int __underflow(FILE *);
73
74 int __fseeko(FILE *, off_t, int);
75 int __fseeko_unlocked(FILE *, off_t, int);
76 off_t __ftello(FILE *);
77 off_t __ftello_unlocked(FILE *);
78 size_t __fwritex(const unsigned char *, size_t, FILE *);
79 int __putc_unlocked(int, FILE *);
80
81 FILE *__fdopen(int, const char *);
82
83 extern struct ofl
84 {
85         FILE *head;
86         int lock;
87 } __ofl;
88
89 #define OFLLOCK() LOCK(&__ofl.lock)
90 #define OFLUNLOCK() UNLOCK(&__ofl.lock)
91 #define ofl_head (__ofl.head)
92
93 #define feof(f) ((f)->flags & F_EOF)
94 #define ferror(f) ((f)->flags & F_ERR)
95
96 /* Caller-allocated FILE * operations */
97 FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
98 int __fclose_ca(FILE *);
99
100 #endif