new scanf implementation and corresponding integer parser/converter
[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 <sys/uio.h>
22 #include "syscall.h"
23 #include "libc.h"
24
25 #define UNGET 8
26
27 #define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
28 #define FUNLOCK(f) if (__need_unlock) __unlockfile((f)); else
29
30 #define F_PERM 1
31 #define F_NORD 4
32 #define F_NOWR 8
33 #define F_EOF 16
34 #define F_ERR 32
35 #define F_SVB 64
36
37 struct __FILE_s {
38         unsigned flags;
39         unsigned char *rpos, *rend;
40         int (*close)(FILE *);
41         unsigned char *wend, *wpos;
42         unsigned char *mustbezero_1;
43         unsigned char *wbase;
44         size_t (*read)(FILE *, unsigned char *, size_t);
45         size_t (*write)(FILE *, const unsigned char *, size_t);
46         off_t (*seek)(FILE *, off_t, int);
47         unsigned char *buf;
48         size_t buf_size;
49         FILE *prev, *next;
50         int fd;
51         int pipe_pid;
52         long lockcount;
53         short dummy3;
54         signed char mode;
55         signed char lbf;
56         int lock;
57         int waiters;
58         void *cookie;
59         off_t off;
60         int (*flush)(FILE *);
61         void *mustbezero_2;
62         unsigned char *shend;
63         off_t shlim, shcnt;
64 };
65
66 size_t __stdio_read(FILE *, unsigned char *, size_t);
67 size_t __stdio_write(FILE *, const unsigned char *, size_t);
68 size_t __stdout_write(FILE *, const unsigned char *, size_t);
69 off_t __stdio_seek(FILE *, off_t, int);
70 int __stdio_close(FILE *);
71
72 size_t __string_read(FILE *, unsigned char *, size_t);
73
74 int __toread(FILE *);
75 int __towrite(FILE *);
76
77 int __overflow(FILE *, int);
78 int __oflow(FILE *);
79 int __uflow(FILE *);
80 int __underflow(FILE *);
81
82 int __fseeko(FILE *, off_t, int);
83 int __fseeko_unlocked(FILE *, off_t, int);
84 off_t __ftello(FILE *);
85 off_t __ftello_unlocked(FILE *);
86 size_t __fwritex(const unsigned char *, size_t, FILE *);
87 int __putc_unlocked(int, FILE *);
88
89 FILE *__fdopen(int, const char *);
90
91 #define OFLLOCK() LOCK(&libc.ofl_lock)
92 #define OFLUNLOCK() UNLOCK(&libc.ofl_lock)
93
94 #define feof(f) ((f)->flags & F_EOF)
95 #define ferror(f) ((f)->flags & F_ERR)
96
97 #define getc_unlocked(f) \
98         ( ((f)->rpos < (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
99
100 #define putc_unlocked(c, f) ( ((c)!=(f)->lbf && (f)->wpos<(f)->wend) \
101         ? *(f)->wpos++ = (c) : __overflow((f),(c)) )
102
103 /* Caller-allocated FILE * operations */
104 FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
105 int __fclose_ca(FILE *);
106
107 #endif