Skip to content

Commit ba655d1

Browse files
committed
Merge branch 'sk/mingw-main'
* sk/mingw-main: mingw: avoid const warning Win32: move main macro to a function
2 parents ce8350f + a15d4af commit ba655d1

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

compat/mingw.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,3 +1847,18 @@ int mingw_offset_1st_component(const char *path)
18471847

18481848
return offset + is_dir_sep(path[offset]);
18491849
}
1850+
1851+
void mingw_startup()
1852+
{
1853+
/* copy executable name to argv[0] */
1854+
__argv[0] = xstrdup(_pgmptr);
1855+
1856+
/* initialize critical section for waitpid pinfo_t list */
1857+
InitializeCriticalSection(&pinfo_cs);
1858+
1859+
/* set up default file mode and file modes for stdin/out/err */
1860+
_fmode = _O_BINARY;
1861+
_setmode(_fileno(stdin), _O_BINARY);
1862+
_setmode(_fileno(stdout), _O_BINARY);
1863+
_setmode(_fileno(stderr), _O_BINARY);
1864+
}

compat/mingw.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,22 +363,16 @@ void free_environ(char **env);
363363
extern CRITICAL_SECTION pinfo_cs;
364364

365365
/*
366-
* A replacement of main() that ensures that argv[0] has a path
367-
* and that default fmode and std(in|out|err) are in binary mode
366+
* A replacement of main() that adds win32 specific initialization.
368367
*/
369368

369+
void mingw_startup();
370370
#define main(c,v) dummy_decl_mingw_main(); \
371371
static int mingw_main(c,v); \
372372
int main(int argc, char **argv) \
373373
{ \
374-
extern CRITICAL_SECTION pinfo_cs; \
375-
_fmode = _O_BINARY; \
376-
_setmode(_fileno(stdin), _O_BINARY); \
377-
_setmode(_fileno(stdout), _O_BINARY); \
378-
_setmode(_fileno(stderr), _O_BINARY); \
379-
argv[0] = xstrdup(_pgmptr); \
380-
InitializeCriticalSection(&pinfo_cs); \
381-
return mingw_main(argc, argv); \
374+
mingw_startup(); \
375+
return mingw_main(__argc, (void *)__argv); \
382376
} \
383377
static int mingw_main(c,v)
384378

0 commit comments

Comments
 (0)