diff options
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/system.c | 37 | ||||
| -rw-r--r-- | src/base/system.h | 17 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/base/system.c b/src/base/system.c index d2f4614a..e2c37bbd 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -909,6 +909,43 @@ int fs_makedir(const char *path) #endif } +int fs_is_dir(const char *path) +{ +#if defined(CONF_FAMILY_WINDOWS) + /* TODO: do this smarter */ + WIN32_FIND_DATA finddata; + HANDLE handle; + char buffer[1024*2]; + str_format(buffer, sizeof(buffer), "%s/*", path); + + if ((handle = FindFirstFileA(buffer, &finddata)) == INVALID_HANDLE_VALUE) + return 0; + + FindClose(handle); + return 1; +#else + struct stat sb; + if (stat(path, &sb) == -1) + return 0; + + if (S_ISDIR(sb.st_mode)) + return 1; + else + return 0; +#endif +} + +int fs_chdir(const char *path) +{ + if (fs_is_dir(path)) + { + chdir(path); + return 0; + } + else + return 1; +} + void swap_endian(void *data, unsigned elem_size, unsigned num) { char *src = (char*) data; diff --git a/src/base/system.h b/src/base/system.h index 9a556341..fdbfe72d 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -824,6 +824,23 @@ int fs_makedir(const char *path); */ int fs_storage_path(const char *appname, char *path, int max); +/* + Function: fs_is_dir + Checks if directory exists + + Returns: + Returns 1 on success, 0 on failure. +*/ +int fs_is_dir(const char *path); + +/* + Function: fs_chdir + Changes current working directory + + Returns: + Returns 0 on success, 1 on failure. +*/ +int fs_chdir(const char *path); /* Group: Undocumented |