From e07dd5afb5a47b8a707f205727e0e4861b409f0a Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sat, 13 Oct 2012 22:48:05 -0700 Subject: [PATCH] added a file open funtion --- common/os_calls.c | 38 ++++++++++++++++++++++++++++++++++++++ common/os_calls.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/common/os_calls.c b/common/os_calls.c index 20c84f3e..602d6c0f 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -1370,6 +1370,44 @@ g_file_open(const char *file_name) #endif } +/*****************************************************************************/ +/* returns -1 on error, else return handle or file descriptor */ +int APP_CC +g_file_open_ex(const char *file_name, int aread, int awrite, + int acreate, int atrunc) +{ +#if defined(_WIN32) + return -1; +#else + int rv; + int flags; + + flags = 0; + if (aread && awrite) + { + flags |= O_RDWR; + } + else if (aread) + { + flags |= O_RDONLY; + } + else if (awrite) + { + flags |= O_WRONLY; + } + if (acreate) + { + flags |= O_CREAT; + } + if (atrunc) + { + flags |= O_TRUNC; + } + rv = open(file_name, flags, S_IRUSR | S_IWUSR); + return rv; +#endif +} + /*****************************************************************************/ /* returns error, always 0 */ int APP_CC diff --git a/common/os_calls.h b/common/os_calls.h index c734c9fe..4bbd09de 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -133,6 +133,9 @@ g_memcmp(const void* s1, const void* s2, int len); int APP_CC g_file_open(const char* file_name); int APP_CC +g_file_open_ex(const char *file_name, int aread, int awrite, + int acreate, int atrunc); +int APP_CC g_file_close(int fd); int APP_CC g_file_read(int fd, char* ptr, int len);