|
#ifndef KIfile
#define KIfile
#endif
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
#ifndef KIfile
#define KIfile
#include <k/type.h>
#include <k/io.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum kfcond {
kfcond_ok = 0,
kfcond_fail = 1,
// an unspecified error occurred
kfcond_bad_domain,
// the values passed to the function are not within
// that function's domain and are invalid
kfcond_overstep,
// kfstep() was only able to move part of the
// distance requested
kfcond_bad_index,
// the requested index is past the end of the file
kfcond_notfound,
// the specified object could not be found
kfcond_unauth,
// you do not have permission to open this object
kfcond_mem,
// there is not enough memory to complete the
// requested operation
} kfcond;
typedef enum kfile_kind {
kfile_closed,
// the file object does not refer to an open file
kfile_open,
// the file object refers to an open file
} kfile_kind;
enum kfopen {
/* file open modes */
kf_read = 1 << 9, kf_write = 1 << 10,
kf_ascii = 1 << 11, kf_new = 1 << 12,
kf_create = 1 << 13, kf_load = 1 << 14,
kf_top = 1 << 15, kf_end = 1 << 16,
kf_wipe = 1 << 17, kf_map = 1 << 18,
/* file permission flags */
kf_ur = 4 << 6, kf_uw = 2 << 6, kf_ux = 1 << 6,
kf_gr = 4 << 3, kf_gw = 2 << 3, kf_gx = 1 << 3,
kf_or = 4 << 0, kf_ow = 2 << 0, kf_ox = 1 << 0,
}
typedef struct kfile {
enum kfile_kind kind;
enum kfopen mode;
kiochan chan;
u8* content;
} kfile;
enum kfset_mode {
kfset_none, // do not move
kfset_top, // move to x bytes from the start of the file
kfset_end, // move to x bytes from the end of the file
}
enum kfplace {
kfplace_none,
kfplace_conf,
kfplace_home,
kfplace_desk,
kfplace_dl,
kfplace_img,
kfplace_vid,
kfplace_msc,
kfplace_doc,
kfplace_dat,
kfplace_share,
kfplace_share_global,
kfplace_cache,
}
kfile kfplace(enum kfplace location, const char* file, enum kfopen mode);
kfile kfopen (const char* file, enum kfopen mode);
kfile kfopens(const ksraw file, enum kfopen mode);
kfcond kfset (struct kfile file, enum kfset_mode mode, sz position);
kfcond kfstep(struct kfile file, offset position);
kfcond kfshred(struct kfile file, sz count);
#ifdef __cplusplus
}
#endif
#endif
|