compat.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "defaults.h"
  3. #include <cstdarg>
  4. #include <csignal>
  5. #if defined(_unix_)
  6. #include <unistd.h>
  7. #endif
  8. #if defined(_win_)
  9. #include <process.h>
  10. #endif
  11. extern "C" {
  12. #if defined(_win_)
  13. using pid_t = int;
  14. inline unsigned int alarm(unsigned int /*seconds*/) {
  15. return 0; // no alarm is currently set :)
  16. }
  17. #define SIGQUIT SIGBREAK // instead of 3
  18. #define SIGKILL SIGTERM // instead of 9
  19. #define SIGPIPE 13 // will not receive under win?
  20. #define SIGALRM 14 // will not receive under win?
  21. #endif
  22. #if defined(__FreeBSD__) || defined(_darwin_)
  23. #define HAVE_NATIVE_GETPROGNAME
  24. #endif
  25. #ifndef HAVE_NATIVE_GETPROGNAME
  26. const char* getprogname();
  27. #endif
  28. #if defined(_MSC_VER)
  29. void warn(const char* m, ...);
  30. void warnx(const char* m, ...);
  31. void vwarnx(const char* format, va_list ap);
  32. void vwarn(const char* format, va_list ap);
  33. [[noreturn]] void err(int e, const char* m, ...);
  34. [[noreturn]] void errx(int e, const char* m, ...);
  35. [[noreturn]] void verr(int status, const char* fmt, va_list args);
  36. [[noreturn]] void verrx(int status, const char* format, va_list ap);
  37. #else
  38. #include <err.h>
  39. #endif
  40. }
  41. #ifdef _MSC_VER
  42. #define popen _popen
  43. #define pclose _pclose
  44. #endif
  45. #ifdef _win_
  46. #define NAME_MAX FILENAME_MAX
  47. #endif
  48. #ifdef _sun_
  49. #define NAME_MAX PATH_MAX
  50. #endif
  51. #ifdef _win_
  52. #ifdef sleep // may be defined by perl
  53. #undef sleep
  54. #endif
  55. void sleep(i64 len);
  56. void usleep(i64 len);
  57. #endif
  58. #ifdef _win_
  59. int ftruncate(int fd, i64 length);
  60. int truncate(const char* name, i64 length);
  61. #endif
  62. #if defined(GNUC)
  63. #ifndef va_copy
  64. #define va_copy __va_copy
  65. #endif
  66. #endif