mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 07:49:57 -04:00
DS: Support enumerating files in directory
This commit is contained in:
parent
93c18b6177
commit
e742a26739
@ -18,6 +18,6 @@ resource 'SIZE' (-1) {
|
|||||||
reserved,
|
reserved,
|
||||||
reserved,
|
reserved,
|
||||||
reserved,
|
reserved,
|
||||||
3584 * 1024,
|
8192 * 1024, // preferred (maximum) memory size
|
||||||
8192 * 1024
|
3584 * 1024, // minimum memory size (enough to load launcher)
|
||||||
};
|
};
|
||||||
|
@ -27,6 +27,6 @@ resource 'SIZE' (-1) {
|
|||||||
reserved,
|
reserved,
|
||||||
reserved,
|
reserved,
|
||||||
reserved,
|
reserved,
|
||||||
8192 * 1024,
|
8192 * 1024, // preferred (maximum) memory size
|
||||||
8192 * 1024
|
8192 * 1024 // minimum memory size
|
||||||
};
|
};
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <dirent.h>
|
||||||
#include "_PlatformConsole.h"
|
#include "_PlatformConsole.h"
|
||||||
|
|
||||||
const cc_result ReturnCode_FileShareViolation = 1000000000; // not used
|
const cc_result ReturnCode_FileShareViolation = 1000000000; // not used
|
||||||
@ -136,7 +137,44 @@ int File_Exists(const cc_string* path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {
|
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {
|
||||||
return ERR_NOT_SUPPORTED;
|
cc_string path; char pathBuffer[FILENAME_SIZE];
|
||||||
|
char str[NATIVE_STR_LEN];
|
||||||
|
struct dirent* entry;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
String_EncodeUtf8(str, dirPath);
|
||||||
|
DIR* dirPtr = opendir(str);
|
||||||
|
if (!dirPtr) return errno;
|
||||||
|
|
||||||
|
/* POSIX docs: "When the end of the directory is encountered, a null pointer is returned and errno is not changed." */
|
||||||
|
/* errno is sometimes leftover from previous calls, so always reset it before readdir gets called */
|
||||||
|
errno = 0;
|
||||||
|
String_InitArray(path, pathBuffer);
|
||||||
|
|
||||||
|
while ((entry = readdir(dirPtr))) {
|
||||||
|
path.length = 0;
|
||||||
|
String_Format1(&path, "%s/", dirPath);
|
||||||
|
|
||||||
|
/* ignore . and .. entry */
|
||||||
|
char* src = entry->d_name;
|
||||||
|
if (src[0] == '.' && src[1] == '\0') continue;
|
||||||
|
if (src[0] == '.' && src[1] == '.' && src[2] == '\0') continue;
|
||||||
|
|
||||||
|
int len = String_Length(src);
|
||||||
|
String_AppendUtf8(&path, src, len);
|
||||||
|
|
||||||
|
if (entry->d_type == DT_DIR) {
|
||||||
|
res = Directory_Enum(&path, obj, callback);
|
||||||
|
if (res) { closedir(dirPtr); return res; }
|
||||||
|
} else {
|
||||||
|
callback(&path, obj);
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = errno; /* return code from readdir */
|
||||||
|
closedir(dirPtr);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_result File_Do(cc_file* file, const cc_string* path, int mode, const char* type) {
|
static cc_result File_Do(cc_file* file, const cc_string* path, int mode, const char* type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user