-/*
- * This is essentially a "wrapper" interface around standard C's IO
- * library. There is two reason we implement this, 1) visual studio
- * hearts for "secure" varations, as part of it's "Security Enhancements
- * in the CRT" (http://msdn.microsoft.com/en-us/library/8ef0s5kh.aspx).
- * 2) But one of the greater reasons is for the possibility of large file
- * support in the future. I don't expect to reach the 2GB limit any
- * time soon (mainly because that would be insane). But when it comes
- * to adding support for some other larger IO tasks (in the test-suite,
- * or even the QCVM we'll need it). There is also a third possibility of
- * building .dat files directly from zip files (which would be very cool
- * at least I think so).
- */
-#ifdef _MSC_VER
-/* {{{ */
- /*
- * Visual Studio has security CRT features which I actually want to support
- * if we ever port to Windows 8, and want GMQCC to be API safe.
- *
- * We handle them here, for all file-operations.
- */
-
- static void file_exception (
- const wchar_t *expression,
- const wchar_t *function,
- const wchar_t *file,
- unsigned int line,
- uintptr_t reserved
- ) {
- wprintf(L"Invalid parameter dectected %s:%d %s [%s]\n", file, line, function, expression);
- wprintf(L"Aborting ...\n");
- abort();
- }
-
- static void file_init() {
- static bool init = false;
-
- if (init)
- return;
-
- _set_invalid_parameter_handler(&file_exception);
-
- /*
- * Turnoff the message box for CRT asserations otherwise
- * we don't get the error reported to the console as we should
- * otherwise get.
- */
- _CrtSetReportMode(_CRT_ASSERT, 0);
- init = !init;
- }
-
-
- FILE *fs_file_open(const char *filename, const char *mode) {
- FILE *handle = NULL;
- file_init();
-
- return (fopen_s(&handle, filename, mode) != 0) ? NULL : handle;
- }
-
- size_t fs_file_read(void *buffer, size_t size, size_t count, FILE *fp) {
- file_init();
- return fread_s(buffer, size*count, size, count, fp);
- }
-
- int fs_file_printf(FILE *fp, const char *format, ...) {
- int rt;
- va_list va;
- va_start(va, format);
-
- file_init();
- rt = vfprintf_s(fp, format, va);
- va_end (va);
-
- return rt;
- }
-
-/* }}} */
-#else
-/* {{{ */
- /*
- * All other compilers/platforms that don't restrict insane policies on
- * IO for no aparent reason.
- */
- FILE *fs_file_open(const char *filename, const char *mode) {
- return fopen(filename, mode);
- }
-
- size_t fs_file_read(void *buffer, size_t size, size_t count, FILE *fp) {
- return fread(buffer, size, count, fp);
- }