master
  1#ifndef _STDIO_IMPL_H
  2#define _STDIO_IMPL_H
  3
  4#include <stdio.h>
  5#if defined(__wasilibc_unmodified_upstream)
  6#include "syscall.h"
  7#endif
  8
  9#define UNGET 8
 10
 11#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
 12#define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0)
 13#define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
 14#define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0)
 15#else
 16// No locking needed.
 17#define FFINALLOCK(f) ((void)(f))
 18#define FLOCK(f) ((void)(f))
 19#define FUNLOCK(f) ((void)(f))
 20#endif
 21
 22#define F_PERM 1
 23#define F_NORD 4
 24#define F_NOWR 8
 25#define F_EOF 16
 26#define F_ERR 32
 27#define F_SVB 64
 28#define F_APP 128
 29
 30struct _IO_FILE {
 31	unsigned flags;
 32	unsigned char *rpos, *rend;
 33	int (*close)(FILE *);
 34	unsigned char *wend, *wpos;
 35#ifdef __wasilibc_unmodified_upstream // WASI doesn't need backwards-compatibility fields.
 36	unsigned char *mustbezero_1;
 37#endif
 38	unsigned char *wbase;
 39	size_t (*read)(FILE *, unsigned char *, size_t);
 40	size_t (*write)(FILE *, const unsigned char *, size_t);
 41	off_t (*seek)(FILE *, off_t, int);
 42	unsigned char *buf;
 43	size_t buf_size;
 44	FILE *prev, *next;
 45	int fd;
 46#ifdef __wasilibc_unmodified_upstream // WASI has no popen
 47	int pipe_pid;
 48#endif
 49#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
 50	long lockcount;
 51#endif
 52	int mode;
 53#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
 54	volatile int lock;
 55#endif
 56	int lbf;
 57	void *cookie;
 58	off_t off;
 59	char *getln_buf;
 60#ifdef __wasilibc_unmodified_upstream // WASI doesn't need backwards-compatibility fields.
 61	void *mustbezero_2;
 62#endif
 63	unsigned char *shend;
 64	off_t shlim, shcnt;
 65#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
 66	FILE *prev_locked, *next_locked;
 67#endif
 68	struct __locale_struct *locale;
 69};
 70
 71extern hidden FILE *volatile __stdin_used;
 72extern hidden FILE *volatile __stdout_used;
 73extern hidden FILE *volatile __stderr_used;
 74
 75#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
 76hidden int __lockfile(FILE *);
 77hidden void __unlockfile(FILE *);
 78#endif
 79
 80hidden size_t __stdio_read(FILE *, unsigned char *, size_t);
 81hidden size_t __stdio_write(FILE *, const unsigned char *, size_t);
 82hidden size_t __stdout_write(FILE *, const unsigned char *, size_t);
 83hidden off_t __stdio_seek(FILE *, off_t, int);
 84hidden int __stdio_close(FILE *);
 85
 86hidden int __toread(FILE *);
 87hidden int __towrite(FILE *);
 88
 89hidden void __stdio_exit(void);
 90hidden void __stdio_exit_needed(void);
 91
 92#ifdef __wasilibc_unmodified_upstream // wasm has no "protected" visibility
 93#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303)
 94__attribute__((visibility("protected")))
 95#endif
 96#endif
 97int __overflow(FILE *, int), __uflow(FILE *);
 98
 99hidden int __fseeko(FILE *, off_t, int);
100hidden int __fseeko_unlocked(FILE *, off_t, int);
101hidden off_t __ftello(FILE *);
102hidden off_t __ftello_unlocked(FILE *);
103hidden size_t __fwritex(const unsigned char *, size_t, FILE *);
104hidden int __putc_unlocked(int, FILE *);
105
106hidden FILE *__fdopen(int, const char *);
107hidden int __fmodeflags(const char *);
108
109hidden FILE *__ofl_add(FILE *f);
110hidden FILE **__ofl_lock(void);
111hidden void __ofl_unlock(void);
112
113struct __pthread;
114hidden void __register_locked_file(FILE *, struct __pthread *);
115hidden void __unlist_locked_file(FILE *);
116hidden void __do_orphaned_stdio_locks(void);
117
118#define MAYBE_WAITERS 0x40000000
119
120hidden void __getopt_msg(const char *, const char *, const char *, size_t);
121
122#define feof(f) ((f)->flags & F_EOF)
123#define ferror(f) ((f)->flags & F_ERR)
124
125#define getc_unlocked(f) \
126	( ((f)->rpos != (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
127
128#define putc_unlocked(c, f) \
129	( (((unsigned char)(c)!=(f)->lbf && (f)->wpos!=(f)->wend)) \
130	? *(f)->wpos++ = (unsigned char)(c) \
131	: __overflow((f),(unsigned char)(c)) )
132
133/* Caller-allocated FILE * operations */
134hidden FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
135hidden int __fclose_ca(FILE *);
136
137#endif