PosixApi.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #ifndef liblldb_Host_windows_PosixApi_h
  9. #define liblldb_Host_windows_PosixApi_h
  10. #include "lldb/Host/Config.h"
  11. #include "llvm/Support/Compiler.h"
  12. #if !defined(_WIN32)
  13. #error "windows/PosixApi.h being #included on non Windows system!"
  14. #endif
  15. // va_start, va_end, etc macros.
  16. #include <cstdarg>
  17. // time_t, timespec, etc.
  18. #include <ctime>
  19. #ifndef PATH_MAX
  20. #define PATH_MAX 32768
  21. #endif
  22. #define O_NOCTTY 0
  23. #define O_NONBLOCK 0
  24. #define SIGTRAP 5
  25. #define SIGKILL 9
  26. #define SIGSTOP 20
  27. #ifndef S_IRUSR
  28. #define S_IRUSR S_IREAD /* read, user */
  29. #define S_IWUSR S_IWRITE /* write, user */
  30. #define S_IXUSR 0 /* execute, user */
  31. #endif
  32. #ifndef S_IRGRP
  33. #define S_IRGRP 0 /* read, group */
  34. #define S_IWGRP 0 /* write, group */
  35. #define S_IXGRP 0 /* execute, group */
  36. #endif
  37. #ifndef S_IROTH
  38. #define S_IROTH 0 /* read, others */
  39. #define S_IWOTH 0 /* write, others */
  40. #define S_IXOTH 0 /* execute, others */
  41. #endif
  42. #ifndef S_IRWXU
  43. #define S_IRWXU 0
  44. #endif
  45. #ifndef S_IRWXG
  46. #define S_IRWXG 0
  47. #endif
  48. #ifndef S_IRWXO
  49. #define S_IRWXO 0
  50. #endif
  51. #if HAVE_SYS_TYPES_H
  52. // pyconfig.h typedefs this. We require python headers to be included before
  53. // any LLDB headers, but there's no way to prevent python's pid_t definition
  54. // from leaking, so this is the best option.
  55. #ifndef NO_PID_T
  56. #include <sys/types.h>
  57. #endif
  58. #endif // HAVE_SYS_TYPES_H
  59. #ifdef _MSC_VER
  60. // PRIxxx format macros for printf()
  61. #include <cinttypes>
  62. // open(), close(), creat(), etc.
  63. #include <io.h>
  64. typedef unsigned short mode_t;
  65. // pyconfig.h typedefs this. We require python headers to be included before
  66. // any LLDB headers, but there's no way to prevent python's pid_t definition
  67. // from leaking, so this is the best option.
  68. #ifndef NO_PID_T
  69. typedef uint32_t pid_t;
  70. #endif
  71. #define STDIN_FILENO 0
  72. #define STDOUT_FILENO 1
  73. #define STDERR_FILENO 2
  74. #define S_IFDIR _S_IFDIR
  75. #ifndef S_ISDIR
  76. #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
  77. #endif
  78. #endif // _MSC_VER
  79. // Various useful posix functions that are not present in Windows. We provide
  80. // custom implementations.
  81. int vasprintf(char **ret, const char *fmt, va_list ap);
  82. char *strcasestr(const char *s, const char *find);
  83. #ifdef _MSC_VER
  84. char *basename(char *path);
  85. char *dirname(char *path);
  86. int strcasecmp(const char *s1, const char *s2);
  87. int strncasecmp(const char *s1, const char *s2, size_t n);
  88. #endif // _MSC_VER
  89. // empty functions
  90. inline int posix_openpt(int flag) { LLVM_BUILTIN_UNREACHABLE; }
  91. inline int strerror_r(int errnum, char *buf, size_t buflen) {
  92. LLVM_BUILTIN_UNREACHABLE;
  93. }
  94. inline int unlockpt(int fd) { LLVM_BUILTIN_UNREACHABLE; }
  95. inline int grantpt(int fd) { LLVM_BUILTIN_UNREACHABLE; }
  96. inline char *ptsname(int fd) { LLVM_BUILTIN_UNREACHABLE; }
  97. inline pid_t fork(void) { LLVM_BUILTIN_UNREACHABLE; }
  98. inline pid_t setsid(void) { LLVM_BUILTIN_UNREACHABLE; }
  99. #endif