]> git.ipfire.org Git - thirdparty/git.git/blame - compat/mingw.h
Windows: Implement start_command().
[thirdparty/git.git] / compat / mingw.h
CommitLineData
f4626df5
JS
1#include <winsock2.h>
2
3/*
4 * things that are not available in header files
5 */
6
7typedef int pid_t;
8#define hstrerror strerror
9
10#define S_IFLNK 0120000 /* Symbolic link */
11#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
12#define S_ISSOCK(x) 0
13#define S_IRGRP 0
14#define S_IWGRP 0
15#define S_IXGRP 0
16#define S_ISGID 0
17#define S_IROTH 0
18#define S_IXOTH 0
19
20#define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */
21#define WEXITSTATUS(x) ((x) & 0xff)
22#define WIFSIGNALED(x) ((unsigned)(x) > 259)
23
24#define SIGKILL 0
25#define SIGCHLD 0
26#define SIGPIPE 0
27#define SIGHUP 0
28#define SIGQUIT 0
29#define SIGALRM 100
30
31#define F_GETFD 1
32#define F_SETFD 2
33#define FD_CLOEXEC 0x1
34
35struct passwd {
36 char *pw_name;
37 char *pw_gecos;
38 char *pw_dir;
39};
40
41struct pollfd {
42 int fd; /* file descriptor */
43 short events; /* requested events */
44 short revents; /* returned events */
45};
46#define POLLIN 1
47#define POLLHUP 2
48
49typedef void (__cdecl *sig_handler_t)(int);
50struct sigaction {
51 sig_handler_t sa_handler;
52 unsigned sa_flags;
53};
54#define sigemptyset(x) (void)0
55#define SA_RESTART 0
56
57struct itimerval {
58 struct timeval it_value, it_interval;
59};
60#define ITIMER_REAL 0
61
62#define st_blocks st_size/512 /* will be cleaned up later */
63#define lstat stat
64
65/*
66 * trivial stubs
67 */
68
69static inline int readlink(const char *path, char *buf, size_t bufsiz)
70{ errno = ENOSYS; return -1; }
71static inline int symlink(const char *oldpath, const char *newpath)
72{ errno = ENOSYS; return -1; }
73static inline int link(const char *oldpath, const char *newpath)
74{ errno = ENOSYS; return -1; }
75static inline int fchmod(int fildes, mode_t mode)
76{ errno = ENOSYS; return -1; }
77static inline int fork(void)
78{ errno = ENOSYS; return -1; }
79static inline unsigned int alarm(unsigned int seconds)
80{ return 0; }
81static inline int fsync(int fd)
82{ return 0; }
83static inline int getppid(void)
84{ return 1; }
85static inline void sync(void)
86{}
87static inline int getuid()
88{ return 1; }
89static inline struct passwd *getpwnam(const char *name)
90{ return NULL; }
91static inline int fcntl(int fd, int cmd, long arg)
92{
93 if (cmd == F_GETFD || cmd == F_SETFD)
94 return 0;
95 errno = EINVAL;
96 return -1;
97}
98
99/*
100 * simple adaptors
101 */
102
103static inline int mingw_mkdir(const char *path, int mode)
104{
105 return mkdir(path);
106}
107#define mkdir mingw_mkdir
108
132a6e90
JS
109static inline int mingw_unlink(const char *pathname)
110{
111 /* read-only files cannot be removed */
112 chmod(pathname, 0666);
113 return unlink(pathname);
114}
115#define unlink mingw_unlink
116
f4626df5
JS
117static inline int waitpid(pid_t pid, unsigned *status, unsigned options)
118{
119 if (options == 0)
120 return _cwait(status, pid, 0);
121 errno = EINVAL;
122 return -1;
123}
124
f4626df5
JS
125/*
126 * implementations of missing functions
127 */
128
897bb8cb 129int pipe(int filedes[2]);
f4626df5
JS
130unsigned int sleep (unsigned int seconds);
131int mkstemp(char *template);
132int gettimeofday(struct timeval *tv, void *tz);
133int poll(struct pollfd *ufds, unsigned int nfds, int timeout);
134struct tm *gmtime_r(const time_t *timep, struct tm *result);
135struct tm *localtime_r(const time_t *timep, struct tm *result);
136int getpagesize(void); /* defined in MinGW's libgcc.a */
137struct passwd *getpwuid(int uid);
138int setitimer(int type, struct itimerval *in, struct itimerval *out);
139int sigaction(int sig, struct sigaction *in, struct sigaction *out);
80ba074f 140
25fe217b
JS
141/*
142 * replacements of existing functions
143 */
144
3e4a1ba0
JS
145int mingw_open (const char *filename, int oflags, ...);
146#define open mingw_open
147
25fe217b
JS
148char *mingw_getcwd(char *pointer, int len);
149#define getcwd mingw_getcwd
150
ea9e98c3
JS
151int mingw_rename(const char*, const char*);
152#define rename mingw_rename
153
f1a4dfb8
JS
154void mingw_execvp(const char *cmd, char *const *argv);
155#define execvp mingw_execvp
156
6072fc31
JS
157sig_handler_t mingw_signal(int sig, sig_handler_t handler);
158#define signal mingw_signal
159
80ba074f
JS
160/*
161 * git specific compatibility
162 */
163
25fe217b
JS
164#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
165#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
80ba074f 166#define PATH_SEP ';'
82f8d969 167#define PRIuMAX "I64u"
ba26f296
JS
168
169/*
170 * helpers
171 */
172
173char **copy_environ(void);
174void free_environ(char **env);
175char **env_setenv(char **env, const char *name);