1 //----------------------------------------------------------------------------
2 // EDGE Filesystem Class
3 //----------------------------------------------------------------------------
4 //
5 // Copyright (c) 2003-2008 The EDGE Team.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 //----------------------------------------------------------------------------
18
19 #include "epi.h"
20
21 #include "file.h"
22 #include "filesystem.h"
23
24 #define MAX_MODE_CHARS 32
25
26 namespace epi
27 {
28
29 // A Filesystem Directory
30
filesystem_dir_c()31 filesystem_dir_c::filesystem_dir_c() : array_c(sizeof(filesys_direntry_c))
32 { }
33
~filesystem_dir_c()34 filesystem_dir_c::~filesystem_dir_c()
35 { }
36
AddEntry(filesys_direntry_c * fs_entry)37 bool filesystem_dir_c::AddEntry(filesys_direntry_c *fs_entry)
38 {
39 if (InsertObject(fs_entry) < 0)
40 return false;
41
42 return true;
43 }
44
CleanupObject(void * obj)45 void filesystem_dir_c::CleanupObject(void *obj)
46 { }
47
operator [](int idx)48 filesys_direntry_c *filesystem_dir_c::operator[](int idx)
49 {
50 return (filesys_direntry_c*)FetchObject(idx);
51 }
52
53
54 //----------------------------------------------------------------------------
55
56 // common functions
57
FS_Access(const char * name,unsigned int flags)58 bool FS_Access(const char *name, unsigned int flags)
59 {
60 SYS_ASSERT(name);
61
62 char mode[MAX_MODE_CHARS];
63
64 if (! FS_FlagsToAnsiMode(flags, mode))
65 return false;
66
67 FILE *fp = fopen(name, mode);
68 if (!fp)
69 return false;
70
71 fclose(fp);
72 return true;
73 }
74
FS_Open(const char * name,unsigned int flags)75 file_c* FS_Open(const char *name, unsigned int flags)
76 {
77 SYS_ASSERT(name);
78
79 char mode[MAX_MODE_CHARS];
80
81 if (! FS_FlagsToAnsiMode(flags, mode))
82 return NULL;
83
84 FILE *fp = fopen(name, mode);
85 if (!fp)
86 return NULL;
87
88 return new ansi_file_c(fp);
89 }
90
91 } // namespace epi
92
93 //--- editor settings ---
94 // vi:ts=4:sw=4:noexpandtab
95