[SDL] cygwin - preventing stdout/stderr redirection

Mark K. Kim markslist at cbreak.org
Sat Feb 2 11:03:00 PST 2002


The redirection occurs before main() by SDL's startup code.

How this happens is quite clever (one might say :).  For compatibility,
your code is supposed to start at "main()".  But Windows actually starts
at "WinMain()", and the "WinMain()" symbol is linked into the SDL library
(so you can't override it).  Furthermore, "main"'s symbol is changed to
"SDL_main" by passing "-Dmain=SDL_main" to `gcc`.  This symbol
manipulation is actually not necessary on Windows, but seems to exist for
compatibility reasons (there was a discussion earlier in the mailing list
about the necessity of mainpulating "main"; I didn't understand what that
was about until yesterday :).  The redirection is accomplished inside
"WinMain()"  by "freopen()"-ing "stdin" and "stdout" before "WinMain()"
calls "SDL_main()".

Anyway, that's why stdin/stdout redirection can't be overridden -- because
SDL does it before "main()" is even called!  Hmmm... now that I think of
it, perhaps symbol manipulation by the linker could be used, but I'd like
to discuss the possibility of SDL support to work around it nicely.

-Mark

On Sat, 2 Feb 2002, Dave Brondsema wrote:

>
> I haven't tested it, but i'd expect you could print usage info
> to the console if you do it before SDL_Init
>
> --
> Dave Brondsema
>
> --- "Mark K. Kim" <markslist at cbreak.org> wrote:
> > Replying to my own post --
> >
> > After poking around the SDL source, it looks like it's not
> > possible to
> > prevent or undo stdout/stderr redirection under Windows
> > without source
> > modification.
> >
> > Further poking ::poke, poke:: shows only Windows and Macintosh
> > do this.
> > I understand why it'd be useful on Macintosh.  I understand
> > why it'd be
> > useful on VC++.  But it's definitely not necessary on MinGW or
> > Cygwin
> > development (redirection can be used if file output is
> > needed.)
> >
> > If this is gonna be done, doesn't it make sense to be able to
> > turn the
> > console output feature on/off?  At least save stdout and
> > stderr file
> > handlers so things can be written to the console if necessary?
> >
> > For example, it'd be nice to be able to print usage
> > information (`progname
> > --help`).  This is common on X11, and I think even some
> > Windows apps
> > (though not many) do this.  It's an open-source-ism if nothing
> > else.
> >
> > -Mark
> >
> > On Fri, 1 Feb 2002, Mark K. Kim wrote:
> >
> > > Hey guys,
> > >
> > > Is there a way to prevent (or work around) the stdout/stderr
> > redirection
> > > to stdout.txt and stderr.txt under Cgywin (without modifying
> > the SDL
> > > startup code :)?  I'm running MingW32 library on SDL's
> > website.  Thanks in
> > > advance!
> > >
> > > -Mark
> > >
> > > --
> > > Mark K. Kim
> > > http://www.cbreak.org/mark/
> > > PGP key available upon request.
> > >
> > >
> > > _______________________________________________
> > > SDL mailing list
> > > SDL at libsdl.org
> > > http://www.libsdl.org/mailman/listinfo/sdl
> > >
> >
> > --
> > Mark K. Kim
> > http://www.cbreak.org/mark/
> > PGP key available upon request.
> >
> >
> >
> >
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
>
>
> __________________________________________________
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
>

--
Mark K. Kim
http://www.cbreak.org/mark/
PGP key available upon request.





More information about the SDL mailing list