1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "strbuf.h"
struct strbuf_file {
struct strbuf input;
int has_error;
int fd;
};
struct strbuf_file *sfdopen(int fd, const char *mode);
int sfclose(struct strbuf_file *sf);
int sfprintf(struct strbuf_file *sf, const char *fmt, ...);
void sfclearerr(struct strbuf_file *sf);
int sfread(char *buf, int size, int n, struct strbuf_file *sf);
char *sfgets(char *buf, int size, struct strbuf_file *sf);
int sfgetc(struct strbuf_file *sf);
#ifdef REPLACE_STDIO
#ifdef FILE
#undef FILE
#endif
#define FILE struct strbuf_file
#ifdef fdopen
#undef fdopen
#endif
#define fdopen(fd,mode) sfdopen(fd,mode)
#ifdef fclose
#undef fclose
#endif
#define fclose(fp) sfclose(fp)
#ifdef fprintf
#undef fprintf
#endif
#define fprintf sfprintf
#ifdef fread
#undef fread
#endif
#define fread(buf,s,n,fp) sfread(buf,s,n,fp)
#ifdef clearerr
#undef clearerr
#endif
#define clearerr(fp) sfclearerr(fp)
#ifdef ferror
#undef ferror
#endif
#define ferror(fp) ((fp)->has_error)
#ifdef fgets
#undef fgets
#endif
#define fgets(buf,n,fp) sfgets(buf,n,fp)
#ifdef getc
#undef getc
#endif
#define getc(fp) sfgetc(fp)
#ifdef fflush
#undef fflush
#endif
#define fflush(fp) 0
#endif
|