Skip to content

Commit

Permalink
Merge branch 'sk/mingw-main'
Browse files Browse the repository at this point in the history
* sk/mingw-main:
  mingw: avoid const warning
  Win32: move main macro to a function
  • Loading branch information
gitster committed Jul 9, 2014
2 parents ce8350f + a15d4af commit ba655d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
15 changes: 15 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1847,3 +1847,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);
}
14 changes: 4 additions & 10 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,22 +363,16 @@ void free_environ(char **env);
extern CRITICAL_SECTION pinfo_cs;

/*
* 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(c,v); \
int main(int argc, 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, (void *)__argv); \
} \
static int mingw_main(c,v)

Expand Down

0 comments on commit ba655d1

Please sign in to comment.