From bd252214a3b0cfe3ddcfb09c2280e5a621789656 Mon Sep 17 00:00:00 2001 From: jsorg71 Date: Fri, 27 Oct 2006 04:14:04 +0000 Subject: [PATCH] added g_create_dir, g_directory_exist, g_remove_dir, and g_chmod --- common/os_calls.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++- common/os_calls.h | 8 +++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/common/os_calls.c b/common/os_calls.c index ab0eaf26..44a2e39f 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -648,6 +648,18 @@ g_set_file_rights(char* filename, int read, int write) #endif } +/*****************************************************************************/ +/* returns error */ +int +g_chmod(char* filename, int flags) +{ +#if defined(_WIN32) + return 0; +#else + return chmod(filename, flags); +#endif +} + /*****************************************************************************/ /* returns error, always zero */ int @@ -702,12 +714,58 @@ int g_file_exist(char* filename) { #if defined(_WIN32) - return 0; // use FindFirstFile(); + return 0; // use FileAge(filename) <> -1 #else return access(filename, F_OK) == 0; #endif } +/*****************************************************************************/ +/* returns boolean, non zero if the directory exists */ +int +g_directory_exist(char* dirname) +{ +#if defined(_WIN32) + return 0; // use GetFileAttributes and check return value + // is not -1 and FILE_ATTRIBUT_DIRECTORY bit is set +#else + struct stat st; + + if (stat(dirname, &st) == 0) + { + return S_ISDIR(st.st_mode); + } + else + { + return 0; + } +#endif +} + +/*****************************************************************************/ +/* returns boolean */ +int +g_create_dir(char* dirname) +{ +#if defined(_WIN32) + return CreateDirectory(dirname, 0); // test this +#else + return mkdir(dirname, (mode_t)-1) == 0; +#endif +} + +/*****************************************************************************/ +/* returns boolean */ +int +g_remove_dir(char* dirname) +{ +#if defined(_WIN32) + return RemoveDirectory(dirname); // test this +#else + return rmdir(dirname) == 0; +#endif +} + /*****************************************************************************/ /* returns non zero if the file was deleted */ int diff --git a/common/os_calls.h b/common/os_calls.h index d8eaeb3a..ce015b8f 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -100,6 +100,8 @@ g_file_lock(int fd, int start, int len); int g_set_file_rights(char* filename, int read, int write); int +g_chmod(char* filename, int flags); +int g_mkdir(char* dirname); char* g_get_current_dir(char* dirname, int maxlen); @@ -108,6 +110,12 @@ g_set_current_dir(char* dirname); int g_file_exist(char* filename); int +g_directory_exist(char* dirname); +int +g_create_dir(char* dirname); +int +g_remove_dir(char* dirname); +int g_file_delete(char* filename); int g_strlen(char* text);