-
Notifications
You must be signed in to change notification settings - Fork 1
/
file.h
109 lines (96 loc) · 2.31 KB
/
file.h
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
// -*- mode:c++ -*-
#ifndef ICI_FILE_H
#define ICI_FILE_H
#include "ftype.h"
#include "object.h"
namespace ici
{
/*
* The following portion of this file exports to ici.h. --ici.h-start--
*/
struct file : object
{
void *f_file;
ftype *f_type;
str *f_name; /* Reasonable name to call it by. */
object *f_ref;
inline int flags() const
{
return f_type->flags;
}
inline int getch()
{
return f_type->getch(f_file);
}
inline int ungetch(int c)
{
return f_type->ungetch(c, f_file);
}
inline int flush()
{
return f_type->flush(f_file);
}
inline int close()
{
return f_type->close(f_file);
}
inline long seek(long o, int w)
{
return f_type->seek(f_file, o, w);
}
inline int eof()
{
return f_type->eof(f_file);
}
inline int read(void *p, long n)
{
return f_type->read(p, n, f_file);
}
inline int write(const void *p, long n)
{
return f_type->write(p, n, f_file);
}
inline int fileno()
{
return f_type->fileno(f_file);
}
inline int setvbuf(char *p, int t, size_t z)
{
return f_type->setvbuf(f_file, p, t, z);
}
static constexpr int closed = 0x20; /* File is closed. */
static constexpr int noclose = 0x40; /* Don't close on object free. */
};
/*
* f_ref An object for this file object to reference.
* This is used to reference the string when we
* are treating a string as a file, and other cases,
* to keep the object referenced. Basically if f_file
* is an implicit reference to some object. May be nullptr.
*/
inline file *fileof(object *o)
{
return o->as<file>();
}
inline bool isfile(object *o)
{
return o->hastype(TC_FILE);
}
class file_type : public type
{
public:
file_type() : type("file", sizeof(struct file))
{
}
size_t mark(object *o) override;
void free(object *o) override;
int cmp(object *o1, object *o2) override;
object *fetch(object *o, object *k) override;
int save(archiver *, object *) override;
object *restore(archiver *) override;
};
/*
* End of ici.h export. --ici.h-end--
*/
} // namespace ici
#endif /* ICI_FILE_H */