4e6d3503c2d39393157e6407dd4f1256dd170018
[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) ((libc.lockfile && (f)->owner>=0) ? (libc.lockfile((f)),0) : 0)
27 #define FUNLOCK(f) ((f)->lockcount && (--(f)->lockcount || ((f)->owner=(f)->lock=0)))
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 *cookie;
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         int owner;
63 };
64
65 size_t __stdio_read(FILE *, unsigned char *, size_t);
66 size_t __stdio_write(FILE *, const unsigned char *, size_t);
67 off_t __stdio_seek(FILE *, off_t, int);
68 int __stdio_close(FILE *);
69
70 int __overflow(FILE *, int);
71 int __oflow(FILE *);
72 int __uflow(FILE *);
73 int __underflow(FILE *);
74
75 int __fseeko(FILE *, off_t, int);
76 int __fseeko_unlocked(FILE *, off_t, int);
77 off_t __ftello(FILE *);
78 off_t __ftello_unlocked(FILE *);
79 size_t __fwritex(const unsigned char *, size_t, FILE *);
80 int __putc_unlocked(int, FILE *);
81
82 FILE *__fdopen(int, const char *);
83
84 #define OFLLOCK() LOCK(&libc.ofl_lock)
85 #define OFLUNLOCK() UNLOCK(&libc.ofl_lock)
86 #define ofl_head (libc.ofl_head)
87
88 #define feof(f) ((f)->flags & F_EOF)
89 #define ferror(f) ((f)->flags & F_ERR)
90
91 /* Caller-allocated FILE * operations */
92 FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
93 int __fclose_ca(FILE *);
94
95 #endif