]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
util_fopen...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 16 Aug 2012 12:01:47 +0000 (14:01 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Thu, 16 Aug 2012 12:01:47 +0000 (14:01 +0200)
code.c
exec.c
gmqcc.h
lexer.c
main.c
util.c

diff --git a/code.c b/code.c
index 9149fbca6a717f7206984c10dcfd20dde71fb0e1..5c69e8803496775313fd91b3d4e4c54dc8abc312 100644 (file)
--- 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 e2bcc5245b75adcc4f0249c3fc6f83f391c4e1b6..348d2af313c72b45817f3845f47cb92a29cc4edd 100644 (file)
--- 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 dee36781381c41850139e679b4481bffeb077ce6..e0784942444239af78dc0bced3696693994adf52 100644 (file)
--- 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 606ef5a9fee5cf768864d6a31e3cb84e5fe96c1a..ef4464ea0cd672a9803f281e7492b08cbee1d3f9 100644 (file)
--- 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 052bc4c0c3c677b31f747fe5ed9773dfcf52c714..260dd3877f448472b5dd36dd4fba7fa34f9908cd 100644 (file)
--- 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 f38c15302ebf68bf04b64a3b9392d8c9a2d50079..d825ab2f5715d72cb57d7cb71ec8c2104097f616 100644 (file)
--- 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
+}
+