VirtualBox

source: kBuild/trunk/src/ash/win/mscfakes.c@ 1185

Last change on this file since 1185 was 785, checked in by bird, 18 years ago

copyright and email updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: mscfakes.c 785 2007-01-24 22:21:56Z bird $ */
2/** @file
3 *
4 * Fake Unix stuff for MSC.
5 *
6 * Copyright (c) 2005-2007 knut st. osmundsen <[email protected]>
7 *
8 *
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.
13 *
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.
18 *
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
22 *
23 */
24
25
26#include <stdarg.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <errno.h>
31#include <io.h>
32#include <fcntl.h>
33#include <sys/times.h>
34#include "err.h"
35#include "mscfakes.h"
36#undef mkdir
37
38
39int optind = 1;
40
41
42char *dirname(char *path)
43{
44 /** @todo later */
45 return path;
46}
47
48
49int link(const char *pszDst, const char *pszLink)
50{
51 errno = ENOSYS;
52 err(1, "link() is not implemented on windows!");
53 return -1;
54}
55
56
57int mkdir_msc(const char *path, mode_t mode)
58{
59 int rc = mkdir(path);
60 if (rc)
61 {
62 int len = strlen(path);
63 if (len > 0 && (path[len - 1] == '/' || path[len - 1] == '\\'))
64 {
65 char *str = strdup(path);
66 while (len > 0 && (str[len - 1] == '/' || str[len - 1] == '\\'))
67 str[--len] = '\0';
68 rc = mkdir(str);
69 free(str);
70 }
71 }
72 return rc;
73}
74
75
76static int doname(char *pszX, char *pszEnd)
77{
78 static char s_szChars[] = "Xabcdefghijklmnopqrstuwvxyz1234567890";
79 int rc = 0;
80 do
81 {
82 char ch;
83
84 pszEnd++;
85 ch = *(strchr(s_szChars, *pszEnd) + 1);
86 if (ch)
87 {
88 *pszEnd = ch;
89 return 0;
90 }
91 *pszEnd = 'a';
92 } while (pszEnd != pszX);
93 return 1;
94}
95
96
97int mkstemp(char *temp)
98{
99 char *pszX = strchr(temp, 'X');
100 char *pszEnd = strchr(pszX, '\0');
101 int cTries = 1000;
102 while (--cTries > 0)
103 {
104 int fd;
105 if (doname(pszX, pszEnd))
106 return -1;
107 fd = open(temp, _O_EXCL | _O_CREAT | _O_BINARY | _O_RDWR, 0777);
108 if (fd >= 0)
109 return fd;
110 }
111 return -1;
112}
113
114
115int symlink(const char *pszDst, const char *pszLink)
116{
117 errno = ENOSYS;
118 err(1, "symlink() is not implemented on windows!");
119 return -1;
120}
121
122
123#if _MSC_VER < 1400
124int snprintf(char *buf, size_t size, const char *fmt, ...)
125{
126 int cch;
127 va_list args;
128 va_start(args, fmt);
129 cch = vsprintf(buf, fmt, args);
130 va_end(args);
131 return cch;
132}
133#endif
134
135
136int utimes(const char *pszPath, const struct timeval *paTimes)
137{
138 /** @todo implement me! */
139 return 0;
140}
141
142
143int writev(int fd, const struct iovec *vector, int count)
144{
145 int size = 0;
146 int i;
147 for (i = 0; i < count; i++)
148 {
149 int cb = write(fd, vector[i].iov_base, vector[i].iov_len);
150 if (cb < 0)
151 return -1;
152 size += cb;
153 }
154 return size;
155}
156
157
158int fcntl(int fd, int iCmd, ...)
159{
160 fprintf(stderr, "fcntl(%d, %d,..)\n", fd, iCmd);
161 return 0;
162}
163
164int ioctl(int fd, unsigned long iCmd, ...)
165{
166 fprintf(stderr, "ioctl(%d, %d,..)\n", fd, iCmd);
167 return 0;
168}
169
170int tcsetpgrp(int fd, pid_t pgrp)
171{
172 fprintf(stderr, "tcgetpgrp(%d, %d)\n", fd, pgrp);
173 return 0;
174}
175
176pid_t tcgetpgrp(int fd)
177{
178 fprintf(stderr, "tcgetpgrp(%d)\n", fd);
179 return 0;
180}
181
182pid_t getpgrp(void)
183{
184 fprintf(stderr, "getpgrp\n");
185 return _getpid();
186}
187
188uid_t getuid(void)
189{
190 fprintf(stderr, "getuid\n");
191 return 0;
192}
193
194gid_t getgid(void)
195{
196 fprintf(stderr, "getgid\n");
197 return 0;
198}
199
200gid_t getegid(void)
201{
202 fprintf(stderr, "getegid\n");
203 return 0;
204}
205
206int setpgid(pid_t pid, pid_t pgid)
207{
208 fprintf(stderr, "setpgid(%d,%d)\n", pid, pgid);
209 return 0;
210}
211
212pid_t getpgid(pid_t pid)
213{
214 fprintf(stderr, "getpgid(%d)\n", pid);
215 return 0;
216}
217
218long sysconf(int name)
219{
220 fprintf(stderr, "sysconf(%d)\n", name);
221 return 0;
222}
223
224clock_t times(struct tms *pBuf)
225{
226 struct timeval tv = {0};
227 if (pBuf)
228 {
229 pBuf->tms_utime = clock(); /* clock () * HZ / CLOCKS_PER_SEC */
230 pBuf->tms_stime = pBuf->tms_cutime = pBuf->tms_cstime = 0;
231 }
232/*
233 gettimeofday(&tv, NULL); */
234 fprintf(stderr, "times(%p)\n", pBuf);
235 return CLK_TCK * tv.tv_sec + (CLK_TCK * tv.tv_usec) / 1000000;
236}
237
238struct passwd *getpwnam(const char *pszName)
239{
240 printf("getpwnam(%s)\n", pszName);
241 return NULL;
242}
243
244int setrlimit(int iResId, const struct rlimit *pLimit)
245{
246 printf("setrlimit(%d, %p)\n", iResId, pLimit);
247 return -1;
248}
249
250int getrlimit(int iResId, struct rlimit *pLimit)
251{
252 printf("getrlimit(%d, %p)\n", iResId, pLimit);
253 return -1;
254}
255
256
257pid_t fork(void)
258{
259 fprintf(stderr, "fork()\n");
260 return -1;
261}
262
263pid_t wait3(int *piStatus, int fOptions, struct rusage *pRUsage)
264{
265 fprintf(stderr, "wait3()\n");
266 return -1;
267}
268
269
270/* signal stuff */
271
272int sigprocmask(int iOperation, const sigset_t *pNew, sigset_t *pOld)
273{
274 fprintf(stderr, "sigprocmask(%d, %p, %p)\n", iOperation, pNew, pOld);
275 return 0;
276}
277
278int sigemptyset(sigset_t *pSet)
279{
280 pSet->__bitmap[0] = 0;
281 return 0;
282}
283
284int siginterrupt(int iSignalNo, int fFlag)
285{
286 fprintf(stderr, "siginterrupt(%d, %#x)\n", iSignalNo, fFlag);
287 return 0;
288}
289
290int sigaction(int iSignalNo, const struct sigaction *pSigAct, struct sigaction *pSigActOld)
291{
292 fprintf(stderr, "sigaction(%d, %p, %p)\n", iSignalNo, pSigAct, pSigActOld);
293 return 0;
294}
295
296int kill(pid_t pid, int iSignalNo)
297{
298 fprintf(stderr, "kill(%d, %d)\n", pid, iSignalNo);
299 return 0;
300}
301
302int killpg(pid_t pgrp, int iSignalNo)
303{
304 if (pgrp < 0)
305 {
306 errno = EINVAL;
307 return -1;
308 }
309 return kill(-pgrp, iSignalNo);
310}
311
312const char * const sys_siglist[NSIG] =
313{
314 "0",
315 "1",
316 "2",
317 "3",
318 "4",
319 "5",
320 "6",
321 "7",
322 "8",
323 "9",
324 "10",
325 "11",
326 "12",
327 "13",
328 "14",
329 "15",
330 "16",
331 "17",
332 "18",
333 "19",
334 "20",
335 "21",
336 "22"
337};
338
339
340/* */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette