Skip to content

Commit d75f8e6

Browse files
lznuaagitster
authored andcommitted
Add platform files for porting to MSVC
Add msvc.c and msvc.h to build git under MSVC. Signed-off-by: Frank Li <[email protected]> Signed-off-by: Marius Storm-Olsen <[email protected]> Acked-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16fe1e0 commit d75f8e6

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

compat/msvc.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "../git-compat-util.h"
2+
#include "win32.h"
3+
#include <conio.h>
4+
#include "../strbuf.h"
5+
6+
DIR *opendir(const char *name)
7+
{
8+
int len;
9+
DIR *p;
10+
p = (DIR*)malloc(sizeof(DIR));
11+
memset(p, 0, sizeof(DIR));
12+
strncpy(p->dd_name, name, PATH_MAX);
13+
len = strlen(p->dd_name);
14+
p->dd_name[len] = '/';
15+
p->dd_name[len+1] = '*';
16+
17+
if (p == NULL)
18+
return NULL;
19+
20+
p->dd_handle = _findfirst(p->dd_name, &p->dd_dta);
21+
22+
if (p->dd_handle == -1) {
23+
free(p);
24+
return NULL;
25+
}
26+
return p;
27+
}
28+
int closedir(DIR *dir)
29+
{
30+
_findclose(dir->dd_handle);
31+
free(dir);
32+
return 0;
33+
}
34+
35+
#include "mingw.c"

compat/msvc.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#ifndef __MSVC__HEAD
2+
#define __MSVC__HEAD
3+
4+
/* Define minimize windows version */
5+
#define WINVER 0x0500
6+
#define _WIN32_WINNT 0x0500
7+
#define _WIN32_WINDOWS 0x0410
8+
#define _WIN32_IE 0x0700
9+
#define NTDDI_VERSION NTDDI_WIN2KSP1
10+
#include <winsock2.h>
11+
#include <direct.h>
12+
#include <process.h>
13+
#include <malloc.h>
14+
15+
/* porting function */
16+
#define inline __inline
17+
#define __inline__ __inline
18+
#define __attribute__(x)
19+
#define va_copy(dst, src) ((dst) = (src))
20+
21+
static __inline int strcasecmp (const char *s1, const char *s2)
22+
{
23+
int size1 = strlen(s1);
24+
int sisz2 = strlen(s2);
25+
return _strnicmp(s1, s2, sisz2 > size1 ? sisz2 : size1);
26+
}
27+
28+
#undef ERROR
29+
#undef stat
30+
#undef _stati64
31+
#include "compat/mingw.h"
32+
#undef stat
33+
#define stat _stati64
34+
#define _stat64(x,y) mingw_lstat(x,y)
35+
36+
/*
37+
Even though _stati64 is normally just defined at _stat64
38+
on Windows, we specify it here as a proper struct to avoid
39+
compiler warnings about macro redefinition due to magic in
40+
mingw.h. Struct taken from ReactOS (GNU GPL license).
41+
*/
42+
struct _stati64 {
43+
_dev_t st_dev;
44+
_ino_t st_ino;
45+
unsigned short st_mode;
46+
short st_nlink;
47+
short st_uid;
48+
short st_gid;
49+
_dev_t st_rdev;
50+
__int64 st_size;
51+
time_t st_atime;
52+
time_t st_mtime;
53+
time_t st_ctime;
54+
};
55+
#endif

git-compat-util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@
113113
/* pull in Windows compatibility stuff */
114114
#include "compat/mingw.h"
115115
#endif /* __MINGW32__ */
116+
#ifdef _MSC_VER
117+
#include "compat/msvc.h"
118+
#endif
116119

117120
#ifndef NO_LIBGEN_H
118121
#include <libgen.h>

0 commit comments

Comments
 (0)