aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-04-14 07:04:40 +0200
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-10 18:38:19 +1000
commitd029ae797bff2ecb95c39b80f6a4eb4419e2e827 (patch)
treea650d520836ecc9bbeab3281502aa5aa801430e5
parent6a89ed1763400f4ad0ba5807d52f8604acc50758 (diff)
downloadbusybox-w32-d029ae797bff2ecb95c39b80f6a4eb4419e2e827.tar.gz
busybox-w32-d029ae797bff2ecb95c39b80f6a4eb4419e2e827.tar.bz2
busybox-w32-d029ae797bff2ecb95c39b80f6a4eb4419e2e827.zip
win32: add mingw.h
This file is like libbb.h for MinGW port.
-rw-r--r--include/mingw.h295
1 files changed, 295 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h
new file mode 100644
index 000000000..44ea2b098
--- /dev/null
+++ b/include/mingw.h
@@ -0,0 +1,295 @@
1#include <sys/utime.h>
2
3#define NOIMPL(name,...) static inline int name(__VA_ARGS__) { errno = ENOSYS; return -1; }
4#define IMPL(name,ret,retval,...) static inline ret name(__VA_ARGS__) { return retval; }
5
6/*
7 * sys/types.h
8 */
9typedef int gid_t;
10typedef int uid_t;
11typedef int pid_t;
12
13/*
14 * arpa/inet.h
15 */
16static inline unsigned int git_ntohl(unsigned int x) { return (unsigned int)ntohl(x); }
17#define ntohl git_ntohl
18
19/*
20 * fcntl.h
21 */
22#define F_DUPFD 0
23#define F_GETFD 1
24#define F_SETFD 2
25#define F_GETFL 3
26#define F_SETFL 3
27#define FD_CLOEXEC 0x1
28#define O_NONBLOCK 04000
29
30/*
31 * grp.h
32 */
33
34struct group {
35 char *gr_name;
36 char *gr_passwd;
37 gid_t gr_gid;
38 char **gr_mem;
39};
40IMPL(getgrnam,struct group *,NULL,const char *name UNUSED_PARAM);
41IMPL(getgrgid,struct group *,NULL,gid_t gid UNUSED_PARAM);
42NOIMPL(initgroups,const char *group UNUSED_PARAM,gid_t gid UNUSED_PARAM);
43static inline void endgrent(void) {}
44
45/*
46 * limits.h
47 */
48#define NAME_MAX 255
49#define MAXSYMLINKS 20
50
51
52/*
53 * poll.h
54 */
55struct pollfd {
56 int fd; /* file descriptor */
57 short events; /* requested events */
58 short revents; /* returned events */
59};
60typedef unsigned long nfds_t;
61#define POLLIN 1
62#define POLLHUP 2
63
64NOIMPL(poll,struct pollfd *ufds UNUSED_PARAM, unsigned int nfds UNUSED_PARAM, int timeout UNUSED_PARAM);
65
66/*
67 * pwd.h
68 */
69struct passwd {
70 char *pw_name;
71 char *pw_gecos;
72 char *pw_dir;
73 uid_t pw_uid;
74 gid_t pw_gid;
75};
76
77IMPL(getpwnam,struct passwd *,NULL,const char *name UNUSED_PARAM);
78IMPL(getpwuid,struct passwd *,NULL,int uid UNUSED_PARAM);
79
80/*
81 * signal.h
82 */
83#define SIGHUP 1
84#define SIGQUIT 3
85#define SIGKILL 9
86#define SIGUSR1 10
87#define SIGUSR2 12
88#define SIGPIPE 13
89#define SIGALRM 14
90#define SIGCHLD 17
91#define SIGCONT 18
92#define SIGSTOP 19
93#define SIGTSTP 20
94#define SIGTTIN 21
95#define SIGTTOU 22
96#define SIGXCPU 24
97#define SIGXFSZ 25
98#define SIGVTALRM 26
99#define SIGWINCH 28
100
101#define SIG_UNBLOCK 1
102
103typedef void (__cdecl *sighandler_t)(int);
104struct sigaction {
105 sighandler_t sa_handler;
106 unsigned sa_flags;
107 int sa_mask;
108};
109#define sigemptyset(x) (void)0
110#define SA_RESTART 0
111
112NOIMPL(sigaction,int sig UNUSED_PARAM, struct sigaction *in UNUSED_PARAM, struct sigaction *out UNUSED_PARAM);
113NOIMPL(sigfillset,int *mask UNUSED_PARAM);
114
115/*
116 * stdio.h
117 */
118#define fseeko(f,o,w) fseek(f,o,w)
119
120int fdprintf(int fd, const char *format, ...);
121
122/*
123 * stdlib.h
124 */
125#define WIFEXITED(x) ((unsigned)(x) < 259) /* STILL_ACTIVE */
126#define WEXITSTATUS(x) ((x) & 0xff)
127#define WIFSIGNALED(x) ((unsigned)(x) > 259)
128#define WTERMSIG(x) ((x) & 0x7f)
129
130NOIMPL(clearenv,void);
131IMPL(mingw_getenv,char*,NULL,const char *name UNUSED_PARAM);
132NOIMPL(mkstemp,char *template UNUSED_PARAM);
133IMPL(realpath,char *,NULL,const char *path UNUSED_PARAM, char *resolved_path UNUSED_PARAM);
134NOIMPL(setenv,const char *name UNUSED_PARAM, const char *value UNUSED_PARAM, int replace UNUSED_PARAM);
135IMPL(unsetenv,void,,const char *env UNUSED_PARAM);
136
137#define getenv mingw_getenv
138/*
139 * string.h
140 */
141IMPL(strsep,char *,NULL,char **stringp UNUSED_PARAM, const char *delim UNUSED_PARAM);
142
143/*
144 * sys/ioctl.h
145 */
146
147#define TIOCGWINSZ 0x5413
148
149NOIMPL(ioctl,int fd UNUSED_PARAM, int code UNUSED_PARAM,...);
150
151/*
152 * sys/socket.h
153 */
154#define hstrerror strerror
155
156NOIMPL(mingw_socket,int domain UNUSED_PARAM, int type UNUSED_PARAM, int protocol UNUSED_PARAM);
157NOIMPL(mingw_sendto,SOCKET s UNUSED_PARAM, const char *buf UNUSED_PARAM, int len UNUSED_PARAM, int flags UNUSED_PARAM, const struct sockaddr *sa UNUSED_PARAM, int salen UNUSED_PARAM);
158NOIMPL(mingw_listen,SOCKET s UNUSED_PARAM,int backlog UNUSED_PARAM);
159NOIMPL(mingw_bind,SOCKET s UNUSED_PARAM,const struct sockaddr* sa UNUSED_PARAM,int salen UNUSED_PARAM);
160
161/* Windows declaration is different */
162#define socket mingw_socket
163#define sendto mingw_sendto
164#define listen mingw_listen
165#define bind mingw_bind
166
167/*
168 * sys/stat.h
169 */
170#define S_ISUID 04000
171#define S_ISGID 02000
172#define S_ISVTX 01000
173#ifndef S_IRWXU
174#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
175#endif
176#define S_IRWXG (S_IRWXU >> 3)
177#define S_IRWXO (S_IRWXG >> 3)
178
179#define S_IFSOCK 0140000
180#define S_IFLNK 0120000 /* Symbolic link */
181#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
182#define S_ISSOCK(x) 0
183
184#define S_IRGRP (S_IRUSR >> 3)
185#define S_IWGRP (S_IWUSR >> 3)
186#define S_IXGRP (S_IXUSR >> 3)
187#define S_IROTH (S_IRGRP >> 3)
188#define S_IWOTH (S_IWGRP >> 3)
189#define S_IXOTH (S_IXGRP >> 3)
190
191NOIMPL(fchmod,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM);
192NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM);
193NOIMPL(mingw_mkdir,const char *path UNUSED_PARAM, int mode UNUSED_PARAM);
194
195#define mkdir mingw_mkdir
196#define lstat stat
197
198/*
199 * sys/sysmacros.h
200 */
201#define makedev(a,b) 0*(a)*(b) /* avoid unused warning */
202#define minor(x) 0
203#define major(x) 0
204
205/*
206 * sys/time.h
207 */
208struct itimerval {
209 struct timeval it_value, it_interval;
210};
211#define ITIMER_REAL 0
212
213int setitimer(int type, struct itimerval *in, struct itimerval *out);
214
215/*
216 * sys/wait.h
217 */
218#define WNOHANG 1
219NOIMPL(waitpid,pid_t pid UNUSED_PARAM, int *status UNUSED_PARAM, unsigned options UNUSED_PARAM);
220
221/*
222 * time.h
223 */
224IMPL(gmtime_r,struct tm *,NULL,const time_t *timep UNUSED_PARAM, struct tm *result UNUSED_PARAM);
225IMPL(localtime_r,struct tm *,NULL,const time_t *timep UNUSED_PARAM, struct tm *result UNUSED_PARAM);
226IMPL(strptime,char*,NULL,const char *s UNUSED_PARAM, const char *format UNUSED_PARAM, struct tm *tm UNUSED_PARAM);
227
228/*
229 * unistd.h
230 */
231#define PIPE_BUF 8192
232
233IMPL(alarm,unsigned int,0,unsigned int seconds UNUSED_PARAM);
234NOIMPL(chown,const char *path UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM);
235NOIMPL(chroot,const char *root UNUSED_PARAM);
236char *mingw_getcwd(char *pointer, int len);
237
238
239#ifdef USE_WIN32_MMAP
240int mingw_getpagesize(void);
241#define getpagesize mingw_getpagesize
242#else
243int getpagesize(void); /* defined in MinGW's libgcc.a */
244#endif
245
246IMPL(getgid,int,1,void);
247NOIMPL(getgroups,int n UNUSED_PARAM,gid_t *groups UNUSED_PARAM);
248IMPL(getppid,int,1,void);
249IMPL(getegid,int,1,void);
250IMPL(geteuid,int,1,void);
251NOIMPL(getsid,pid_t pid UNUSED_PARAM);
252IMPL(getuid,int,1,void);
253NOIMPL(fcntl,int fd UNUSED_PARAM, int cmd UNUSED_PARAM, ...);
254#define fork() -1
255IMPL(fsync,int,0,int fd UNUSED_PARAM);
256NOIMPL(kill,pid_t pid UNUSED_PARAM, int sig UNUSED_PARAM);
257NOIMPL(link,const char *oldpath UNUSED_PARAM, const char *newpath UNUSED_PARAM);
258NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM);
259NOIMPL(pipe,int filedes[2] UNUSED_PARAM);
260NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM);
261NOIMPL(setgid,gid_t gid UNUSED_PARAM);
262NOIMPL(setsid,void);
263NOIMPL(setuid,uid_t gid UNUSED_PARAM);
264NOIMPL(sleep,unsigned int seconds UNUSED_PARAM);
265NOIMPL(symlink,const char *oldpath UNUSED_PARAM, const char *newpath UNUSED_PARAM);
266static inline void sync(void) {}
267NOIMPL(vfork,void);
268
269#define getcwd mingw_getcwd
270#define lchown(a,b,c) chown(a,b,c)
271
272/*
273 * utime.h
274 */
275int mingw_utime(const char *file_name, const struct utimbuf *times);
276NOIMPL(utimes,const char *filename UNUSED_PARAM, const struct timeval times[2] UNUSED_PARAM);
277
278#define utime mingw_utime
279
280/*
281 * MinGW specific
282 */
283#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
284#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
285#define PRIuMAX "I64u"
286
287/*
288 * helpers
289 */
290
291char **copy_environ(const char *const *env);
292void free_environ(char **env);
293char **env_setenv(char **env, const char *name);
294
295const char *get_busybox_exec_path(void);