-
Notifications
You must be signed in to change notification settings - Fork 1
/
ftype.cc
140 lines (112 loc) · 2.28 KB
/
ftype.cc
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#define ICI_CORE
#include "ftype.h"
namespace ici
{
int ftype::getch(void *)
{
return -1;
}
int ftype::ungetch(int, void *)
{
return -1;
}
int ftype::flush(void *)
{
return 0;
}
int ftype::close(void *)
{
return 0;
}
int long ftype::seek(void *, long, int)
{
return -1l;
}
int ftype::eof(void *)
{
return 0;
}
int ftype::read(void *, long, void *)
{
return 0;
}
int ftype::write(const void *, long, void *)
{
return 0;
}
int ftype::fileno(void *)
{
return -1;
}
int ftype::setvbuf(void *, char *, int, size_t)
{
return -1;
}
//================================================================
stdio_ftype::stdio_ftype()
: ftype(nomutex)
{
}
int stdio_ftype::getch(void *file)
{
signals_invoke_immediately(1);
auto result = ::fgetc((FILE *)file);
signals_invoke_immediately(0);
return result;
}
int stdio_ftype::ungetch(int c, void *file)
{
return ::ungetc(c, (FILE *)file);
}
int stdio_ftype::flush(void *file)
{
return ::fflush((FILE *)file);
}
int stdio_ftype::close(void *file)
{
return ::fclose((FILE *)file);
}
long stdio_ftype::seek(void *file, long offset, int whence)
{
if (::fseek((FILE *)file, offset, whence) == -1)
{
set_error("seek failed");
return -1;
}
return ::ftell((FILE *)file);
}
int stdio_ftype::eof(void *file)
{
return ::feof((FILE *)file);
}
int stdio_ftype::read(void *buf, long n, void *file)
{
signals_invoke_immediately(1);
auto result = ::fread(buf, 1, n, (FILE *)file);
signals_invoke_immediately(0);
return result;
}
int stdio_ftype::write(const void *buf, long n, void *file)
{
signals_invoke_immediately(1);
auto result = ::fwrite(buf, 1, (size_t)n, (FILE *)file);
signals_invoke_immediately(0);
return result;
}
int stdio_ftype::fileno(void *f)
{
return ::fileno((FILE *)f);
}
int stdio_ftype::setvbuf(void *f, char *buf, int typ, size_t size)
{
return ::setvbuf((FILE *)f, buf, typ, size);
}
//================================================================
int popen_ftype::close(void *file)
{
return ::pclose((FILE *)file);
}
//================================================================
ftype *stdio_ftype = instanceof <class stdio_ftype>();
ftype *popen_ftype = instanceof <class popen_ftype>();
} // namespace ici