1 |
/* |
2 |
* HT Editor |
3 |
* file.h |
4 |
* |
5 |
* file system functions |
6 |
* |
7 |
* Copyright (C) 1999-2002 Stefan Weyergraf |
8 |
* |
9 |
* This program is free software; you can redistribute it and/or modify |
10 |
* it under the terms of the GNU General Public License version 2 as |
11 |
* published by the Free Software Foundation. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 |
*/ |
22 |
|
23 |
#ifndef __FILE_H__ |
24 |
#define __FILE_H__ |
25 |
|
26 |
/* Note: all functions only take absolute dir/filenames ! */ |
27 |
|
28 |
#include "types.h" |
29 |
#include "fileofs.h" |
30 |
|
31 |
//#include <dirent.h> |
32 |
#include <sys/types.h> |
33 |
#include <time.h> |
34 |
|
35 |
#ifdef PATH_MAX |
36 |
#define HT_NAME_MAX PATH_MAX /* DJGPP at least */ |
37 |
#else |
38 |
#ifdef MAXNAMLEN |
39 |
#define HT_NAME_MAX MAXNAMLEN /* some BSD... */ |
40 |
#else |
41 |
#ifdef NAME_MAX |
42 |
#define HT_NAME_MAX NAME_MAX /* POSIX and friends... */ |
43 |
#else |
44 |
#define HT_NAME_MAX 260 /* unknown... */ |
45 |
#endif |
46 |
#endif |
47 |
#endif |
48 |
|
49 |
#define HT_S_IFREG 0x1000 |
50 |
#define HT_S_IFBLK 0x2000 |
51 |
#define HT_S_IFCHR 0x3000 |
52 |
#define HT_S_IFDIR 0x4000 |
53 |
#define HT_S_IFFIFO 0x5000 |
54 |
#define HT_S_IFLNK 0x6000 |
55 |
#define HT_S_IFSOCK 0x7000 |
56 |
|
57 |
#define HT_S_IFMT 0xf000 |
58 |
|
59 |
#define HT_S_ISREG(m) (((m) & HT_S_IFMT) == HT_S_IFREG) |
60 |
#define HT_S_ISBLK(m) (((m) & HT_S_IFMT) == HT_S_IFBLK) |
61 |
#define HT_S_ISCHR(m) (((m) & HT_S_IFMT) == HT_S_IFCHR) |
62 |
#define HT_S_ISDIR(m) (((m) & HT_S_IFMT) == HT_S_IFDIR) |
63 |
#define HT_S_ISFIFO(m) (((m) & HT_S_IFMT) == HT_S_IFFIFO) |
64 |
#define HT_S_ISLNK(m) (((m) & HT_S_IFMT) == HT_S_IFLNK) |
65 |
#define HT_S_ISSOCK(m) (((m) & HT_S_IFMT) == HT_S_IFSOCK) |
66 |
|
67 |
#define HT_S_IRUSR 0x0100 |
68 |
#define HT_S_IRGRP 0x0020 |
69 |
#define HT_S_IROTH 0x0004 |
70 |
#define HT_S_IWUSR 0x0080 |
71 |
#define HT_S_IWGRP 0x0010 |
72 |
#define HT_S_IWOTH 0x0002 |
73 |
#define HT_S_IXUSR 0x0040 |
74 |
#define HT_S_IXGRP 0x0008 |
75 |
#define HT_S_IXOTH 0x0001 |
76 |
#define HT_S_IRWXU (HT_S_IRUSR || HT_S_IWUSR || HT_S_IXUSR) |
77 |
#define HT_S_IRWXG (HT_S_IRGRP || HT_S_IWGRP || HT_S_IXGRP) |
78 |
#define HT_S_IRWXO (HT_S_IROTH || HT_S_IWOTH || HT_S_IXOTH) |
79 |
|
80 |
#define pstat_ctime 0x00000001 |
81 |
#define pstat_mtime 0x00000002 |
82 |
#define pstat_atime 0x00000004 |
83 |
#define pstat_uid 0x00000008 |
84 |
#define pstat_gid 0x00000010 |
85 |
#define pstat_mode_usr 0x00000020 |
86 |
#define pstat_mode_grp 0x00000040 |
87 |
#define pstat_mode_oth 0x00000080 |
88 |
#define pstat_mode_r 0x00000100 |
89 |
#define pstat_mode_w 0x00000200 |
90 |
#define pstat_mode_x 0x00000400 |
91 |
#define pstat_mode_type 0x00000800 |
92 |
#define pstat_size 0x00001000 |
93 |
#define pstat_inode 0x00002000 |
94 |
#define pstat_cluster 0x00004000 |
95 |
#define pstat_fsid 0x00008000 |
96 |
#define pstat_desc 0x00010000 |
97 |
|
98 |
#define pstat_mode_all (pstat_mode_usr|pstat_mode_grp|pstat_mode_oth|pstat_mode_r|pstat_mode_w|pstat_mode_x|pstat_mode_type) |
99 |
|
100 |
struct pstat_t { |
101 |
uint32 caps; |
102 |
time_t ctime; |
103 |
time_t mtime; |
104 |
time_t atime; |
105 |
uint uid; |
106 |
uint gid; |
107 |
mode_t mode; // S_ISUID, S_ISGID, S_I[RWX](USR|GRP|OTH) |
108 |
uint64 size; |
109 |
union { |
110 |
uint inode; |
111 |
uint cluster; |
112 |
uint fsid; |
113 |
}; |
114 |
char desc[32]; |
115 |
}; |
116 |
|
117 |
struct pfind_t { |
118 |
const char *name; |
119 |
pstat_t stat; |
120 |
void *findstate; |
121 |
}; |
122 |
|
123 |
typedef bool (*is_path_delim)(char c); |
124 |
|
125 |
#define SYS_OPEN_READ 1 |
126 |
#define SYS_OPEN_WRITE 2 |
127 |
#define SYS_OPEN_CREATE 4 |
128 |
|
129 |
#define SYS_SEEK_SET 1 |
130 |
#define SYS_SEEK_REL 2 |
131 |
#define SYS_SEEK_END 3 |
132 |
|
133 |
#define SYS_FILE void |
134 |
|
135 |
|
136 |
/* system-independent (implementation in sys.cc) */ |
137 |
int sys_basename(char *result, const char *filename); |
138 |
int sys_dirname(char *result, const char *filename); |
139 |
int sys_relname(char *result, const char *filename, const char *cwd); |
140 |
int sys_common_canonicalize(char *result, const char *in_name, const char *cwd, is_path_delim delim); |
141 |
char * sys_filename_suffix(const char *fn); |
142 |
int sys_tmpfile_fd(); |
143 |
|
144 |
/* system-dependent (implementation in $MYSYSTEM/ *.cc) */ |
145 |
int sys_canonicalize(char *result, const char *filename); |
146 |
int sys_file_mode(int mode); |
147 |
int sys_findclose(pfind_t &pfind); |
148 |
int sys_findfirst(pfind_t &pfind, const char *dirname); |
149 |
int sys_findnext(pfind_t &pfind); |
150 |
int sys_pstat(pstat_t &s, const char *filename); |
151 |
int sys_pstat_fd(pstat_t &s, int fd); |
152 |
int sys_truncate(const char *filename, FileOfs ofs); |
153 |
int sys_truncate_fd(int fd, FileOfs ofs); |
154 |
int sys_deletefile(const char *filename); |
155 |
bool sys_is_path_delim(char c); |
156 |
int sys_filename_cmp(const char *a, const char *b); |
157 |
bool sys_filename_is_absolute(const char *filename); |
158 |
|
159 |
SYS_FILE * sys_fopen(const char *filename, int openmode); |
160 |
void sys_fclose(SYS_FILE *file); |
161 |
int sys_fread(SYS_FILE *file, byte *buf, int size); |
162 |
int sys_fwrite(SYS_FILE *file, byte *buf, int size); |
163 |
int sys_fseek(SYS_FILE *file, FileOfs newofs, int seekmode = SYS_SEEK_SET); |
164 |
FileOfs sys_ftell(SYS_FILE *file); |
165 |
void sys_flush(SYS_FILE *file); |
166 |
//int sys_geterror(); |
167 |
|
168 |
#endif /* __FILE_H__ */ |