diff options
| author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-14 07:04:40 +0200 |
|---|---|---|
| committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-10 18:38:19 +1000 |
| commit | d029ae797bff2ecb95c39b80f6a4eb4419e2e827 (patch) | |
| tree | a650d520836ecc9bbeab3281502aa5aa801430e5 /include | |
| parent | 6a89ed1763400f4ad0ba5807d52f8604acc50758 (diff) | |
| download | busybox-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.
Diffstat (limited to 'include')
| -rw-r--r-- | include/mingw.h | 295 |
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 | */ | ||
| 9 | typedef int gid_t; | ||
| 10 | typedef int uid_t; | ||
| 11 | typedef int pid_t; | ||
| 12 | |||
| 13 | /* | ||
| 14 | * arpa/inet.h | ||
| 15 | */ | ||
| 16 | static 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 | |||
| 34 | struct group { | ||
| 35 | char *gr_name; | ||
| 36 | char *gr_passwd; | ||
| 37 | gid_t gr_gid; | ||
| 38 | char **gr_mem; | ||
| 39 | }; | ||
| 40 | IMPL(getgrnam,struct group *,NULL,const char *name UNUSED_PARAM); | ||
| 41 | IMPL(getgrgid,struct group *,NULL,gid_t gid UNUSED_PARAM); | ||
| 42 | NOIMPL(initgroups,const char *group UNUSED_PARAM,gid_t gid UNUSED_PARAM); | ||
| 43 | static 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 | */ | ||
| 55 | struct pollfd { | ||
| 56 | int fd; /* file descriptor */ | ||
| 57 | short events; /* requested events */ | ||
| 58 | short revents; /* returned events */ | ||
| 59 | }; | ||
| 60 | typedef unsigned long nfds_t; | ||
| 61 | #define POLLIN 1 | ||
| 62 | #define POLLHUP 2 | ||
| 63 | |||
| 64 | NOIMPL(poll,struct pollfd *ufds UNUSED_PARAM, unsigned int nfds UNUSED_PARAM, int timeout UNUSED_PARAM); | ||
| 65 | |||
| 66 | /* | ||
| 67 | * pwd.h | ||
| 68 | */ | ||
| 69 | struct 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 | |||
| 77 | IMPL(getpwnam,struct passwd *,NULL,const char *name UNUSED_PARAM); | ||
| 78 | IMPL(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 | |||
| 103 | typedef void (__cdecl *sighandler_t)(int); | ||
| 104 | struct 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 | |||
| 112 | NOIMPL(sigaction,int sig UNUSED_PARAM, struct sigaction *in UNUSED_PARAM, struct sigaction *out UNUSED_PARAM); | ||
| 113 | NOIMPL(sigfillset,int *mask UNUSED_PARAM); | ||
| 114 | |||
| 115 | /* | ||
| 116 | * stdio.h | ||
| 117 | */ | ||
| 118 | #define fseeko(f,o,w) fseek(f,o,w) | ||
| 119 | |||
| 120 | int 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 | |||
| 130 | NOIMPL(clearenv,void); | ||
| 131 | IMPL(mingw_getenv,char*,NULL,const char *name UNUSED_PARAM); | ||
| 132 | NOIMPL(mkstemp,char *template UNUSED_PARAM); | ||
| 133 | IMPL(realpath,char *,NULL,const char *path UNUSED_PARAM, char *resolved_path UNUSED_PARAM); | ||
| 134 | NOIMPL(setenv,const char *name UNUSED_PARAM, const char *value UNUSED_PARAM, int replace UNUSED_PARAM); | ||
| 135 | IMPL(unsetenv,void,,const char *env UNUSED_PARAM); | ||
| 136 | |||
| 137 | #define getenv mingw_getenv | ||
| 138 | /* | ||
| 139 | * string.h | ||
| 140 | */ | ||
| 141 | IMPL(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 | |||
| 149 | NOIMPL(ioctl,int fd UNUSED_PARAM, int code UNUSED_PARAM,...); | ||
| 150 | |||
| 151 | /* | ||
| 152 | * sys/socket.h | ||
| 153 | */ | ||
| 154 | #define hstrerror strerror | ||
| 155 | |||
| 156 | NOIMPL(mingw_socket,int domain UNUSED_PARAM, int type UNUSED_PARAM, int protocol UNUSED_PARAM); | ||
| 157 | NOIMPL(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); | ||
| 158 | NOIMPL(mingw_listen,SOCKET s UNUSED_PARAM,int backlog UNUSED_PARAM); | ||
| 159 | NOIMPL(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 | |||
| 191 | NOIMPL(fchmod,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM); | ||
| 192 | NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); | ||
| 193 | NOIMPL(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 | */ | ||
| 208 | struct itimerval { | ||
| 209 | struct timeval it_value, it_interval; | ||
| 210 | }; | ||
| 211 | #define ITIMER_REAL 0 | ||
| 212 | |||
| 213 | int setitimer(int type, struct itimerval *in, struct itimerval *out); | ||
| 214 | |||
| 215 | /* | ||
| 216 | * sys/wait.h | ||
| 217 | */ | ||
| 218 | #define WNOHANG 1 | ||
| 219 | NOIMPL(waitpid,pid_t pid UNUSED_PARAM, int *status UNUSED_PARAM, unsigned options UNUSED_PARAM); | ||
| 220 | |||
| 221 | /* | ||
| 222 | * time.h | ||
| 223 | */ | ||
| 224 | IMPL(gmtime_r,struct tm *,NULL,const time_t *timep UNUSED_PARAM, struct tm *result UNUSED_PARAM); | ||
| 225 | IMPL(localtime_r,struct tm *,NULL,const time_t *timep UNUSED_PARAM, struct tm *result UNUSED_PARAM); | ||
| 226 | IMPL(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 | |||
| 233 | IMPL(alarm,unsigned int,0,unsigned int seconds UNUSED_PARAM); | ||
| 234 | NOIMPL(chown,const char *path UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); | ||
| 235 | NOIMPL(chroot,const char *root UNUSED_PARAM); | ||
| 236 | char *mingw_getcwd(char *pointer, int len); | ||
| 237 | |||
| 238 | |||
| 239 | #ifdef USE_WIN32_MMAP | ||
| 240 | int mingw_getpagesize(void); | ||
| 241 | #define getpagesize mingw_getpagesize | ||
| 242 | #else | ||
| 243 | int getpagesize(void); /* defined in MinGW's libgcc.a */ | ||
| 244 | #endif | ||
| 245 | |||
| 246 | IMPL(getgid,int,1,void); | ||
| 247 | NOIMPL(getgroups,int n UNUSED_PARAM,gid_t *groups UNUSED_PARAM); | ||
| 248 | IMPL(getppid,int,1,void); | ||
| 249 | IMPL(getegid,int,1,void); | ||
| 250 | IMPL(geteuid,int,1,void); | ||
| 251 | NOIMPL(getsid,pid_t pid UNUSED_PARAM); | ||
| 252 | IMPL(getuid,int,1,void); | ||
| 253 | NOIMPL(fcntl,int fd UNUSED_PARAM, int cmd UNUSED_PARAM, ...); | ||
| 254 | #define fork() -1 | ||
| 255 | IMPL(fsync,int,0,int fd UNUSED_PARAM); | ||
| 256 | NOIMPL(kill,pid_t pid UNUSED_PARAM, int sig UNUSED_PARAM); | ||
| 257 | NOIMPL(link,const char *oldpath UNUSED_PARAM, const char *newpath UNUSED_PARAM); | ||
| 258 | NOIMPL(mknod,const char *name UNUSED_PARAM, mode_t mode UNUSED_PARAM, dev_t device UNUSED_PARAM); | ||
| 259 | NOIMPL(pipe,int filedes[2] UNUSED_PARAM); | ||
| 260 | NOIMPL(readlink,const char *path UNUSED_PARAM, char *buf UNUSED_PARAM, size_t bufsiz UNUSED_PARAM); | ||
| 261 | NOIMPL(setgid,gid_t gid UNUSED_PARAM); | ||
| 262 | NOIMPL(setsid,void); | ||
| 263 | NOIMPL(setuid,uid_t gid UNUSED_PARAM); | ||
| 264 | NOIMPL(sleep,unsigned int seconds UNUSED_PARAM); | ||
| 265 | NOIMPL(symlink,const char *oldpath UNUSED_PARAM, const char *newpath UNUSED_PARAM); | ||
| 266 | static inline void sync(void) {} | ||
| 267 | NOIMPL(vfork,void); | ||
| 268 | |||
| 269 | #define getcwd mingw_getcwd | ||
| 270 | #define lchown(a,b,c) chown(a,b,c) | ||
| 271 | |||
| 272 | /* | ||
| 273 | * utime.h | ||
| 274 | */ | ||
| 275 | int mingw_utime(const char *file_name, const struct utimbuf *times); | ||
| 276 | NOIMPL(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 | |||
| 291 | char **copy_environ(const char *const *env); | ||
| 292 | void free_environ(char **env); | ||
| 293 | char **env_setenv(char **env, const char *name); | ||
| 294 | |||
| 295 | const char *get_busybox_exec_path(void); | ||
