From a9323d9ccb4a1dccaf5c62bfc7db0c22c9011c61 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 Nov 2022 17:54:25 -0500 Subject: Use zix_current_path() --- src/filesystem.c | 29 ++++------------------------- src/filesystem.h | 8 -------- 2 files changed, 4 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/filesystem.c b/src/filesystem.c index 572b8ea..584eaad 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -10,17 +10,12 @@ #include "zix/path.h" #ifdef _WIN32 -# include # include # include -# define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) #else # include -# include #endif -#include - #include #include #include @@ -52,12 +47,6 @@ lilv_path_is_child(const char* path, const char* dir) return false; } -char* -lilv_path_current(void) -{ - return getcwd(NULL, 0); -} - char* lilv_path_relative_to(const char* path, const char* base) { @@ -158,26 +147,13 @@ lilv_path_filename(const char* path) return ret; } -bool -lilv_is_directory(const char* path) -{ -#if defined(_WIN32) - const DWORD attrs = GetFileAttributes(path); - - return (attrs != INVALID_FILE_ATTRIBUTES) && - (attrs & FILE_ATTRIBUTE_DIRECTORY); -#else - struct stat st; - return !stat(path, &st) && S_ISDIR(st.st_mode); -#endif -} - void lilv_dir_for_each(const char* path, void* data, void (*f)(const char* path, const char* name, void* data)) { #ifdef _WIN32 + char* pat = zix_path_join(NULL, path, "*"); WIN32_FIND_DATA fd; HANDLE fh = FindFirstFile(pat, &fd); @@ -190,7 +166,9 @@ lilv_dir_for_each(const char* path, } FindClose(fh); free(pat); + #else + DIR* dir = opendir(path); if (dir) { for (struct dirent* entry = NULL; (entry = readdir(dir));) { @@ -200,6 +178,7 @@ lilv_dir_for_each(const char* path, } closedir(dir); } + #endif } diff --git a/src/filesystem.h b/src/filesystem.h index db6114e..d2f14b6 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -7,10 +7,6 @@ bool lilv_path_is_child(const char* path, const char* dir); -/// Return the current working directory -char* -lilv_path_current(void); - /** Return `path` relative to `base` if possible. @@ -37,10 +33,6 @@ lilv_path_parent(const char* path); char* lilv_path_filename(const char* path); -/// Return true iff `path` points to an existing directory -bool -lilv_is_directory(const char* path); - /** Visit every file in the directory at `path`. -- cgit v1.2.1