From: Wolfgang (Blub) Bumiller Date: Thu, 16 Aug 2012 12:01:47 +0000 (+0200) Subject: util_fopen... X-Git-Tag: 0.1-rc1~259 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=0d9435d326c6a01f615fd6cb86432db75193d9bf;p=xonotic%2Fgmqcc.git util_fopen... --- diff --git a/code.c b/code.c index 9149fbc..5c69e88 100644 --- a/code.c +++ b/code.c @@ -203,7 +203,7 @@ bool code_write(const char *filename) { util_endianswap(code_functions_data, code_functions_elements, sizeof(prog_section_function)); util_endianswap(code_globals_data, code_globals_elements, sizeof(int32_t)); - fp = fopen(filename, "wb"); + fp = util_fopen(filename, "wb"); if (!fp) return false; diff --git a/exec.c b/exec.c index e2bcc52..348d2af 100644 --- a/exec.c +++ b/exec.c @@ -55,7 +55,7 @@ qc_program* prog_load(const char *filename) size_t i; FILE *file; - file = fopen(filename, "rb"); + file = util_fopen(filename, "rb"); if (!file) return NULL; diff --git a/gmqcc.h b/gmqcc.h index dee3678..e078494 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -189,9 +189,7 @@ typedef char intptr_size_is_correct [sizeof(uintptr_t)== sizeof(int*)?1:-1]; /*===================================================================*/ /*=========================== util.c ================================*/ /*===================================================================*/ -#ifdef WIN32 -# define fopen fopen_s -#endif +FILE *util_fopen(const char *filename, const char *mode); void *util_memory_a (unsigned int, unsigned int, const char *); void util_memory_d (void *, unsigned int, const char *); diff --git a/lexer.c b/lexer.c index 606ef5a..ef4464e 100644 --- a/lexer.c +++ b/lexer.c @@ -122,7 +122,7 @@ token* token_copy_all(const token *cp) lex_file* lex_open(const char *file) { lex_file *lex; - FILE *in = fopen(file, "rb"); + FILE *in = util_fopen(file, "rb"); if (!in) { lexerror(NULL, "open failed: '%s'\n", file); diff --git a/main.c b/main.c index 052bc4c..260dd38 100644 --- a/main.c +++ b/main.c @@ -418,7 +418,7 @@ int main(int argc, char **argv) { char *line; printf("Mode: progs.src\n"); - src = fopen("progs.src", "rb"); + src = util_fopen("progs.src", "rb"); if (!src) { printf("failed to open `progs.src` for reading\n"); retval = 1; diff --git a/util.c b/util.c index f38c153..d825ab2 100644 --- a/util.c +++ b/util.c @@ -398,3 +398,16 @@ size_t util_strtononcmd(const char *in, char *out, size_t outsz) { *out = 0; return sz-1; } + +FILE *util_fopen(const char *filename, const char *mode) +{ +#ifdef WIN32 + FILE *out; + if (fopen_s(&out, file, mode) != 0) + return NULL; + return out; +#else + return fopen(file, mode); +#endif +} +