aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-10-01 15:59:12 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-10-01 15:59:12 +0200
commit7854c1a0c21193af3992ef672b322a27d41c883d (patch)
tree99ade81c317791227d6521cfd7db4b306b64ed61 /src/main.cpp
parent5df92c6ba09f3d058cb8336661b930d234b649b4 (diff)
downloadosc-graphics-7854c1a0c21193af3992ef672b322a27d41c883d.tar.gz
fixed MinGW SDL stdio redirection issue
instead of trying to reopen stdout and stderr, we ensure that stdio redirection is not initialized in the first place. * the workaround code could be in a separate C or C++ file but that would require conditional compilation and linking and therefore a new Automake conditional
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c933a10..1f15c6e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -190,12 +190,6 @@ main(int argc, char **argv)
port, sdl_flags, show_cursor,
width, height, bpp, framerate);
-#ifdef __WIN32__
- /* disable SDL's stdio redirect */
- freopen("CON", "w", stdout);
- freopen("CON", "w", stderr);
-#endif
-
if (SDL_Init(SDL_INIT_VIDEO)) {
SDL_ERROR("SDL_Init");
return EXIT_FAILURE;
@@ -240,3 +234,22 @@ main(int argc, char **argv)
/* never reached */
return EXIT_FAILURE;
}
+
+#if defined(__WIN32__) && defined(main)
+#undef main
+/*
+ * Define a main() symbol, so that libmingw32 won't define it and libSDLmain's
+ * WinMain() is not called since that would initiate stdio redirection.
+ * Instead we call libSDLmain's console_main() which in turn calls
+ * the main() defined above which was renamed to SDL_main by SDL CFLAGS.
+ */
+
+extern "C" int console_main(int argc, char *argv[]);
+
+extern "C" int
+main(int argc, char *argv[])
+{
+ return console_main(argc, argv);
+}
+
+#endif