compat/mingw: split out POSIX-related bits
Split out POSIX-related bits from "compat/mingw.h" and "compat/msvc.h". This is in preparation for splitting up "git-compat-utils.h" into a header that provides POSIX-compatibility and a header that provides common wrappers used by the Git project. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Feb 18, 2025 at 10:20 UTC
0b960a53daa1b336bcec5810f70d8af8ced86ca8
4 files changed
+467
-453
compat/mingw-posix.h
new
+431
@@ -0,0 +1,431 @@
1
+#ifndef COMPAT_MINGW_POSIX_H
2
+#define COMPAT_MINGW_POSIX_H
3
+
4
+#ifdef __MINGW64_VERSION_MAJOR
5
+#include <stdint.h>
6
+#include <wchar.h>
7
+typedef _sigset_t sigset_t;
8
+#endif
9
+#include <winsock2.h>
10
+#include <ws2tcpip.h>
11
+
12
+/* MinGW-w64 reports to have flockfile, but it does not actually have it. */
13
+#ifdef __MINGW64_VERSION_MAJOR
14
+#undef _POSIX_THREAD_SAFE_FUNCTIONS
15
+#endif
16
+
17
+/*
18
+ * things that are not available in header files
19
+ */
20
+
21
+typedef int uid_t;
22
+typedef int socklen_t;
23
+#ifndef __MINGW64_VERSION_MAJOR
24
+typedef int pid_t;
25
+#define hstrerror strerror
26
+#endif
27
+
28
+#define S_IFLNK 0120000 /* Symbolic link */
29
+#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
30
+#define S_ISSOCK(x) 0
31
+
32
+#ifndef S_IRWXG
33
+#define S_IRGRP 0
34
+#define S_IWGRP 0
35
+#define S_IXGRP 0
36
+#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
37
+#endif
38
+#ifndef S_IRWXO
39
+#define S_IROTH 0
40
+#define S_IWOTH 0
41
+#define S_IXOTH 0
42
+#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
43
+#endif
44
+
45
+#define S_ISUID 0004000
46
+#define S_ISGID 0002000
47
+#define S_ISVTX 0001000
48
+
49
+#define WIFEXITED(x) 1
50
+#define WIFSIGNALED(x) 0
51
+#define WEXITSTATUS(x) ((x) & 0xff)
52
+#define WTERMSIG(x) SIGTERM
53
+
54
+#ifndef EWOULDBLOCK
55
+#define EWOULDBLOCK EAGAIN
56
+#endif
57
+#ifndef ELOOP
58
+#define ELOOP EMLINK
59
+#endif
60
+#define SHUT_WR SD_SEND
61
+
62
+#define SIGHUP 1
63
+#define SIGQUIT 3
64
+#define SIGKILL 9
65
+#define SIGPIPE 13
66
+#define SIGALRM 14
67
+#define SIGCHLD 17
68
+
69
+#define F_GETFD 1
70
+#define F_SETFD 2
71
+#define FD_CLOEXEC 0x1
72
+
73
+#if !defined O_CLOEXEC && defined O_NOINHERIT
74
+#define O_CLOEXEC O_NOINHERIT
75
+#endif
76
+
77
+#ifndef EAFNOSUPPORT
78
+#define EAFNOSUPPORT WSAEAFNOSUPPORT
79
+#endif
80
+#ifndef ECONNABORTED
81
+#define ECONNABORTED WSAECONNABORTED
82
+#endif
83
+#ifndef ENOTSOCK
84
+#define ENOTSOCK WSAENOTSOCK
85
+#endif
86
+
87
+struct passwd {
88
+ char *pw_name;
89
+ char *pw_gecos;
90
+ char *pw_dir;
91
+};
92
+
93
+typedef void (__cdecl *sig_handler_t)(int);
94
+struct sigaction {
95
+ sig_handler_t sa_handler;
96
+ unsigned sa_flags;
97
+};
98
+#define SA_RESTART 0
99
+
100
+struct itimerval {
101
+ struct timeval it_value, it_interval;
102
+};
103
+#define ITIMER_REAL 0
104
+
105
+struct utsname {
106
+ char sysname[16];
107
+ char nodename[1];
108
+ char release[16];
109
+ char version[16];
110
+ char machine[1];
111
+};
112
+
113
+/*
114
+ * sanitize preprocessor namespace polluted by Windows headers defining
115
+ * macros which collide with git local versions
116
+ */
117
+#undef HELP_COMMAND /* from winuser.h */
118
+
119
+/*
120
+ * trivial stubs
121
+ */
122
+
123
+static inline int readlink(const char *path UNUSED, char *buf UNUSED, size_t bufsiz UNUSED)
124
+{ errno = ENOSYS; return -1; }
125
+static inline int symlink(const char *oldpath UNUSED, const char *newpath UNUSED)
126
+{ errno = ENOSYS; return -1; }
127
+static inline int fchmod(int fildes UNUSED, mode_t mode UNUSED)
128
+{ errno = ENOSYS; return -1; }
129
+#ifndef __MINGW64_VERSION_MAJOR
130
+static inline pid_t fork(void)
131
+{ errno = ENOSYS; return -1; }
132
+#endif
133
+static inline unsigned int alarm(unsigned int seconds UNUSED)
134
+{ return 0; }
135
+static inline int fsync(int fd)
136
+{ return _commit(fd); }
137
+static inline void sync(void)
138
+{}
139
+static inline uid_t getuid(void)
140
+{ return 1; }
141
+static inline struct passwd *getpwnam(const char *name UNUSED)
142
+{ return NULL; }
143
+static inline int fcntl(int fd UNUSED, int cmd, ...)
144
+{
145
+ if (cmd == F_GETFD || cmd == F_SETFD)
146
+ return 0;
147
+ errno = EINVAL;
148
+ return -1;
149
+}
150
+
151
+#define sigemptyset(x) (void)0
152
+static inline int sigaddset(sigset_t *set UNUSED, int signum UNUSED)
153
+{ return 0; }
154
+#define SIG_BLOCK 0
155
+#define SIG_UNBLOCK 0
156
+static inline int sigprocmask(int how UNUSED, const sigset_t *set UNUSED, sigset_t *oldset UNUSED)
157
+{ return 0; }
158
+static inline pid_t getppid(void)
159
+{ return 1; }
160
+static inline pid_t getpgid(pid_t pid)
161
+{ return pid == 0 ? getpid() : pid; }
162
+static inline pid_t tcgetpgrp(int fd UNUSED)
163
+{ return getpid(); }
164
+
165
+/*
166
+ * simple adaptors
167
+ */
168
+
169
+int mingw_mkdir(const char *path, int mode);
170
+#define mkdir mingw_mkdir
171
+
172
+#define WNOHANG 1
173
+pid_t waitpid(pid_t pid, int *status, int options);
174
+
175
+#define kill mingw_kill
176
+int mingw_kill(pid_t pid, int sig);
177
+
178
+#define locate_in_PATH mingw_locate_in_PATH
179
+char *mingw_locate_in_PATH(const char *cmd);
180
+
181
+/*
182
+ * implementations of missing functions
183
+ */
184
+
185
+int pipe(int filedes[2]);
186
+unsigned int sleep (unsigned int seconds);
187
+int mkstemp(char *template);
188
+int gettimeofday(struct timeval *tv, void *tz);
189
+#ifndef __MINGW64_VERSION_MAJOR
190
+struct tm *gmtime_r(const time_t *timep, struct tm *result);
191
+struct tm *localtime_r(const time_t *timep, struct tm *result);
192
+#endif
193
+int getpagesize(void); /* defined in MinGW's libgcc.a */
194
+struct passwd *getpwuid(uid_t uid);
195
+int setitimer(int type, struct itimerval *in, struct itimerval *out);
196
+int sigaction(int sig, struct sigaction *in, struct sigaction *out);
197
+int link(const char *oldpath, const char *newpath);
198
+int uname(struct utsname *buf);
199
+
200
+/*
201
+ * replacements of existing functions
202
+ */
203
+
204
+int mingw_unlink(const char *pathname);
205
+#define unlink mingw_unlink
206
+
207
+int mingw_rmdir(const char *path);
208
+#define rmdir mingw_rmdir
209
+
210
+int mingw_open (const char *filename, int oflags, ...);
211
+#define open mingw_open
212
+#undef OPEN_RETURNS_EINTR
213
+
214
+int mingw_fgetc(FILE *stream);
215
+#define fgetc mingw_fgetc
216
+
217
+FILE *mingw_fopen (const char *filename, const char *otype);
218
+#define fopen mingw_fopen
219
+
220
+FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream);
221
+#define freopen mingw_freopen
222
+
223
+int mingw_fflush(FILE *stream);
224
+#define fflush mingw_fflush
225
+
226
+ssize_t mingw_write(int fd, const void *buf, size_t len);
227
+#define write mingw_write
228
+
229
+int mingw_access(const char *filename, int mode);
230
+#undef access
231
+#define access mingw_access
232
+
233
+int mingw_chdir(const char *dirname);
234
+#define chdir mingw_chdir
235
+
236
+int mingw_chmod(const char *filename, int mode);
237
+#define chmod mingw_chmod
238
+
239
+char *mingw_mktemp(char *template);
240
+#define mktemp mingw_mktemp
241
+
242
+char *mingw_getcwd(char *pointer, int len);
243
+#define getcwd mingw_getcwd
244
+
245
+#ifdef NO_UNSETENV
246
+#error "NO_UNSETENV is incompatible with the Windows-specific startup code!"
247
+#endif
248
+
249
+/*
250
+ * We bind *env() routines (even the mingw_ ones) to private mingw_ versions.
251
+ * These talk to the CRT using UNICODE/wchar_t, but maintain the original
252
+ * narrow-char API.
253
+ *
254
+ * Note that the MSCRT maintains both ANSI (getenv()) and UNICODE (_wgetenv())
255
+ * routines and stores both versions of each environment variable in parallel
256
+ * (and secretly updates both when you set one or the other), but it uses CP_ACP
257
+ * to do the conversion rather than CP_UTF8.
258
+ *
259
+ * Since everything in the git code base is UTF8, we define the mingw_ routines
260
+ * to access the CRT using the UNICODE routines and manually convert them to
261
+ * UTF8. This also avoids round-trip problems.
262
+ *
263
+ * This also helps with our linkage, since "_wenviron" is publicly exported
264
+ * from the CRT. But to access "_environ" we would have to statically link
265
+ * to the CRT (/MT).
266
+ *
267
+ * We require NO_SETENV (and let gitsetenv() call our mingw_putenv).
268
+ */
269
+#define getenv mingw_getenv
270
+#define putenv mingw_putenv
271
+#define unsetenv mingw_putenv
272
+char *mingw_getenv(const char *name);
273
+int mingw_putenv(const char *name);
274
+
275
+int mingw_gethostname(char *host, int namelen);
276
+#define gethostname mingw_gethostname
277
+
278
+struct hostent *mingw_gethostbyname(const char *host);
279
+#define gethostbyname mingw_gethostbyname
280
+
281
+int mingw_getaddrinfo(const char *node, const char *service,
282
+ const struct addrinfo *hints, struct addrinfo **res);
283
+#define getaddrinfo mingw_getaddrinfo
284
+
285
+int mingw_socket(int domain, int type, int protocol);
286
+#define socket mingw_socket
287
+
288
+int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz);
289
+#define connect mingw_connect
290
+
291
+int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz);
292
+#define bind mingw_bind
293
+
294
+int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen);
295
+#define setsockopt mingw_setsockopt
296
+
297
+int mingw_shutdown(int sockfd, int how);
298
+#define shutdown mingw_shutdown
299
+
300
+int mingw_listen(int sockfd, int backlog);
301
+#define listen mingw_listen
302
+
303
+int mingw_accept(int sockfd, struct sockaddr *sa, socklen_t *sz);
304
+#define accept mingw_accept
305
+
306
+int mingw_rename(const char*, const char*);
307
+#define rename mingw_rename
308
+
309
+#if defined(USE_WIN32_MMAP) || defined(_MSC_VER)
310
+int mingw_getpagesize(void);
311
+#define getpagesize mingw_getpagesize
312
+#endif
313
+
314
+int win32_fsync_no_flush(int fd);
315
+#define fsync_no_flush win32_fsync_no_flush
316
+
317
+#define FSYNC_COMPONENTS_PLATFORM_DEFAULT (FSYNC_COMPONENTS_DEFAULT | FSYNC_COMPONENT_LOOSE_OBJECT)
318
+#define FSYNC_METHOD_DEFAULT (FSYNC_METHOD_BATCH)
319
+
320
+struct rlimit {
321
+ unsigned int rlim_cur;
322
+};
323
+#define RLIMIT_NOFILE 0
324
+
325
+static inline int getrlimit(int resource, struct rlimit *rlp)
326
+{
327
+ if (resource != RLIMIT_NOFILE) {
328
+ errno = EINVAL;
329
+ return -1;
330
+ }
331
+
332
+ rlp->rlim_cur = 2048;
333
+ return 0;
334
+}
335
+
336
+/*
337
+ * Use mingw specific stat()/lstat()/fstat() implementations on Windows,
338
+ * including our own struct stat with 64 bit st_size and nanosecond-precision
339
+ * file times.
340
+ */
341
+#ifndef __MINGW64_VERSION_MAJOR
342
+#define off_t off64_t
343
+#define lseek _lseeki64
344
+#ifndef _MSC_VER
345
+struct timespec {
346
+ time_t tv_sec;
347
+ long tv_nsec;
348
+};
349
+#endif
350
+#endif
351
+
352
+struct mingw_stat {
353
+ _dev_t st_dev;
354
+ _ino_t st_ino;
355
+ _mode_t st_mode;
356
+ short st_nlink;
357
+ short st_uid;
358
+ short st_gid;
359
+ _dev_t st_rdev;
360
+ off64_t st_size;
361
+ struct timespec st_atim;
362
+ struct timespec st_mtim;
363
+ struct timespec st_ctim;
364
+};
365
+
366
+#define st_atime st_atim.tv_sec
367
+#define st_mtime st_mtim.tv_sec
368
+#define st_ctime st_ctim.tv_sec
369
+
370
+#ifdef stat
371
+#undef stat
372
+#endif
373
+#define stat mingw_stat
374
+int mingw_lstat(const char *file_name, struct stat *buf);
375
+int mingw_stat(const char *file_name, struct stat *buf);
376
+int mingw_fstat(int fd, struct stat *buf);
377
+#ifdef fstat
378
+#undef fstat
379
+#endif
380
+#define fstat mingw_fstat
381
+#ifdef lstat
382
+#undef lstat
383
+#endif
384
+#define lstat mingw_lstat
385
+
386
+
387
+int mingw_utime(const char *file_name, const struct utimbuf *times);
388
+#define utime mingw_utime
389
+size_t mingw_strftime(char *s, size_t max,
390
+ const char *format, const struct tm *tm);
391
+#define strftime mingw_strftime
392
+
393
+pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
394
+ const char *dir,
395
+ int fhin, int fhout, int fherr);
396
+int mingw_execvp(const char *cmd, char *const *argv);
397
+#define execvp mingw_execvp
398
+int mingw_execv(const char *cmd, char *const *argv);
399
+#define execv mingw_execv
400
+
401
+static inline unsigned int git_ntohl(unsigned int x)
402
+{ return (unsigned int)ntohl(x); }
403
+#define ntohl git_ntohl
404
+
405
+sig_handler_t mingw_signal(int sig, sig_handler_t handler);
406
+#define signal mingw_signal
407
+
408
+int mingw_raise(int sig);
409
+#define raise mingw_raise
410
+
411
+/*
412
+ * ANSI emulation wrappers
413
+ */
414
+
415
+int winansi_isatty(int fd);
416
+#define isatty winansi_isatty
417
+
418
+int winansi_dup2(int oldfd, int newfd);
419
+#define dup2 winansi_dup2
420
+
421
+void winansi_init(void);
422
+HANDLE winansi_get_osfhandle(int fd);
423
+
424
+#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
425
+#define PRIuMAX "I64u"
426
+#define PRId64 "I64d"
427
+#else
428
+#include <inttypes.h>
429
+#endif
430
+
431
+#endif /* COMPAT_MINGW_POSIX_H */
compat/mingw.h
+1
-425
@@ -1,185 +1,10 @@
1
-#ifdef __MINGW64_VERSION_MAJOR
2
-#include <stdint.h>
3
-#include <wchar.h>
4
-typedef _sigset_t sigset_t;
5
-#endif
6
-#include <winsock2.h>
7
-#include <ws2tcpip.h>
8
-
9
-/* MinGW-w64 reports to have flockfile, but it does not actually have it. */
10
-#ifdef __MINGW64_VERSION_MAJOR
11
-#undef _POSIX_THREAD_SAFE_FUNCTIONS
12
-#endif
1
+#include "mingw-posix.h"
2
3
struct config_context;
4
int mingw_core_config(const char *var, const char *value,
5
const struct config_context *ctx, void *cb);
6
#define platform_core_config mingw_core_config
7
19
-/*
20
- * things that are not available in header files
21
- */
22
-
23
-typedef int uid_t;
24
-typedef int socklen_t;
25
-#ifndef __MINGW64_VERSION_MAJOR
26
-typedef int pid_t;
27
-#define hstrerror strerror
28
-#endif
29
-
30
-#define S_IFLNK 0120000 /* Symbolic link */
31
-#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
32
-#define S_ISSOCK(x) 0
33
-
34
-#ifndef S_IRWXG
35
-#define S_IRGRP 0
36
-#define S_IWGRP 0
37
-#define S_IXGRP 0
38
-#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
39
-#endif
40
-#ifndef S_IRWXO
41
-#define S_IROTH 0
42
-#define S_IWOTH 0
43
-#define S_IXOTH 0
44
-#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
45
-#endif
46
-
47
-#define S_ISUID 0004000
48
-#define S_ISGID 0002000
49
-#define S_ISVTX 0001000
50
-
51
-#define WIFEXITED(x) 1
52
-#define WIFSIGNALED(x) 0
53
-#define WEXITSTATUS(x) ((x) & 0xff)
54
-#define WTERMSIG(x) SIGTERM
55
-
56
-#ifndef EWOULDBLOCK
57
-#define EWOULDBLOCK EAGAIN
58
-#endif
59
-#ifndef ELOOP
60
-#define ELOOP EMLINK
61
-#endif
62
-#define SHUT_WR SD_SEND
63
-
64
-#define SIGHUP 1
65
-#define SIGQUIT 3
66
-#define SIGKILL 9
67
-#define SIGPIPE 13
68
-#define SIGALRM 14
69
-#define SIGCHLD 17
70
-
71
-#define F_GETFD 1
72
-#define F_SETFD 2
73
-#define FD_CLOEXEC 0x1
74
-
75
-#if !defined O_CLOEXEC && defined O_NOINHERIT
76
-#define O_CLOEXEC O_NOINHERIT
77
-#endif
78
-
79
-#ifndef EAFNOSUPPORT
80
-#define EAFNOSUPPORT WSAEAFNOSUPPORT
81
-#endif
82
-#ifndef ECONNABORTED
83
-#define ECONNABORTED WSAECONNABORTED
84
-#endif
85
-#ifndef ENOTSOCK
86
-#define ENOTSOCK WSAENOTSOCK
87
-#endif
88
-
89
-struct passwd {
90
- char *pw_name;
91
- char *pw_gecos;
92
- char *pw_dir;
93
-};
94
-
95
-typedef void (__cdecl *sig_handler_t)(int);
96
-struct sigaction {
97
- sig_handler_t sa_handler;
98
- unsigned sa_flags;
99
-};
100
-#define SA_RESTART 0
101
-
102
-struct itimerval {
103
- struct timeval it_value, it_interval;
104
-};
105
-#define ITIMER_REAL 0
106
-
107
-struct utsname {
108
- char sysname[16];
109
- char nodename[1];
110
- char release[16];
111
- char version[16];
112
- char machine[1];
113
-};
114
-
115
-/*
116
- * sanitize preprocessor namespace polluted by Windows headers defining
117
- * macros which collide with git local versions
118
- */
119
-#undef HELP_COMMAND /* from winuser.h */
120
-
121
-/*
122
- * trivial stubs
123
- */
124
-
125
-static inline int readlink(const char *path UNUSED, char *buf UNUSED, size_t bufsiz UNUSED)
126
-{ errno = ENOSYS; return -1; }
127
-static inline int symlink(const char *oldpath UNUSED, const char *newpath UNUSED)
128
-{ errno = ENOSYS; return -1; }
129
-static inline int fchmod(int fildes UNUSED, mode_t mode UNUSED)
130
-{ errno = ENOSYS; return -1; }
131
-#ifndef __MINGW64_VERSION_MAJOR
132
-static inline pid_t fork(void)
133
-{ errno = ENOSYS; return -1; }
134
-#endif
135
-static inline unsigned int alarm(unsigned int seconds UNUSED)
136
-{ return 0; }
137
-static inline int fsync(int fd)
138
-{ return _commit(fd); }
139
-static inline void sync(void)
140
-{}
141
-static inline uid_t getuid(void)
142
-{ return 1; }
143
-static inline struct passwd *getpwnam(const char *name UNUSED)
144
-{ return NULL; }
145
-static inline int fcntl(int fd UNUSED, int cmd, ...)
146
-{
147
- if (cmd == F_GETFD || cmd == F_SETFD)
148
- return 0;
149
- errno = EINVAL;
150
- return -1;
151
-}
152
-
153
-#define sigemptyset(x) (void)0
154
-static inline int sigaddset(sigset_t *set UNUSED, int signum UNUSED)
155
-{ return 0; }
156
-#define SIG_BLOCK 0
157
-#define SIG_UNBLOCK 0
158
-static inline int sigprocmask(int how UNUSED, const sigset_t *set UNUSED, sigset_t *oldset UNUSED)
159
-{ return 0; }
160
-static inline pid_t getppid(void)
161
-{ return 1; }
162
-static inline pid_t getpgid(pid_t pid)
163
-{ return pid == 0 ? getpid() : pid; }
164
-static inline pid_t tcgetpgrp(int fd UNUSED)
165
-{ return getpid(); }
166
-
167
-/*
168
- * simple adaptors
169
- */
170
-
171
-int mingw_mkdir(const char *path, int mode);
172
-#define mkdir mingw_mkdir
173
-
174
-#define WNOHANG 1
175
-pid_t waitpid(pid_t pid, int *status, int options);
176
-
177
-#define kill mingw_kill
178
-int mingw_kill(pid_t pid, int sig);
179
-
180
-#define locate_in_PATH mingw_locate_in_PATH
181
-char *mingw_locate_in_PATH(const char *cmd);
182
-
8
#ifndef NO_OPENSSL
9
#include <openssl/ssl.h>
10
static inline int mingw_SSL_set_fd(SSL *ssl, int fd)
@@ -201,249 +26,6 @@ static inline int mingw_SSL_set_wfd(SSL *ssl, int fd)
26
#define SSL_set_wfd mingw_SSL_set_wfd
27
#endif
28
204
-/*
205
- * implementations of missing functions
206
- */
207
-
208
-int pipe(int filedes[2]);
209
-unsigned int sleep (unsigned int seconds);
210
-int mkstemp(char *template);
211
-int gettimeofday(struct timeval *tv, void *tz);
212
-#ifndef __MINGW64_VERSION_MAJOR
213
-struct tm *gmtime_r(const time_t *timep, struct tm *result);
214
-struct tm *localtime_r(const time_t *timep, struct tm *result);
215
-#endif
216
-int getpagesize(void); /* defined in MinGW's libgcc.a */
217
-struct passwd *getpwuid(uid_t uid);
218
-int setitimer(int type, struct itimerval *in, struct itimerval *out);
219
-int sigaction(int sig, struct sigaction *in, struct sigaction *out);
220
-int link(const char *oldpath, const char *newpath);
221
-int uname(struct utsname *buf);
222
-
223
-/*
224
- * replacements of existing functions
225
- */
226
-
227
-int mingw_unlink(const char *pathname);
228
-#define unlink mingw_unlink
229
-
230
-int mingw_rmdir(const char *path);
231
-#define rmdir mingw_rmdir
232
-
233
-int mingw_open (const char *filename, int oflags, ...);
234
-#define open mingw_open
235
-#undef OPEN_RETURNS_EINTR
236
-
237
-int mingw_fgetc(FILE *stream);
238
-#define fgetc mingw_fgetc
239
-
240
-FILE *mingw_fopen (const char *filename, const char *otype);
241
-#define fopen mingw_fopen
242
-
243
-FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream);
244
-#define freopen mingw_freopen
245
-
246
-int mingw_fflush(FILE *stream);
247
-#define fflush mingw_fflush
248
-
249
-ssize_t mingw_write(int fd, const void *buf, size_t len);
250
-#define write mingw_write
251
-
252
-int mingw_access(const char *filename, int mode);
253
-#undef access
254
-#define access mingw_access
255
-
256
-int mingw_chdir(const char *dirname);
257
-#define chdir mingw_chdir
258
-
259
-int mingw_chmod(const char *filename, int mode);
260
-#define chmod mingw_chmod
261
-
262
-char *mingw_mktemp(char *template);
263
-#define mktemp mingw_mktemp
264
-
265
-char *mingw_getcwd(char *pointer, int len);
266
-#define getcwd mingw_getcwd
267
-
268
-#ifdef NO_UNSETENV
269
-#error "NO_UNSETENV is incompatible with the Windows-specific startup code!"
270
-#endif
271
-
272
-/*
273
- * We bind *env() routines (even the mingw_ ones) to private mingw_ versions.
274
- * These talk to the CRT using UNICODE/wchar_t, but maintain the original
275
- * narrow-char API.
276
- *
277
- * Note that the MSCRT maintains both ANSI (getenv()) and UNICODE (_wgetenv())
278
- * routines and stores both versions of each environment variable in parallel
279
- * (and secretly updates both when you set one or the other), but it uses CP_ACP
280
- * to do the conversion rather than CP_UTF8.
281
- *
282
- * Since everything in the git code base is UTF8, we define the mingw_ routines
283
- * to access the CRT using the UNICODE routines and manually convert them to
284
- * UTF8. This also avoids round-trip problems.
285
- *
286
- * This also helps with our linkage, since "_wenviron" is publicly exported
287
- * from the CRT. But to access "_environ" we would have to statically link
288
- * to the CRT (/MT).
289
- *
290
- * We require NO_SETENV (and let gitsetenv() call our mingw_putenv).
291
- */
292
-#define getenv mingw_getenv
293
-#define putenv mingw_putenv
294
-#define unsetenv mingw_putenv
295
-char *mingw_getenv(const char *name);
296
-int mingw_putenv(const char *name);
297
-
298
-int mingw_gethostname(char *host, int namelen);
299
-#define gethostname mingw_gethostname
300
-
301
-struct hostent *mingw_gethostbyname(const char *host);
302
-#define gethostbyname mingw_gethostbyname
303
-
304
-int mingw_getaddrinfo(const char *node, const char *service,
305
- const struct addrinfo *hints, struct addrinfo **res);
306
-#define getaddrinfo mingw_getaddrinfo
307
-
308
-int mingw_socket(int domain, int type, int protocol);
309
-#define socket mingw_socket
310
-
311
-int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz);
312
-#define connect mingw_connect
313
-
314
-int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz);
315
-#define bind mingw_bind
316
-
317
-int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen);
318
-#define setsockopt mingw_setsockopt
319
-
320
-int mingw_shutdown(int sockfd, int how);
321
-#define shutdown mingw_shutdown
322
-
323
-int mingw_listen(int sockfd, int backlog);
324
-#define listen mingw_listen
325
-
326
-int mingw_accept(int sockfd, struct sockaddr *sa, socklen_t *sz);
327
-#define accept mingw_accept
328
-
329
-int mingw_rename(const char*, const char*);
330
-#define rename mingw_rename
331
-
332
-#if defined(USE_WIN32_MMAP) || defined(_MSC_VER)
333
-int mingw_getpagesize(void);
334
-#define getpagesize mingw_getpagesize
335
-#endif
336
-
337
-int win32_fsync_no_flush(int fd);
338
-#define fsync_no_flush win32_fsync_no_flush
339
-
340
-#define FSYNC_COMPONENTS_PLATFORM_DEFAULT (FSYNC_COMPONENTS_DEFAULT | FSYNC_COMPONENT_LOOSE_OBJECT)
341
-#define FSYNC_METHOD_DEFAULT (FSYNC_METHOD_BATCH)
342
-
343
-struct rlimit {
344
- unsigned int rlim_cur;
345
-};
346
-#define RLIMIT_NOFILE 0
347
-
348
-static inline int getrlimit(int resource, struct rlimit *rlp)
349
-{
350
- if (resource != RLIMIT_NOFILE) {
351
- errno = EINVAL;
352
- return -1;
353
- }
354
-
355
- rlp->rlim_cur = 2048;
356
- return 0;
357
-}
358
-
359
-/*
360
- * Use mingw specific stat()/lstat()/fstat() implementations on Windows,
361
- * including our own struct stat with 64 bit st_size and nanosecond-precision
362
- * file times.
363
- */
364
-#ifndef __MINGW64_VERSION_MAJOR
365
-#define off_t off64_t
366
-#define lseek _lseeki64
367
-#ifndef _MSC_VER
368
-struct timespec {
369
- time_t tv_sec;
370
- long tv_nsec;
371
-};
372
-#endif
373
-#endif
374
-
375
-struct mingw_stat {
376
- _dev_t st_dev;
377
- _ino_t st_ino;
378
- _mode_t st_mode;
379
- short st_nlink;
380
- short st_uid;
381
- short st_gid;
382
- _dev_t st_rdev;
383
- off64_t st_size;
384
- struct timespec st_atim;
385
- struct timespec st_mtim;
386
- struct timespec st_ctim;
387
-};
388
-
389
-#define st_atime st_atim.tv_sec
390
-#define st_mtime st_mtim.tv_sec
391
-#define st_ctime st_ctim.tv_sec
392
-
393
-#ifdef stat
394
-#undef stat
395
-#endif
396
-#define stat mingw_stat
397
-int mingw_lstat(const char *file_name, struct stat *buf);
398
-int mingw_stat(const char *file_name, struct stat *buf);
399
-int mingw_fstat(int fd, struct stat *buf);
400
-#ifdef fstat
401
-#undef fstat
402
-#endif
403
-#define fstat mingw_fstat
404
-#ifdef lstat
405
-#undef lstat
406
-#endif
407
-#define lstat mingw_lstat
408
-
409
-
410
-int mingw_utime(const char *file_name, const struct utimbuf *times);
411
-#define utime mingw_utime
412
-size_t mingw_strftime(char *s, size_t max,
413
- const char *format, const struct tm *tm);
414
-#define strftime mingw_strftime
415
-
416
-pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
417
- const char *dir,
418
- int fhin, int fhout, int fherr);
419
-int mingw_execvp(const char *cmd, char *const *argv);
420
-#define execvp mingw_execvp
421
-int mingw_execv(const char *cmd, char *const *argv);
422
-#define execv mingw_execv
423
-
424
-static inline unsigned int git_ntohl(unsigned int x)
425
-{ return (unsigned int)ntohl(x); }
426
-#define ntohl git_ntohl
427
-
428
-sig_handler_t mingw_signal(int sig, sig_handler_t handler);
429
-#define signal mingw_signal
430
-
431
-int mingw_raise(int sig);
432
-#define raise mingw_raise
433
-
434
-/*
435
- * ANSI emulation wrappers
436
- */
437
-
438
-int winansi_isatty(int fd);
439
-#define isatty winansi_isatty
440
-
441
-int winansi_dup2(int oldfd, int newfd);
442
-#define dup2 winansi_dup2
443
-
444
-void winansi_init(void);
445
-HANDLE winansi_get_osfhandle(int fd);
446
-
29
/*
30
* git specific compatibility
31
*/
@@ -457,12 +39,6 @@ static inline void convert_slashes(char *path)
39
#define PATH_SEP ';'
40
char *mingw_query_user_email(void);
41
#define query_user_email mingw_query_user_email
460
-#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
461
-#define PRIuMAX "I64u"
462
-#define PRId64 "I64d"
463
-#else
464
-#include <inttypes.h>
465
-#endif
42
43
/**
44
* Verifies that the specified path is owned by the user running the
compat/msvc-posix.h
new
+33
@@ -0,0 +1,33 @@
1
+#ifndef COMPAT_MSVC_POSIX_H
2
+#define COMPAT_MSVC_POSIX_H
3
+
4
+#include <direct.h>
5
+#include <process.h>
6
+#include <malloc.h>
7
+#include <io.h>
8
+
9
+#pragma warning(disable: 4018) /* signed/unsigned comparison */
10
+#pragma warning(disable: 4244) /* type conversion, possible loss of data */
11
+#pragma warning(disable: 4090) /* 'function' : different 'const' qualifiers (ALLOC_GROW etc.)*/
12
+
13
+/* porting function */
14
+#define inline __inline
15
+#define __inline__ __inline
16
+#define __attribute__(x)
17
+#define strcasecmp _stricmp
18
+#define strncasecmp _strnicmp
19
+#define ftruncate _chsize
20
+#define strtoull _strtoui64
21
+#define strtoll _strtoi64
22
+
23
+#undef ERROR
24
+
25
+#define ftello _ftelli64
26
+
27
+typedef int sigset_t;
28
+/* open for reading, writing, or both (not in fcntl.h) */
29
+#define O_ACCMODE (_O_RDONLY | _O_WRONLY | _O_RDWR)
30
+
31
+#include "mingw-posix.h"
32
+
33
+#endif /* COMPAT_MSVC_POSIX_H */
compat/msvc.h
+2
-28
@@ -1,33 +1,7 @@
1
#ifndef __MSVC__HEAD
2
#define __MSVC__HEAD
3
4
-#include <direct.h>
5
-#include <process.h>
6
-#include <malloc.h>
7
-#include <io.h>
8
-
9
-#pragma warning(disable: 4018) /* signed/unsigned comparison */
10
-#pragma warning(disable: 4244) /* type conversion, possible loss of data */
11
-#pragma warning(disable: 4090) /* 'function' : different 'const' qualifiers (ALLOC_GROW etc.)*/
12
-
13
-/* porting function */
14
-#define inline __inline
15
-#define __inline__ __inline
16
-#define __attribute__(x)
17
-#define strcasecmp _stricmp
18
-#define strncasecmp _strnicmp
19
-#define ftruncate _chsize
20
-#define strtoull _strtoui64
21
-#define strtoll _strtoi64
22
-
23
-#undef ERROR
24
-
25
-#define ftello _ftelli64
26
-
27
-typedef int sigset_t;
28
-/* open for reading, writing, or both (not in fcntl.h) */
29
-#define O_ACCMODE (_O_RDONLY | _O_WRONLY | _O_RDWR)
30
-
31
-#include "compat/mingw.h"
4
+#include "msvc-posix.h"
5
+#include "mingw.h"
6
7
#endif