diff options
Diffstat (limited to 'src/base/system.c')
| -rw-r--r-- | src/base/system.c | 37 |
1 files changed, 37 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; |