From 397b9a764b435a7b8c410bd9edc445009a7a9564 Mon Sep 17 00:00:00 2001 From: Dominik Geyer Date: Wed, 1 Oct 2008 17:16:22 +0000 Subject: data-dir autodetection; data-dir override; compiled-in data-dir; messagebox if detection fails; does chdir into data-dir --- src/base/system.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/base/system.c') 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; -- cgit 1.4.1