LLDB  mainline
windows/PosixApi.h
Go to the documentation of this file.
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 <cstdarg>
20 
21 // time_t, timespec, etc.
22 #include <ctime>
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 // pyconfig.h typedefs this. We require python headers to be included before
60 // any LLDB headers, but there's no way to prevent python's pid_t definition
61 // from leaking, so this is the best option.
62 #ifndef NO_PID_T
63 #include <sys/types.h>
64 #endif
65 
66 #ifdef _MSC_VER
67 
68 // PRIxxx format macros for printf()
69 #include <cinttypes>
70 
71 // open(), close(), creat(), etc.
72 #include <io.h>
73 
74 typedef unsigned short mode_t;
75 
76 // pyconfig.h typedefs this. We require python headers to be included before
77 // any LLDB headers, but there's no way to prevent python's pid_t definition
78 // from leaking, so this is the best option.
79 #ifndef NO_PID_T
80 typedef uint32_t pid_t;
81 #endif
82 
83 #define STDIN_FILENO 0
84 #define STDOUT_FILENO 1
85 #define STDERR_FILENO 2
86 
87 #define S_IFDIR _S_IFDIR
88 
89 #ifndef S_ISDIR
90 #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
91 #endif
92 
93 #endif // _MSC_VER
94 
95 // Various useful posix functions that are not present in Windows. We provide
96 // custom implementations.
97 int vasprintf(char **ret, const char *fmt, va_list ap);
98 char *strcasestr(const char *s, const char *find);
99 
100 #ifdef _MSC_VER
101 
102 char *basename(char *path);
103 char *dirname(char *path);
104 
105 int strcasecmp(const char *s1, const char *s2);
106 int strncasecmp(const char *s1, const char *s2, size_t n);
107 
108 #endif // _MSC_VER
109 
110 // empty functions
111 inline int posix_openpt(int flag) { LLVM_BUILTIN_UNREACHABLE; }
112 
113 inline int strerror_r(int errnum, char *buf, size_t buflen) {
114  LLVM_BUILTIN_UNREACHABLE;
115 }
116 
117 inline int unlockpt(int fd) { LLVM_BUILTIN_UNREACHABLE; }
118 inline int grantpt(int fd) { LLVM_BUILTIN_UNREACHABLE; }
119 inline char *ptsname(int fd) { LLVM_BUILTIN_UNREACHABLE; }
120 
121 inline pid_t fork(void) { LLVM_BUILTIN_UNREACHABLE; }
122 inline pid_t setsid(void) { LLVM_BUILTIN_UNREACHABLE; }
123 
124 #endif
unlockpt
int unlockpt(int fd)
Definition: windows/PosixApi.h:117
strerror_r
int strerror_r(int errnum, char *buf, size_t buflen)
Definition: windows/PosixApi.h:113
strcasestr
char * strcasestr(const char *s, const char *find)
Definition: Windows.cpp:47
vasprintf
int vasprintf(char **ret, const char *fmt, va_list ap)
Definition: Windows.cpp:25
posix_openpt
int posix_openpt(int flag)
Definition: windows/PosixApi.h:111
uint32_t
setsid
pid_t setsid(void)
Definition: windows/PosixApi.h:122
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
ptsname
char * ptsname(int fd)
Definition: windows/PosixApi.h:119
fork
pid_t fork(void)
Definition: windows/PosixApi.h:121
grantpt
int grantpt(int fd)
Definition: windows/PosixApi.h:118