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

Last change on this file was 3636, checked in by bird, 9 months ago

kmk/kmkbuiltins: Some UCRT & VC++ 2022 adjustments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
RevLine 
[370]1/* $Id: mscfakes.h 3636 2024-11-02 01:52:45Z bird $ */
2/** @file
3 * Unix fakes for MSC.
[2019]4 */
5
6/*
[2413]7 * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
[370]8 *
[2019]9 * This file is part of kBuild.
[370]10 *
[2019]11 * kBuild is free software; you can redistribute it and/or modify
[370]12 * it under the terms of the GNU General Public License as published by
[2019]13 * the Free Software Foundation; either version 3 of the License, or
[370]14 * (at your option) any later version.
15 *
[2019]16 * kBuild is distributed in the hope that it will be useful,
[370]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
[2019]22 * along with kBuild. If not, see <http://www.gnu.org/licenses/>
[370]23 *
24 */
25
[2019]26#ifndef ___mscfakes_h
27#define ___mscfakes_h
[370]28#ifdef _MSC_VER
29
[3060]30#define timeval windows_timeval
31
[2759]32/* Include the config file (kmk's) so we don't need to duplicate stuff from it here. */
33#include "config.h"
34
[370]35#include <io.h>
36#include <direct.h>
37#include <time.h>
[775]38#include <stdarg.h>
[809]39#include <malloc.h>
[3213]40#ifndef FAKES_NO_GETOPT_H
41# include "getopt.h"
42#endif
[2759]43#ifndef MSCFAKES_NO_WINDOWS_H
44# include <Windows.h>
45#endif
[370]46
[2592]47#include <sys/stat.h>
48#include <io.h>
49#include <direct.h>
[3636]50#include <stdio.h> /* unlink for UCRT */
[2702]51#include "nt/ntstat.h"
[2713]52#include "nt/ntunlink.h"
[3092]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
[1309]58#endif
59
[3060]60#undef timeval
61
[2178]62#undef PATH_MAX
63#define PATH_MAX _MAX_PATH
64#undef MAXPATHLEN
[370]65#define MAXPATHLEN _MAX_PATH
66
67#define EX_OK 0
68#define EX_OSERR 1
69#define EX_NOUSER 1
70#define EX_USAGE 1
71
72#define STDIN_FILENO 0
73#define STDOUT_FILENO 1
74#define STDERR_FILENO 2
75
76#define F_OK 0
77#define X_OK 1
78#define W_OK 2
79#define R_OK 4
80
81#define EFTYPE EINVAL
82
83#define _PATH_DEVNULL "/dev/null"
84
[2178]85#ifndef MAX
86# define MAX(a,b) ((a) >= (b) ? (a) : (b))
87#endif
[370]88
89typedef int mode_t;
90typedef unsigned short nlink_t;
[2178]91#if 0 /* found in config.h */
[370]92typedef unsigned short uid_t;
93typedef unsigned short gid_t;
[2178]94#endif
[3188]95typedef intptr_t ssize_t;
[370]96typedef unsigned long u_long;
97typedef unsigned int u_int;
98typedef unsigned short u_short;
99
[2766]100#if _MSC_VER >= 1600
101# include <stdint.h>
102#else
103typedef unsigned char uint8_t;
104typedef unsigned short uint16_t;
105typedef unsigned int uint32_t;
106typedef signed char int8_t;
107typedef signed short int16_t;
108typedef signed int int32_t;
109#endif
110
[3140]111struct msc_timeval
[370]112{
[3060]113 __time64_t tv_sec;
[370]114 long tv_usec;
115};
[3140]116#define timeval msc_timeval
[370]117
[775]118struct iovec
[370]119{
120 char *iov_base;
121 size_t iov_len;
122};
123
[775]124typedef __int64 intmax_t;
[2178]125#if 0 /* found in config.h */
[775]126typedef unsigned __int64 uintmax_t;
[2178]127#endif
[370]128
129#define chown(path, uid, gid) 0 /** @todo implement fchmod! */
130char *dirname(char *path);
131#define fsync(fd) 0
132#define fchown(fd,uid,gid) 0
133#define fchmod(fd, mode) 0 /** @todo implement fchmod! */
134#define geteuid() 0
[1292]135#define getegid() 0
[1710]136int lchmod(const char *path, mode_t mode);
137int msc_chmod(const char *path, mode_t mode);
138#define chmod msc_chmod
[370]139#define lchown(path, uid, gid) chown(path, uid, gid)
140int link(const char *pszDst, const char *pszLink);
141int mkdir_msc(const char *path, mode_t mode);
142#define mkdir(path, mode) mkdir_msc(path, mode)
143#define mkfifo(path, mode) -1
144#define mknod(path, mode, devno) -1
145int mkstemp(char *temp);
146#define readlink(link, buf, size) -1
147#define reallocf(old, size) realloc(old, size)
[936]148int rmdir_msc(const char *path);
149#define rmdir(path) rmdir_msc(path)
[775]150intmax_t strtoimax(const char *nptr, char **endptr, int base);
[805]151uintmax_t strtoumax(const char *nptr, char **endptr, int base);
[1117]152#define strtoll(a,b,c) strtoimax(a,b,c)
153#define strtoull(a,b,c) strtoumax(a,b,c)
[775]154int asprintf(char **strp, const char *fmt, ...);
155int vasprintf(char **strp, const char *fmt, va_list ap);
[370]156#if _MSC_VER < 1400
157int snprintf(char *buf, size_t size, const char *fmt, ...);
[526]158#else
159#define snprintf _snprintf
[775]160#endif
[370]161int symlink(const char *pszDst, const char *pszLink);
[3140]162int utimes(const char *pszPath, const struct msc_timeval *paTimes);
163int lutimes(const char *pszPath, const struct msc_timeval *paTimes);
[2759]164ssize_t writev(int fd, const struct iovec *vector, int count);
[370]165
[3140]166int gettimeofday(struct msc_timeval *pNow, void *pvIgnored);
[3060]167struct tm *localtime_r(const __time64_t *pNow, struct tm *pResult);
168__time64_t timegm(struct tm *pNow);
169#undef mktime
170#define mktime _mktime64
171
[2759]172/* bird write ENOSPC hacks. */
173#undef write
174#define write msc_write
175ssize_t msc_write(int fd, const void *pvSrc, size_t cbSrc);
[2702]176
177/*
178 * MSC fake internals / helpers.
179 */
180int birdSetErrno(unsigned dwErr);
181
[370]182#endif /* _MSC_VER */
[775]183#endif
[370]184
Note: See TracBrowser for help on using the repository browser.