mingw-compat.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef NIXIO_MINGW_COMPAT_H_
  2. #define NIXIO_MINGW_COMPAT_H_
  3. #include <winsock2.h>
  4. #include <ws2tcpip.h>
  5. #include <io.h>
  6. #include <process.h>
  7. #include <stdint.h>
  8. #include <sys/stat.h>
  9. #include <errno.h>
  10. typedef unsigned int uint;
  11. typedef unsigned long ulong;
  12. #define S_ISLNK(m) 0
  13. #define S_ISSOCK(m) 0
  14. #define EWOULDBLOCK WSAEWOULDBLOCK
  15. #define EAFNOSUPPORT WSAEAFNOSUPPORT
  16. #define ENOPROTOOPT WSAENOPROTOOPT
  17. #define SHUT_RD SD_RECEIVE
  18. #define SHUT_WR SD_SEND
  19. #define SHUT_RDWR SD_BOTH
  20. #define pipe(fds) _pipe(fds, 65536, 0)
  21. #define fsync _commit
  22. #define lseek lseek64
  23. #define stat _stati64
  24. #define lstat _stati64
  25. #define fstat _fstati64
  26. #define F_LOCK 1
  27. #define F_ULOCK 0
  28. #define F_TLOCK 2
  29. #define F_TEST 3
  30. int nixio__mgw_lockf(int fd, int cmd, off_t len);
  31. #define lockf nixio__mgw_lockf
  32. const char* nixio__mgw_inet_ntop
  33. (int af, const void *src, char *dst, socklen_t size);
  34. #define inet_ntop nixio__mgw_inet_ntop
  35. int nixio__mgw_inet_pton (int af, const char *src, void *dst);
  36. #define inet_pton nixio__mgw_inet_pton
  37. #ifndef POLLIN
  38. #define POLLIN 0x001
  39. #define POLLOUT 0x004
  40. #define POLLERR 0x008
  41. struct pollfd {
  42. int fd;
  43. short events;
  44. short revents;
  45. };
  46. #endif
  47. typedef int nfds_t;
  48. int nixio__mgw_poll(struct pollfd *fds, nfds_t nfds, int timeout);
  49. #define poll nixio__mgw_poll
  50. struct timespec {
  51. time_t tv_sec;
  52. long tv_nsec;
  53. };
  54. int nixio__mgw_nanosleep(const struct timespec *req, struct timespec *rem);
  55. #define nanosleep nixio__mgw_nanosleep
  56. char* nixio__mgw_realpath(const char *path, char *resolved);
  57. #define realpath nixio__mgw_realpath
  58. int nixio__mgw_link(const char *oldpath, const char *newpath);
  59. #define link nixio__mgw_link
  60. int nixio__mgw_utimes(const char *filename, const struct timeval times[2]);
  61. #define utimes nixio__mgw_utimes
  62. #define setenv(k, v, o) !SetEnvironmentVariable(k, v)
  63. #define unsetenv(k) !SetEnvironmentVariable(k, NULL)
  64. #define execv(p, a) execv(p, (const char* const*)a)
  65. #define execvp(p, a) execvp(p, (const char* const*)a)
  66. #define execve(p, a, e) execve(p, (const char* const*)a, (const char* const*)e)
  67. #define mkdir(p, m) mkdir(p)
  68. #define nixio__perror_s(L) \
  69. errno = WSAGetLastError(); \
  70. return nixio__perror(L);
  71. #define nixio__pstatus_s(L, c) \
  72. errno = WSAGetLastError(); \
  73. return nixio__pstatus(L, c);
  74. #define NIXIO_WSA_CONSTANT(x) \
  75. lua_pushinteger(L, x); \
  76. lua_setfield(L, -2, #x+3);
  77. void nixio_open__mingw(lua_State *L);
  78. #endif /* NIXIO_MINGW_COMPAT_H_ */