/** * cf_file.c */ #include "cf_file.h" #ifdef _WIN32 # include # include # include # define S_IWUSR _S_IWRITE # define S_IRUSR _S_IREAD # define S_IXUSR _S_IEXEC # define S_IRGRP 0x00000000 # define S_IWGRP 0x00000000 # define S_IXGRP 0x00000000 # define S_IROTH 0x00000000 # define S_IWOTH 0x00000000 # define S_IXOTH 0x00000000 #else // #ifdef _WIN32 # include #endif // #ifdef _WIN32 #define FILE_MODE S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH int CF_File_Open (const char * path, const CF_FILE_FLAG flag) { int result = open (path, flag); if (result < 0) return CF_ERROR_FILE_OPEN; return result; } int CF_File_Create (const char * path) { int result = open (path, CF_FILE_CR|CF_FILE_WO|CF_FILE_TR, FILE_MODE); if (result < 0) return CF_ERROR_FILE_CREATE; return result; } int CF_File_Close (const int fd) { int result = 0; if (fd < 0) return CF_ERROR_FILE_INVALID_ARGS; result = close (fd); if (result < 0) return CF_ERROR_FILE_CLOSE; return CF_OK; } int CF_File_Read (const int fd, void * buf, const size_t len) { int result = (int) read (fd, buf, len); if (result < 0) return CF_ERROR_FILE_READ; return CF_OK; } int CF_File_Write (const int fd, const void * buf, const size_t len) { int result = (int) write (fd, buf, len); if (result != len) return CF_ERROR_FILE_WRITE; return CF_OK; } int CF_File_GetSize (const int fd) { int result = (int) lseek (fd, 0, SEEK_END); if (result < 0 || lseek (fd, 0, SEEK_SET) < 0) return CF_ERROR_FILE_GET_SIZE; return result; }