source: trunk/src/kmk/kmkbuiltin/mscfakes.h@ 3090

Last change on this file since 3090 was 3060, checked in by bird, 8 years ago

kmk,lib: ported kmk_touch to windows (nt).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: mscfakes.h 3060 2017-09-21 15:11:07Z bird $ */
2/** @file
3 * Unix fakes for MSC.
4 */
5
6/*
7 * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
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#define timeval windows_timeval
31
32/* Include the config file (kmk's) so we don't need to duplicate stuff from it here. */
33#include "config.h"
34
35#include <io.h>
36#include <direct.h>
37#include <time.h>
38#include <stdarg.h>
39#include <malloc.h>
40#include "getopt.h"
41#ifndef MSCFAKES_NO_WINDOWS_H
42# include <Windows.h>
43#endif
44
45#include <sys/stat.h>
46#include <io.h>
47#include <direct.h>
48#include "nt/ntstat.h"
49#include "nt/ntunlink.h"
50#if defined(MSC_DO_64_BIT_IO) && _MSC_VER >= 1400 /* We want 64-bit file lengths here when possible. */
51# define off_t __int64
52# define lseek _lseeki64
53#endif
54
55#undef timeval
56
57#undef PATH_MAX
58#define PATH_MAX _MAX_PATH
59#undef MAXPATHLEN
60#define MAXPATHLEN _MAX_PATH
61
62#define EX_OK 0
63#define EX_OSERR 1
64#define EX_NOUSER 1
65#define EX_USAGE 1
66
67#define STDIN_FILENO 0
68#define STDOUT_FILENO 1
69#define STDERR_FILENO 2
70
71#define F_OK 0
72#define X_OK 1
73#define W_OK 2
74#define R_OK 4
75
76#define EFTYPE EINVAL
77
78#define _PATH_DEVNULL "/dev/null"
79
80#ifndef MAX
81# define MAX(a,b) ((a) >= (b) ? (a) : (b))
82#endif
83
84typedef int mode_t;
85typedef unsigned short nlink_t;
86#if 0 /* found in config.h */
87typedef unsigned short uid_t;
88typedef unsigned short gid_t;
89#endif
90#if defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || defined(_WIN64)
91typedef __int64 ssize_t;
92#else
93typedef long ssize_t;
94#endif
95typedef unsigned long u_long;
96typedef unsigned int u_int;
97typedef unsigned short u_short;
98
99#if _MSC_VER >= 1600
100# include <stdint.h>
101#else
102typedef unsigned char uint8_t;
103typedef unsigned short uint16_t;
104typedef unsigned int uint32_t;
105typedef signed char int8_t;
106typedef signed short int16_t;
107typedef signed int int32_t;
108#endif
109
110struct timeval
111{
112 __time64_t tv_sec;
113 long tv_usec;
114};
115
116struct iovec
117{
118 char *iov_base;
119 size_t iov_len;
120};
121
122typedef __int64 intmax_t;
123#if 0 /* found in config.h */
124typedef unsigned __int64 uintmax_t;
125#endif
126
127#define chown(path, uid, gid) 0 /** @todo implement fchmod! */
128char *dirname(char *path);
129#define fsync(fd) 0
130#define fchown(fd,uid,gid) 0
131#define fchmod(fd, mode) 0 /** @todo implement fchmod! */
132#define geteuid() 0
133#define getegid() 0
134int lchmod(const char *path, mode_t mode);
135int msc_chmod(const char *path, mode_t mode);
136#define chmod msc_chmod
137#define lchown(path, uid, gid) chown(path, uid, gid)
138int link(const char *pszDst, const char *pszLink);
139int mkdir_msc(const char *path, mode_t mode);
140#define mkdir(path, mode) mkdir_msc(path, mode)
141#define mkfifo(path, mode) -1
142#define mknod(path, mode, devno) -1
143int mkstemp(char *temp);
144#define readlink(link, buf, size) -1
145#define reallocf(old, size) realloc(old, size)
146int rmdir_msc(const char *path);
147#define rmdir(path) rmdir_msc(path)
148intmax_t strtoimax(const char *nptr, char **endptr, int base);
149uintmax_t strtoumax(const char *nptr, char **endptr, int base);
150#define strtoll(a,b,c) strtoimax(a,b,c)
151#define strtoull(a,b,c) strtoumax(a,b,c)
152int asprintf(char **strp, const char *fmt, ...);
153int vasprintf(char **strp, const char *fmt, va_list ap);
154#if _MSC_VER < 1400
155int snprintf(char *buf, size_t size, const char *fmt, ...);
156#else
157#define snprintf _snprintf
158#endif
159int symlink(const char *pszDst, const char *pszLink);
160int utimes(const char *pszPath, const struct timeval *paTimes);
161int lutimes(const char *pszPath, const struct timeval *paTimes);
162ssize_t writev(int fd, const struct iovec *vector, int count);
163
164int gettimeofday(struct timeval *pNow, void *pvIgnored);
165struct tm *localtime_r(const __time64_t *pNow, struct tm *pResult);
166__time64_t timegm(struct tm *pNow);
167#undef mktime
168#define mktime _mktime64
169
170/* bird write ENOSPC hacks. */
171#undef write
172#define write msc_write
173ssize_t msc_write(int fd, const void *pvSrc, size_t cbSrc);
174
175/*
176 * MSC fake internals / helpers.
177 */
178int birdSetErrno(unsigned dwErr);
179
180#endif /* _MSC_VER */
181#endif
182
Note: See TracBrowser for help on using the repository browser.