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

Last change on this file since 3686 was 3682, checked in by bird, 3 months ago

lib/nt,kmk: Fixed around rm/unlink semantics and general support for long file names in lib/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 3682 2025-08-12 23:34:19Z 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#ifndef FAKES_NO_GETOPT_H
41# include "getopt.h"
42#endif
43#ifndef MSCFAKES_NO_WINDOWS_H
44# include <Windows.h>
45#endif
46
47#include <sys/stat.h>
48#include <io.h>
49#include <direct.h>
50#include <stdio.h> /* unlink for UCRT */
51#include "nt/ntstat.h"
52#include "nt/ntunlink.h" /* redefines both unlink and rmdir */
53#ifdef MSC_DO_64_BIT_IO
54# if _MSC_VER >= 1400 /* We want 64-bit file lengths here when possible. */
55# define off_t __int64
56# define lseek _lseeki64
57# endif
58#endif
59
60#undef timeval
61
62#undef PATH_MAX
63/*#define PATH_MAX _MAX_PATH */
64#define PATH_MAX 1024
65#undef MAXPATHLEN
66#define MAXPATHLEN PATH_MAX
67
68#define EX_OK 0
69#define EX_OSERR 1
70#define EX_NOUSER 1
71#define EX_USAGE 1
72
73#define STDIN_FILENO 0
74#define STDOUT_FILENO 1
75#define STDERR_FILENO 2
76
77#define F_OK 0
78#define X_OK 1
79#define W_OK 2
80#define R_OK 4
81
82#define EFTYPE EINVAL
83
84#define _PATH_DEVNULL "/dev/null"
85
86#ifndef MAX
87# define MAX(a,b) ((a) >= (b) ? (a) : (b))
88#endif
89
90typedef int mode_t;
91typedef unsigned short nlink_t;
92#if 0 /* found in config.h */
93typedef unsigned short uid_t;
94typedef unsigned short gid_t;
95#endif
96typedef intptr_t ssize_t;
97typedef unsigned long u_long;
98typedef unsigned int u_int;
99typedef unsigned short u_short;
100
101#if _MSC_VER >= 1600
102# include <stdint.h>
103#else
104typedef unsigned char uint8_t;
105typedef unsigned short uint16_t;
106typedef unsigned int uint32_t;
107typedef signed char int8_t;
108typedef signed short int16_t;
109typedef signed int int32_t;
110#endif
111
112struct msc_timeval
113{
114 __time64_t tv_sec;
115 long tv_usec;
116};
117#define timeval msc_timeval
118
119struct iovec
120{
121 char *iov_base;
122 size_t iov_len;
123};
124
125typedef __int64 intmax_t;
126#if 0 /* found in config.h */
127typedef unsigned __int64 uintmax_t;
128#endif
129
130#define chown(path, uid, gid) 0 /** @todo implement fchmod! */
131char *dirname(char *path);
132#define fsync(fd) 0
133#define fchown(fd,uid,gid) 0
134#define fchmod(fd, mode) 0 /** @todo implement fchmod! */
135#define geteuid() 0
136#define getegid() 0
137int lchmod(const char *path, mode_t mode);
138int msc_chmod(const char *path, mode_t mode);
139#define chmod msc_chmod
140#define lchown(path, uid, gid) chown(path, uid, gid)
141int link(const char *pszDst, const char *pszLink);
142int mkdir_msc(const char *path, mode_t mode);
143#define mkdir(path, mode) mkdir_msc(path, mode)
144#define mkfifo(path, mode) -1
145#define mknod(path, mode, devno) -1
146int mkstemp(char *temp);
147#define readlink(link, buf, size) -1
148#define reallocf(old, size) realloc(old, size)
149/*int rmdir_msc(const char *path);
150#define rmdir(path) rmdir_msc(path) */
151intmax_t strtoimax(const char *nptr, char **endptr, int base);
152uintmax_t strtoumax(const char *nptr, char **endptr, int base);
153#define strtoll(a,b,c) strtoimax(a,b,c)
154#define strtoull(a,b,c) strtoumax(a,b,c)
155int asprintf(char **strp, const char *fmt, ...);
156int vasprintf(char **strp, const char *fmt, va_list ap);
157#if _MSC_VER < 1400
158int snprintf(char *buf, size_t size, const char *fmt, ...);
159#else
160#define snprintf _snprintf
161#endif
162int symlink(const char *pszDst, const char *pszLink);
163int utimes(const char *pszPath, const struct msc_timeval *paTimes);
164int lutimes(const char *pszPath, const struct msc_timeval *paTimes);
165ssize_t writev(int fd, const struct iovec *vector, int count);
166
167int gettimeofday(struct msc_timeval *pNow, void *pvIgnored);
168struct tm *localtime_r(const __time64_t *pNow, struct tm *pResult);
169__time64_t timegm(struct tm *pNow);
170#undef mktime
171#define mktime _mktime64
172
173/* bird write ENOSPC hacks. */
174#undef write
175#define write msc_write
176ssize_t msc_write(int fd, const void *pvSrc, size_t cbSrc);
177
178/*
179 * MSC fake internals / helpers.
180 */
181int birdSetErrno(unsigned dwErr);
182
183#endif /* _MSC_VER */
184#endif
185
Note: See TracBrowser for help on using the repository browser.