master
1#ifndef _STDIO_IMPL_H
2#define _STDIO_IMPL_H
3
4#include <stdio.h>
5#include "syscall.h"
6
7#define UNGET 8
8
9#define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0)
10#define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
11#define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0)
12
13#define F_PERM 1
14#define F_NORD 4
15#define F_NOWR 8
16#define F_EOF 16
17#define F_ERR 32
18#define F_SVB 64
19#define F_APP 128
20
21struct _IO_FILE {
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 int mode;
38 volatile int lock;
39 int lbf;
40 void *cookie;
41 off_t off;
42 char *getln_buf;
43 void *mustbezero_2;
44 unsigned char *shend;
45 off_t shlim, shcnt;
46 FILE *prev_locked, *next_locked;
47 struct __locale_struct *locale;
48};
49
50extern hidden FILE *volatile __stdin_used;
51extern hidden FILE *volatile __stdout_used;
52extern hidden FILE *volatile __stderr_used;
53
54hidden int __lockfile(FILE *);
55hidden void __unlockfile(FILE *);
56
57hidden size_t __stdio_read(FILE *, unsigned char *, size_t);
58hidden size_t __stdio_write(FILE *, const unsigned char *, size_t);
59hidden size_t __stdout_write(FILE *, const unsigned char *, size_t);
60hidden off_t __stdio_seek(FILE *, off_t, int);
61hidden int __stdio_close(FILE *);
62
63hidden int __toread(FILE *);
64hidden int __towrite(FILE *);
65
66hidden void __stdio_exit(void);
67hidden void __stdio_exit_needed(void);
68
69#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303)
70__attribute__((visibility("protected")))
71#endif
72int __overflow(FILE *, int), __uflow(FILE *);
73
74hidden int __fseeko(FILE *, off_t, int);
75hidden int __fseeko_unlocked(FILE *, off_t, int);
76hidden off_t __ftello(FILE *);
77hidden off_t __ftello_unlocked(FILE *);
78hidden size_t __fwritex(const unsigned char *, size_t, FILE *);
79hidden int __putc_unlocked(int, FILE *);
80
81hidden FILE *__fdopen(int, const char *);
82hidden int __fmodeflags(const char *);
83
84hidden FILE *__ofl_add(FILE *f);
85hidden FILE **__ofl_lock(void);
86hidden void __ofl_unlock(void);
87
88struct __pthread;
89hidden void __register_locked_file(FILE *, struct __pthread *);
90hidden void __unlist_locked_file(FILE *);
91hidden void __do_orphaned_stdio_locks(void);
92
93#define MAYBE_WAITERS 0x40000000
94
95hidden void __getopt_msg(const char *, const char *, const char *, size_t);
96
97#define feof(f) ((f)->flags & F_EOF)
98#define ferror(f) ((f)->flags & F_ERR)
99
100#define getc_unlocked(f) \
101 ( ((f)->rpos != (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
102
103#define putc_unlocked(c, f) \
104 ( (((unsigned char)(c)!=(f)->lbf && (f)->wpos!=(f)->wend)) \
105 ? *(f)->wpos++ = (unsigned char)(c) \
106 : __overflow((f),(unsigned char)(c)) )
107
108/* Caller-allocated FILE * operations */
109hidden FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
110hidden int __fclose_ca(FILE *);
111
112#endif