Win32: move main macro to a function

The code in the MinGW main macro is getting more and more complex, move to
a separate initialization function for readabiliy and extensibility.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
This commit is contained in:
Karsten Blees 2011-01-07 19:47:23 +01:00 committed by Johannes Schindelin
parent 82d8bd39d9
commit 064ff1edf7
2 changed files with 19 additions and 10 deletions

View file

@ -1868,3 +1868,18 @@ int mingw_offset_1st_component(const char *path)
return offset + is_dir_sep(path[offset]);
}
void mingw_startup()
{
/* copy executable name to argv[0] */
__argv[0] = xstrdup(_pgmptr);
/* initialize critical section for waitpid pinfo_t list */
InitializeCriticalSection(&pinfo_cs);
/* set up default file mode and file modes for stdin/out/err */
_fmode = _O_BINARY;
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stderr), _O_BINARY);
}

View file

@ -327,22 +327,16 @@ char **make_augmented_environ(const char *const *vars);
void free_environ(char **env);
/*
* A replacement of main() that ensures that argv[0] has a path
* and that default fmode and std(in|out|err) are in binary mode
* A replacement of main() that adds win32 specific initialization.
*/
void mingw_startup();
#define main(c,v) dummy_decl_mingw_main(); \
static int mingw_main(); \
int main(int argc, const char **argv) \
{ \
extern CRITICAL_SECTION pinfo_cs; \
_fmode = _O_BINARY; \
_setmode(_fileno(stdin), _O_BINARY); \
_setmode(_fileno(stdout), _O_BINARY); \
_setmode(_fileno(stderr), _O_BINARY); \
argv[0] = xstrdup(_pgmptr); \
InitializeCriticalSection(&pinfo_cs); \
return mingw_main(argc, argv); \
mingw_startup(); \
return mingw_main(__argc, __argv); \
} \
static int mingw_main(c,v)