1 | /* $Id: mscfakes.h 2766 2015-01-30 03:32:38Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * Unix fakes for MSC.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2005-2010 knut st. osmundsen <[email protected]>
|
---|
8 | *
|
---|
9 | * This file is part of kBuild.
|
---|
10 | *
|
---|
11 | * kBuild is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 3 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kBuild is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
---|
23 | *
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___mscfakes_h
|
---|
27 | #define ___mscfakes_h
|
---|
28 | #ifdef _MSC_VER
|
---|
29 |
|
---|
30 | /* Include the config file (kmk's) so we don't need to duplicate stuff from it here. */
|
---|
31 | #include "config.h"
|
---|
32 |
|
---|
33 | #include <io.h>
|
---|
34 | #include <direct.h>
|
---|
35 | #include <time.h>
|
---|
36 | #include <stdarg.h>
|
---|
37 | #include <malloc.h>
|
---|
38 | #include "getopt.h"
|
---|
39 | #ifndef MSCFAKES_NO_WINDOWS_H
|
---|
40 | # include <Windows.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <sys/stat.h>
|
---|
44 | #include <io.h>
|
---|
45 | #include <direct.h>
|
---|
46 | #include "nt/ntstat.h"
|
---|
47 | #include "nt/ntunlink.h"
|
---|
48 | #if defined(MSC_DO_64_BIT_IO) && _MSC_VER >= 1400 /* We want 64-bit file lengths here when possible. */
|
---|
49 | # define off_t __int64
|
---|
50 | # define lseek _lseeki64
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | #undef PATH_MAX
|
---|
54 | #define PATH_MAX _MAX_PATH
|
---|
55 | #undef MAXPATHLEN
|
---|
56 | #define MAXPATHLEN _MAX_PATH
|
---|
57 |
|
---|
58 | #define EX_OK 0
|
---|
59 | #define EX_OSERR 1
|
---|
60 | #define EX_NOUSER 1
|
---|
61 | #define EX_USAGE 1
|
---|
62 |
|
---|
63 | #define STDIN_FILENO 0
|
---|
64 | #define STDOUT_FILENO 1
|
---|
65 | #define STDERR_FILENO 2
|
---|
66 |
|
---|
67 | #define F_OK 0
|
---|
68 | #define X_OK 1
|
---|
69 | #define W_OK 2
|
---|
70 | #define R_OK 4
|
---|
71 |
|
---|
72 | #define EFTYPE EINVAL
|
---|
73 |
|
---|
74 | #define _PATH_DEVNULL "/dev/null"
|
---|
75 |
|
---|
76 | #ifndef MAX
|
---|
77 | # define MAX(a,b) ((a) >= (b) ? (a) : (b))
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | typedef int mode_t;
|
---|
81 | typedef unsigned short nlink_t;
|
---|
82 | #if 0 /* found in config.h */
|
---|
83 | typedef unsigned short uid_t;
|
---|
84 | typedef unsigned short gid_t;
|
---|
85 | #endif
|
---|
86 | #if defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || defined(_WIN64)
|
---|
87 | typedef __int64 ssize_t;
|
---|
88 | #else
|
---|
89 | typedef long ssize_t;
|
---|
90 | #endif
|
---|
91 | typedef unsigned long u_long;
|
---|
92 | typedef unsigned int u_int;
|
---|
93 | typedef unsigned short u_short;
|
---|
94 |
|
---|
95 | #if _MSC_VER >= 1600
|
---|
96 | # include <stdint.h>
|
---|
97 | #else
|
---|
98 | typedef unsigned char uint8_t;
|
---|
99 | typedef unsigned short uint16_t;
|
---|
100 | typedef unsigned int uint32_t;
|
---|
101 | typedef signed char int8_t;
|
---|
102 | typedef signed short int16_t;
|
---|
103 | typedef signed int int32_t;
|
---|
104 | #endif
|
---|
105 |
|
---|
106 | #if !defined(timerisset) && defined(MSCFAKES_NO_WINDOWS_H)
|
---|
107 | struct timeval
|
---|
108 | {
|
---|
109 | long tv_sec;
|
---|
110 | long tv_usec;
|
---|
111 | };
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | struct iovec
|
---|
115 | {
|
---|
116 | char *iov_base;
|
---|
117 | size_t iov_len;
|
---|
118 | };
|
---|
119 |
|
---|
120 | typedef __int64 intmax_t;
|
---|
121 | #if 0 /* found in config.h */
|
---|
122 | typedef unsigned __int64 uintmax_t;
|
---|
123 | #endif
|
---|
124 |
|
---|
125 | #define chown(path, uid, gid) 0 /** @todo implement fchmod! */
|
---|
126 | char *dirname(char *path);
|
---|
127 | #define fsync(fd) 0
|
---|
128 | #define fchown(fd,uid,gid) 0
|
---|
129 | #define fchmod(fd, mode) 0 /** @todo implement fchmod! */
|
---|
130 | #define geteuid() 0
|
---|
131 | #define getegid() 0
|
---|
132 | int lchmod(const char *path, mode_t mode);
|
---|
133 | int msc_chmod(const char *path, mode_t mode);
|
---|
134 | #define chmod msc_chmod
|
---|
135 | #define lchown(path, uid, gid) chown(path, uid, gid)
|
---|
136 | #define lutimes(path, tvs) utimes(path, tvs)
|
---|
137 | int link(const char *pszDst, const char *pszLink);
|
---|
138 | int mkdir_msc(const char *path, mode_t mode);
|
---|
139 | #define mkdir(path, mode) mkdir_msc(path, mode)
|
---|
140 | #define mkfifo(path, mode) -1
|
---|
141 | #define mknod(path, mode, devno) -1
|
---|
142 | int mkstemp(char *temp);
|
---|
143 | #define readlink(link, buf, size) -1
|
---|
144 | #define reallocf(old, size) realloc(old, size)
|
---|
145 | int rmdir_msc(const char *path);
|
---|
146 | #define rmdir(path) rmdir_msc(path)
|
---|
147 | intmax_t strtoimax(const char *nptr, char **endptr, int base);
|
---|
148 | uintmax_t strtoumax(const char *nptr, char **endptr, int base);
|
---|
149 | #define strtoll(a,b,c) strtoimax(a,b,c)
|
---|
150 | #define strtoull(a,b,c) strtoumax(a,b,c)
|
---|
151 | int asprintf(char **strp, const char *fmt, ...);
|
---|
152 | int vasprintf(char **strp, const char *fmt, va_list ap);
|
---|
153 | #if _MSC_VER < 1400
|
---|
154 | int snprintf(char *buf, size_t size, const char *fmt, ...);
|
---|
155 | #else
|
---|
156 | #define snprintf _snprintf
|
---|
157 | #endif
|
---|
158 | int symlink(const char *pszDst, const char *pszLink);
|
---|
159 | int utimes(const char *pszPath, const struct timeval *paTimes);
|
---|
160 | ssize_t writev(int fd, const struct iovec *vector, int count);
|
---|
161 |
|
---|
162 | /* bird write ENOSPC hacks. */
|
---|
163 | #undef write
|
---|
164 | #define write msc_write
|
---|
165 | ssize_t msc_write(int fd, const void *pvSrc, size_t cbSrc);
|
---|
166 |
|
---|
167 | /*
|
---|
168 | * MSC fake internals / helpers.
|
---|
169 | */
|
---|
170 | int birdSetErrno(unsigned dwErr);
|
---|
171 |
|
---|
172 | #endif /* _MSC_VER */
|
---|
173 | #endif
|
---|
174 |
|
---|