*: Updated copyright to 2009 and normalized name & email.
[kbuild-mirror.git] / src / ash / win / mscfakes.h
blobb0c2f602c92b3e358f84e17f56b99507018dc8d3
1 /* $Id$ */
2 /** @file
4 * Unix fakes for MSC.
6 * Copyright (c) 2005-2009 knut st. osmundsen <bird-kBuild-spamix@anduin.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with This program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef __mscfakes_h__
26 #define __mscfakes_h__
27 #ifdef _MSC_VER
29 #define setmode setmode_msc
30 #include <sys/cdefs.h>
31 #include <io.h>
32 #include <direct.h>
33 #include <time.h>
34 #include <fcntl.h>
35 #include <limits.h>
36 #include <stdlib.h>
37 #include <process.h>
38 #undef setmode
39 //#include "getopt.h"
41 #if !defined(__GNUC__) && !defined(__attribute__)
42 #define __attribute__(a)
43 #endif
45 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
46 #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
47 #define S_ISLNK(m) 0
48 #define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
49 #define S_IXUSR _S_IEXEC
50 #define S_IWUSR _S_IWRITE
51 #define S_IRUSR _S_IREAD
52 #define S_IRWXG 0000070
53 #define S_IRGRP 0000040
54 #define S_IWGRP 0000020
55 #define S_IXGRP 0000010
56 #define S_IRWXO 0000007
57 #define S_IROTH 0000004
58 #define S_IWOTH 0000002
59 #define S_IXOTH 0000001
60 #define S_ISUID 0004000
61 #define S_ISGID 0002000
62 #define ALLPERMS 0000777
64 #define PATH_MAX _MAX_PATH
65 #define MAXPATHLEN _MAX_PATH
67 #define EX_OK 0
68 #define EX_OSERR 1
69 #define EX_NOUSER 1
70 #define EX_USAGE 1
72 #define STDIN_FILENO 0
73 #define STDOUT_FILENO 1
74 #define STDERR_FILENO 2
76 #define F_OK 0
77 #define X_OK 1
78 #define W_OK 2
79 #define R_OK 4
81 #define EFTYPE EINVAL
83 #define _PATH_DEVNULL "/dev/null"
85 #define MAX(a,b) ((a) >= (b) ? (a) : (b))
87 typedef int mode_t;
88 typedef unsigned short nlink_t;
89 typedef long ssize_t;
90 typedef unsigned long u_long;
91 typedef unsigned int u_int;
92 typedef unsigned short u_short;
94 #ifndef timerisset
95 struct timeval
97 long tv_sec;
98 long tv_usec;
100 #endif
102 struct iovec
104 char *iov_base;
105 size_t iov_len;
109 #define chown(path, uid, gid) 0 /** @todo implement fchmod! */
110 char *dirname(char *path);
111 #define fsync(fd) 0
112 #define fchown(fd,uid,gid) 0
113 #define fchmod(fd, mode) 0 /** @todo implement fchmod! */
114 #define geteuid() 0
115 #define lstat(path, s) stat(path, s)
116 #define lchmod(path, mod) chmod(path, mod)
117 #define lchown(path, uid, gid) chown(path, uid, gid)
118 #define lutimes(path, tvs) utimes(path, tvs)
119 int link(const char *pszDst, const char *pszLink);
120 int mkdir_msc(const char *path, mode_t mode);
121 #define mkdir(path, mode) mkdir_msc(path, mode)
122 #define mkfifo(path, mode) -1
123 #define mknod(path, mode, devno) -1
124 #define pipe(v) _pipe(v,0,0)
125 int mkstemp(char *temp);
126 #define readlink(link, buf, size) -1
127 #define reallocf(old, size) realloc(old, size)
128 #define strcasecmp stricmp
129 #define strncasecmp strnicmp
130 #if _MSC_VER < 1400
131 int snprintf(char *buf, size_t size, const char *fmt, ...);
132 #else
133 #define snprintf _snprintf
134 #endif
135 size_t strlcpy(char *, const char *, size_t);
136 int symlink(const char *pszDst, const char *pszLink);
137 int utimes(const char *pszPath, const struct timeval *paTimes);
138 int writev(int fd, const struct iovec *vector, int count);
139 #define F_DUPFD 0
140 #define F_GETFD 1
141 #define F_SETFD 2
142 #define F_GETFL 3
143 #define F_SETFL 4
144 #define FD_CLOEXEC 1
145 #define O_NONBLOCK 0 /// @todo
146 #define EWOULDBLOCK 512
147 int fcntl(int, int, ...);
148 int ioctl(int, unsigned long, ...);
149 pid_t tcgetpgrp(int fd);
152 /* signal hacks */
153 #include <signal.h>
154 typedef struct sigset
156 unsigned long __bitmap[1];
157 } sigset_t;
158 typedef void __sighandler_t(int);
159 typedef void __siginfohandler_t(int, struct __siginfo *, void *);
160 typedef __sighandler_t *sig_t; /** BSD 4.4 type. */
161 struct sigaction
163 union
165 __siginfohandler_t *__sa_sigaction;
166 __sighandler_t *__sa_handler;
167 } __sigaction_u;
168 sigset_t sa_mask;
169 int sa_flags;
171 #define sa_handler __sigaction_u.__sa_handler
172 #define sa_sigaction __sigaction_u.__sa_sigaction
174 int sigprocmask(int, const sigset_t *, sigset_t *);
175 #define SIG_BLOCK 1
176 #define SIG_UNBLOCK 2
177 #define SIG_SETMASK 3
179 #define SIGTTIN 19
180 #define SIGTSTP 18
181 #define SIGTTOU 17
182 #define SIGCONT 20
183 #define SIGPIPE 12
184 #define SIGQUIT 9
185 #define SIGHUP 5
187 extern const char *const sys_siglist[NSIG]; /* NSIG == 23 */
189 int kill(pid_t, int);
190 int sigaction(int, const struct sigaction *, struct sigaction *);
191 //int sigaddset(sigset_t *, int);
192 //int sigdelset(sigset_t *, int);
193 int sigemptyset(sigset_t *);
194 //int sigfillset(sigset_t *);
195 //int sigismember(const sigset_t *, int);
196 //int sigpending(sigset_t *);
197 //int sigsuspend(const sigset_t *);
198 //int sigwait(const sigset_t *, int *);
199 int siginterrupt(int, int);
201 #endif /* _MSC_VER */
202 #endif