From d5a89b8ce104285bcc697e1ac8df7432ac686623 Mon Sep 17 00:00:00 2001 From: jsorg71 Date: Sat, 15 Sep 2007 05:48:13 +0000 Subject: [PATCH] added init and deinit functions and windows unicode fixes --- common/os_calls.c | 40 +++++++++++++++++++++++++++++++--------- common/os_calls.h | 4 ++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index c833e6f5..bbbe5e73 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -56,6 +56,7 @@ #include #include #include +#include #include "os_calls.h" #include "arch.h" @@ -74,6 +75,27 @@ extern char** environ; #define INADDR_NONE ((unsigned long)-1) #endif +/*****************************************************************************/ +void APP_CC +g_init(void) +{ +#if defined(_WIN32) + WSADATA wsadata; + + WSAStartup(2, &wsadata); +#endif + setlocale(LC_CTYPE, ""); +} + +/*****************************************************************************/ +void APP_CC +g_deinit(void) +{ +#if defined(_WIN32) + WSACleanup(); +#endif +} + /*****************************************************************************/ /* allocate memory, returns a pointer to it, size bytes are allocated, if zero is non zero, each byte will be set to zero */ @@ -641,9 +663,9 @@ int APP_CC g_file_open(const char* file_name) { #if defined(_WIN32) - return (int)CreateFile(file_name, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + return (int)CreateFileA(file_name, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); #else int rv; @@ -818,7 +840,7 @@ char* APP_CC g_get_current_dir(char* dirname, int maxlen) { #if defined(_WIN32) - GetCurrentDirectory(maxlen, dirname); + GetCurrentDirectoryA(maxlen, dirname); return 0; #else getcwd(dirname, maxlen); @@ -832,7 +854,7 @@ int APP_CC g_set_current_dir(char* dirname) { #if defined(_WIN32) - if (SetCurrentDirectory(dirname)) + if (SetCurrentDirectoryA(dirname)) { return 0; } @@ -885,7 +907,7 @@ int APP_CC g_create_dir(const char* dirname) { #if defined(_WIN32) - return CreateDirectory(dirname, 0); // test this + return CreateDirectoryA(dirname, 0); // test this #else return mkdir(dirname, (mode_t)-1) == 0; #endif @@ -897,7 +919,7 @@ int APP_CC g_remove_dir(const char* dirname) { #if defined(_WIN32) - return RemoveDirectory(dirname); // test this + return RemoveDirectoryA(dirname); // test this #else return rmdir(dirname) == 0; #endif @@ -909,7 +931,7 @@ int APP_CC g_file_delete(const char* filename) { #if defined(_WIN32) - return DeleteFile(filename); + return DeleteFileA(filename); #else return unlink(filename) != -1; #endif @@ -1057,7 +1079,7 @@ long APP_CC g_load_library(char* in) { #if defined(_WIN32) - return (long)LoadLibrary(in); + return (long)LoadLibraryA(in); #else return (long)dlopen(in, RTLD_LOCAL | RTLD_LAZY); #endif diff --git a/common/os_calls.h b/common/os_calls.h index 845c2558..79c07093 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -27,6 +27,10 @@ #include "arch.h" +void APP_CC +g_init(void); +void APP_CC +g_deinit(void); void* APP_CC g_malloc(int size, int zero); void APP_CC