about summary refs log tree commit diff
path: root/src/base
diff options
context:
space:
mode:
authorDominik Geyer <dominik.geyer@gmx.de>2008-10-01 17:16:22 +0000
committerDominik Geyer <dominik.geyer@gmx.de>2008-10-01 17:16:22 +0000
commit397b9a764b435a7b8c410bd9edc445009a7a9564 (patch)
treef7d5c80cdd8b0998c3267e064a20f8a56405d029 /src/base
parentfb3e8dec7905611a170c6b069cbaac34c4e04e70 (diff)
downloadzcatch-397b9a764b435a7b8c410bd9edc445009a7a9564.tar.gz
zcatch-397b9a764b435a7b8c410bd9edc445009a7a9564.zip
data-dir autodetection; data-dir override; compiled-in data-dir; messagebox if detection fails; does chdir into data-dir
Diffstat (limited to 'src/base')
-rw-r--r--src/base/system.c37
-rw-r--r--src/base/system.h17
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