added g_create_dir, g_directory_exist, g_remove_dir, and g_chmod

ulab-original
jsorg71 18 years ago
parent 5dfa4e3f39
commit bd252214a3

@ -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

@ -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);

Loading…
Cancel
Save