diff options
| -rw-r--r-- | kon/konfs.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/kon/konfs.h b/kon/konfs.h index 6fd4c64..9c45e72 100644 --- a/kon/konfs.h +++ b/kon/konfs.h @@ -76,6 +76,12 @@ void kon_fsJoin(char *out, size_t size, const char *dir, const char *name); Windows is "" */ int kon_fsParent(char *path); +/* every file in dir and in the folders inside it, as paths from dir with /. folders are not in the list. sorted by name. returns 0 when dir cannot be read */ +int kon_fsWalk(const char *dir, kon_fsList_t *list); + +/* 1 when path starts at a root: / or X:/ */ +int kon_fsIsAbsolute(const char *path); + /* the last part of path */ const char *kon_fsBaseName(const char *path); @@ -349,4 +355,42 @@ int kon_fsRead(const char *dir, kon_fsList_t *list) #endif /* _WIN32 */ +int kon_fsIsAbsolute(const char *path) +{ + return kon_fsRootLength_(path) > 0; +} + +static int kon_fsWalk_(const char *base, const char *rel, int depth, kon_fsList_t *out) +{ + kon_fsList_t list; + char path[KON_FS_PATH], name[KON_FS_PATH]; + size_t i; + int ok = 1; + + if (depth > 32) return 1; + kon_fsJoin(path, sizeof(path), base, rel); + if (!kon_fsRead(path, &list)) { + kon_fsFree(&list); + return 0; + } + for (i = 0; i < list.count && ok; i++) { + kon_fsJoin(name, sizeof(name), rel, list.items[i].name); + if (list.items[i].isDir) ok = kon_fsWalk_(base, name, depth + 1, out); + else ok = kon_fsPush_(out, name, 0, list.items[i].size); + } + kon_fsFree(&list); + return ok; +} + +int kon_fsWalk(const char *dir, kon_fsList_t *list) +{ + memset(list, 0, sizeof(*list)); + if (!kon_fsWalk_(dir, "", 0, list)) { + kon_fsFree(list); + return 0; + } + if (list->count > 1) qsort(list->items, list->count, sizeof(kon_fsEntry_t), kon_fsCompare_); + return 1; +} + #endif /* KONFS_IMPLEMENTATION */ |
