1 //===-- windows/PosixApi.h --------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_Host_windows_PosixApi_h
10 #define liblldb_Host_windows_PosixApi_h
11 
12 #include "lldb/Host/Config.h"
13 #include "llvm/Support/Compiler.h"
14 #if !defined(_WIN32)
15 #error "windows/PosixApi.h being #included on non Windows system!"
16 #endif
17 
18 // va_start, va_end, etc macros.
19 #include <stdarg.h>
20 
21 // time_t, timespec, etc.
22 #include <time.h>
23 
24 #ifndef PATH_MAX
25 #define PATH_MAX 32768
26 #endif
27 
28 #define O_NOCTTY 0
29 #define O_NONBLOCK 0
30 #define SIGTRAP 5
31 #define SIGKILL 9
32 #define SIGSTOP 20
33 
34 #ifndef S_IRUSR
35 #define S_IRUSR S_IREAD  /* read, user */
36 #define S_IWUSR S_IWRITE /* write, user */
37 #define S_IXUSR 0        /* execute, user */
38 #endif
39 #ifndef S_IRGRP
40 #define S_IRGRP 0 /* read, group */
41 #define S_IWGRP 0 /* write, group */
42 #define S_IXGRP 0 /* execute, group */
43 #endif
44 #ifndef S_IROTH
45 #define S_IROTH 0 /* read, others */
46 #define S_IWOTH 0 /* write, others */
47 #define S_IXOTH 0 /* execute, others */
48 #endif
49 #ifndef S_IRWXU
50 #define S_IRWXU 0
51 #endif
52 #ifndef S_IRWXG
53 #define S_IRWXG 0
54 #endif
55 #ifndef S_IRWXO
56 #define S_IRWXO 0
57 #endif
58 
59 #if HAVE_SYS_TYPES_H
60 // pyconfig.h typedefs this.  We require python headers to be included before
61 // any LLDB headers, but there's no way to prevent python's pid_t definition
62 // from leaking, so this is the best option.
63 #ifndef NO_PID_T
64 #include <sys/types.h>
65 #endif
66 #endif // HAVE_SYS_TYPES_H
67 
68 #ifdef _MSC_VER
69 
70 // PRIxxx format macros for printf()
71 #include <inttypes.h>
72 
73 // open(), close(), creat(), etc.
74 #include <io.h>
75 
76 typedef unsigned short mode_t;
77 
78 // pyconfig.h typedefs this.  We require python headers to be included before
79 // any LLDB headers, but there's no way to prevent python's pid_t definition
80 // from leaking, so this is the best option.
81 #ifndef NO_PID_T
82 typedef uint32_t pid_t;
83 #endif
84 
85 #define STDIN_FILENO 0
86 #define STDOUT_FILENO 1
87 #define STDERR_FILENO 2
88 
89 #define S_IFDIR _S_IFDIR
90 
91 #ifndef S_ISDIR
92 #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
93 #endif
94 
95 #endif // _MSC_VER
96 
97 // Various useful posix functions that are not present in Windows.  We provide
98 // custom implementations.
99 int vasprintf(char **ret, const char *fmt, va_list ap);
100 char *strcasestr(const char *s, const char *find);
101 char *realpath(const char *name, char *resolved);
102 
103 #ifdef _MSC_VER
104 
105 char *basename(char *path);
106 char *dirname(char *path);
107 
108 int strcasecmp(const char *s1, const char *s2);
109 int strncasecmp(const char *s1, const char *s2, size_t n);
110 
111 #endif // _MSC_VER
112 
113 // empty functions
posix_openpt(int flag)114 inline int posix_openpt(int flag) { LLVM_BUILTIN_UNREACHABLE; }
115 
strerror_r(int errnum,char * buf,size_t buflen)116 inline int strerror_r(int errnum, char *buf, size_t buflen) {
117   LLVM_BUILTIN_UNREACHABLE;
118 }
119 
unlockpt(int fd)120 inline int unlockpt(int fd) { LLVM_BUILTIN_UNREACHABLE; }
grantpt(int fd)121 inline int grantpt(int fd) { LLVM_BUILTIN_UNREACHABLE; }
ptsname(int fd)122 inline char *ptsname(int fd) { LLVM_BUILTIN_UNREACHABLE; }
123 
fork(void)124 inline pid_t fork(void) { LLVM_BUILTIN_UNREACHABLE; }
setsid(void)125 inline pid_t setsid(void) { LLVM_BUILTIN_UNREACHABLE; }
126 
127 #endif
128