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;
size_t i;
FILE *file;
- file = fopen(filename, "rb");
+ file = util_fopen(filename, "rb");
if (!file)
return NULL;
/*===================================================================*/
/*=========================== 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 *);
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);
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;
*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
+}
+