Angband
z-file.h
Go to the documentation of this file.
1 
18 #ifndef INCLUDED_Z_FILE_H
19 #define INCLUDED_Z_FILE_H
20 
21 #include "h-basic.h"
22 
34 extern int player_uid;
35 extern int player_egid;
36 
49 void safe_setuid_grab(void);
50 void safe_setuid_drop(void);
51 
52 
65 size_t path_build(char *buf, size_t len, const char *base, const char *leaf);
66 
71 size_t path_filename_index( const char *path );
72 
84 typedef struct ang_file ang_file;
85 
89 typedef enum
90 {
94 } file_mode;
95 
99 typedef enum
100 {
105 } file_type;
106 
107 
113 bool file_exists(const char *fname);
114 
120 bool file_delete(const char *fname);
121 
127 bool file_move(const char *fname, const char *newname);
128 
132 bool file_newer(const char *first, const char *second);
133 
134 
152 ang_file *file_open(const char *buf, file_mode mode, file_type ftype);
153 
154 
158 extern void (*file_open_hook)(const char *path, file_type ftype);
159 
160 
166 bool file_close(ang_file *f);
167 
168 
177 void file_lock(ang_file *f);
178 void file_unlock(ang_file *f);
179 
180 
192 bool file_getl(ang_file *f, char *buf, size_t n);
193 
199 bool file_put(ang_file *f, const char *buf);
200 
204 bool file_putf(ang_file *f, const char *fmt, ...);
205 bool file_vputf(ang_file *f, const char *fmt, va_list vp);
206 
207 
214 bool file_skip(ang_file *f, int bytes);
215 
220 int file_read(ang_file *f, char *buf, size_t n);
221 
228 bool file_write(ang_file *f, const char *buf, size_t n);
229 
236 bool file_readc(ang_file *f, byte *b);
237 
243 bool file_writec(ang_file *f, byte b);
244 
245 
246 
256 bool dir_exists(const char *dirname);
257 
263 bool dir_create(const char *dirname);
264 
268 typedef struct ang_dir ang_dir;
269 
270 
279 ang_dir *my_dopen(const char *dirname);
280 
290 bool my_dread(ang_dir *dir, char *fname, size_t len);
291 
295 void my_dclose(ang_dir *dir);
296 
297 #endif /* INCLUDED_Z_FILE_H */
char ** path
Definition: main.c:147
void file_unlock(ang_file *f)
Unlock a file locked using file_lock().
Definition: z-file.c:463
char * dirname
Definition: z-file.c:806
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
Definition: z-file.h:101
bool file_exists(const char *fname)
Utility functions.
Definition: z-file.c:307
Definition: z-file.h:104
Directory scanning API
Definition: z-file.c:803
bool file_delete(const char *fname)
Tries to delete fname.
Definition: z-file.c:275
Definition: z-file.c:261
file_mode
Specifies what kind of access is required to a file.
Definition: z-file.h:89
bool dir_create(const char *dirname)
Create's the given directory, creating intermediate directories if needed and possible.
Definition: z-file.c:663
ang_dir * my_dopen(const char *dirname)
Opens a directory handle.
Definition: z-file.c:809
void safe_setuid_drop(void)
Drop permissions.
Definition: z-file.c:69
char * fname
Definition: z-file.c:264
bool file_readc(ang_file *f, byte *b)
Read a byte from the file represented by f and place it at the location specified by 'b'...
Definition: z-file.c:490
Definition: z-file.h:102
uint8_t byte
Definition: h-basic.h:167
void file_lock(ang_file *f)
File locking.
Definition: z-file.c:447
size_t path_build(char *buf, size_t len, const char *base, const char *leaf)
Path building code
Definition: z-file.c:170
bool file_write(ang_file *f, const char *buf, size_t n)
Write the first n bytes following the pointer buf to the file represented by f.
Definition: z-file.c:525
ang_file * file_open(const char *buf, file_mode mode, file_type ftype)
File handle creation.
Definition: z-file.c:374
The lowest level header.
Definition: z-file.h:93
bool my_dread(ang_dir *dir, char *fname, size_t len)
Reads a directory entry.
Definition: z-file.c:833
png_bytep buf
Definition: libpng12/png.h:2815
bool file_newer(const char *first, const char *second)
Returns true if the file first is newer than second.
Definition: z-file.c:345
bool file_putf(ang_file *f, const char *fmt,...)
Format (using strnfmt) the given args, and then call file_put().
Definition: z-file.c:616
int file_read(ang_file *f, char *buf, size_t n)
Reads n bytes from file 'f' into buffer 'buf'.
Definition: z-file.c:512
file_mode mode
Definition: z-file.c:265
size_t path_filename_index(const char *path)
Return the index of the filename in a path, using PATH_SEPC.
Definition: z-file.c:219
Definition: z-file.h:92
file_type
Specifies what kind of thing a file is, when writing.
Definition: z-file.h:99
void(* file_open_hook)(const char *path, file_type ftype)
Platform hook for file_open.
Definition: z-file.c:368
int player_uid
Permissions code
Definition: z-file.c:60
Definition: z-file.h:103
bool file_getl(ang_file *f, char *buf, size_t n)
Line-based IO.
Definition: z-file.c:540
int player_egid
Definition: z-file.c:61
bool file_close(ang_file *f)
Attempt to close the file handle f.
Definition: z-file.c:429
bool file_skip(ang_file *f, int bytes)
Byte-based IO.
Definition: z-file.c:482
bool file_move(const char *fname, const char *newname)
Moves the file fname to newname.
Definition: z-file.c:288
bool file_vputf(ang_file *f, const char *fmt, va_list vp)
Append a formatted line of text to the end of file 'f'.
Definition: z-file.c:636
void safe_setuid_grab(void)
Drop or grab privileges.
Definition: z-file.c:90
Definition: z-file.h:91
bool dir_exists(const char *dirname)
Directory code
Definition: z-file.c:647
void my_dclose(ang_dir *dir)
Close a directory handle.
Definition: z-file.c:866
bool file_put(ang_file *f, const char *buf)
Write the string pointed to by buf to the file represented by f.
Definition: z-file.c:599
bool file_writec(ang_file *f, byte b)
Write the byte b to the file represented by f.
Definition: z-file.c:504