84
* ---------------------------------------------------------------
89
* The filter may contain one '*' as wildcard.
91
void CSDirectory::open()
94
if (!(iDir = opendir(iPath->getCString())))
95
CSException::throwFileError(CS_CONTEXT, iPath->getCString(), errno);
99
void CSDirectory::close()
109
bool CSDirectory::next()
112
struct dirent *result;
116
err = readdir_r(iDir, &iEntry->entry, &result);
119
CSException::throwFileError(CS_CONTEXT, iPath->getCString(), err);
122
/* Filter out '.' and '..': */
123
if (iEntry->entry.d_name[0] == '.') {
124
if (iEntry->entry.d_name[1] == '.') {
125
if (iEntry->entry.d_name[2] == '\0')
129
if (iEntry->entry.d_name[1] == '\0')
135
return_(result ? true : false);
138
void CSDirectory::getFilePath(char *path, size_t size)
140
cs_strcpy(size, path, iPath->getCString());
141
cs_add_dir_char(size, path);
142
cs_strcat(size, path, iEntry->entry.d_name);
145
68
void CSDirectory::deleteEntry()
147
70
char path[PATH_MAX];
150
getFilePath(path, PATH_MAX);
74
getEntryPath(path, PATH_MAX);
152
76
CSPath *cs_path = CSPath::newPath(path);
154
78
cs_path->removeFile();
160
84
const char *CSDirectory::name()
162
return iEntry->entry.d_name;
165
89
bool CSDirectory::isFile()
94
off64_t CSDirectory::getSize()
168
96
char path[PATH_MAX];
171
getFilePath(path, PATH_MAX);
173
if (stat(path, &sb) == -1) {
174
CSException::throwFileError(CS_CONTEXT, path, errno);
175
return false; // Never reached.
178
if ( sb.st_mode & S_IFDIR )
181
if (iEntry->entry.d_type & DT_DIR)
98
getEntryPath(path, PATH_MAX);
100
return CSPath::getSize(path);
187
103
void CSDirectory::info(bool *is_dir, off64_t *size, CSTime *mod_time)
189
105
char path[PATH_MAX];
107
getEntryPath(path, PATH_MAX);
109
CSPath::info(path, is_dir, size, mod_time);
112
bool CSDirectory::exists()
192
getFilePath(path, PATH_MAX);
194
CSPath *cs_path = CSPath::newPath(path);
196
cs_path->info(is_dir, size, mod_time);
118
path = CSPath::newPath(RETAIN(sd_path));
120
yup = path->exists();
202
125
CSDirectory *CSDirectory::newDirectory(CSString *path)
204
127
CSDirectory *dir;
210
size = pathconf(path->getCString(), _PC_NAME_MAX) + sizeof(struct dirent) + 1;
212
size = sizeof(struct dirent);
215
129
if (!(dir = new CSDirectory())) {
216
131
CSException::throwOSError(CS_CONTEXT, ENOMEM);
222
dir->iEntry = (union var_dirent *) cs_malloc(size);
137
CSDirectory *CSDirectory::newDirectory(CSPath *path)
143
dir = newDirectory(RETAIN(path->getString()));
228
CSDirectory *CSDirectory::newDirectory(CSPath *path)
148
CSDirectory *CSDirectory::newDirectory(const char *path)
230
CSString *str = path->getString();
234
return newDirectory(str);
150
return newDirectory(CSString::newString(path));