diff options
-rw-r--r-- | common/os_calls.c | 60 | ||||
-rw-r--r-- | common/os_calls.h | 8 |
2 files changed, 67 insertions, 1 deletions
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 @@ -649,6 +649,18 @@ g_set_file_rights(char* filename, int read, int write) } /*****************************************************************************/ +/* 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 g_mkdir(char* dirname) @@ -702,13 +714,59 @@ 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 g_file_delete(char* filename) 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); |