Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 5fc41c4

Browse files
kbleeskasal
authored andcommitted
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 <[email protected]> Signed-off-by: Erik Faye-Lund <[email protected]>
1 parent 548cf58 commit 5fc41c4

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

compat/mingw.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,3 +1823,18 @@ pid_t waitpid(pid_t pid, int *status, int options)
18231823
errno = EINVAL;
18241824
return -1;
18251825
}
1826+
1827+
void mingw_startup()
1828+
{
1829+
/* copy executable name to argv[0] */
1830+
__argv[0] = xstrdup(_pgmptr);
1831+
1832+
/* initialize critical section for waitpid pinfo_t list */
1833+
InitializeCriticalSection(&pinfo_cs);
1834+
1835+
/* set up default file mode and file modes for stdin/out/err */
1836+
_fmode = _O_BINARY;
1837+
_setmode(_fileno(stdin), _O_BINARY);
1838+
_setmode(_fileno(stdout), _O_BINARY);
1839+
_setmode(_fileno(stderr), _O_BINARY);
1840+
}

compat/mingw.h

Lines changed: 5 additions & 11 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); \
372-
int main(int argc, char **argv) \
372+
int main(c,v) \
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, __argv); \
382376
} \
383377
static int mingw_main(c,v)
384378

http-fetch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
static const char http_fetch_usage[] = "git http-fetch "
77
"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
88

9-
int main(int argc, const char **argv)
9+
int main(int argc, char **av)
1010
{
1111
struct walker *walker;
1212
int commits_on_stdin = 0;
1313
int commits;
14+
const char **argv = (const char **)av;
1415
const char **write_ref = NULL;
1516
char **commit_id;
1617
char *url = NULL;

remote-curl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,9 +941,10 @@ static void parse_push(struct strbuf *buf)
941941
free(specs);
942942
}
943943

944-
int main(int argc, const char **argv)
944+
int main(int argc, char **av)
945945
{
946946
struct strbuf buf = STRBUF_INIT;
947+
const char **argv = (const char **)av;
947948
int nongit;
948949

949950
git_extract_argv0_path(argv[0]);

0 commit comments

Comments
 (0)