From 0d9435d326c6a01f615fd6cb86432db75193d9bf Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Thu, 16 Aug 2012 14:01:47 +0200 Subject: [PATCH] util_fopen... --- code.c | 2 +- exec.c | 2 +- gmqcc.h | 4 +--- lexer.c | 2 +- main.c | 2 +- util.c | 13 +++++++++++++ 6 files changed, 18 insertions(+), 7 deletions(-) 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 +} + -- 2.39.2