cs.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * csacred.com crt
  3. * Copyright (c) 2007-2018 ls
  4. **/
  5. #ifndef _CS_CRT_H_INCLUDED_
  6. #define _CS_CRT_H_INCLUDED_
  7. #define cs_version 062
  8. #define CS_VERSION "0.6.2"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <stdarg.h>
  16. #include <fcntl.h>
  17. #include <errno.h>
  18. #include <signal.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <time.h>
  22. #include <sys/timeb.h>
  23. #include <errno.h>
  24. #define CS_OK 0
  25. #define CS_ERR -1
  26. #define CS_AGAIN -2
  27. #define CS_BUSY -3
  28. #define CS_DONE -4
  29. #define CS_DECLINED -5
  30. #define CS_ABORT -6
  31. /*
  32. * Platform defined
  33. *
  34. * __linux__ // Linux
  35. * __APPLE__ // osx
  36. * __MVS__ // os390
  37. * _PASE // posix
  38. * _AIX // aix
  39. * __sun // sun os
  40. * __FreeBSD__ // freebsd
  41. * __OpenBSD__ // openbsd
  42. * __NetBSD__ // netbsd
  43. **/
  44. /* Platform */
  45. #ifdef _WIN32 /* Windows */
  46. #include <winsock2.h>
  47. //#include <mswsock.h>
  48. #include <wininet.h>
  49. #include <winreg.h>
  50. #include <process.h>
  51. #include <tchar.h>
  52. #include <io.h>
  53. #include <ws2tcpip.h>
  54. #ifndef LIBCS_STATIC
  55. #ifdef LIBCS_EXPORTS
  56. #define CS_API _declspec(dllexport)
  57. #else
  58. #define CS_API _declspec(dllimport)
  59. #endif
  60. #else
  61. #define CS_API
  62. #endif
  63. #define cs_inline __inline
  64. #define cs_int64_t __int64
  65. #define cs_uint64_t unsigned __int64
  66. #define cs_sock_t SOCKET
  67. #define cs_s64 "%I64d"
  68. #define cs_us64 "%I64u"
  69. #if _MSC_VER > 1200 /* VC6+ */
  70. typedef intptr_t cs_int_t;
  71. typedef uintptr_t cs_uint_t;
  72. #else /* VC6 */
  73. #define _WIN32_WINNT 0x0500
  74. typedef int cs_int_t;
  75. typedef unsigned int cs_uint_t;
  76. #endif
  77. #define cs_errno GetLastError()
  78. //#define cs_sock_errno GetLastError() // WSAGetLastError()
  79. #else /* Linux/BSD/... */
  80. #include <stdint.h>
  81. #include <unistd.h>
  82. #include <sys/socket.h>
  83. #include <netinet/in.h>
  84. #include <netinet/tcp.h> /* TCP_NODELAY, TCP_CORK */
  85. #include <arpa/inet.h>
  86. #include <netdb.h>
  87. #include <pthread.h>
  88. #include <poll.h>
  89. #include <sys/malloc.h>
  90. #include <sys/time.h>
  91. #define CS_API
  92. #define cs_inline inline
  93. typedef intptr_t cs_int_t;
  94. typedef uintptr_t cs_uint_t;
  95. #define cs_int64_t int64_t
  96. #define cs_uint64_t uint64_t
  97. #define cs_sock_t int
  98. #define cs_errno errno
  99. //#define cs_sock_errno errno
  100. #define cs_s64 "%lld"
  101. #define cs_us64 "%llu"
  102. #endif
  103. #ifndef u_char
  104. #define u_char unsigned char
  105. #endif
  106. #define CS_ALIGNMENT sizeof(unsigned long) /* platform word */
  107. #define cs_align(d, a) (((d) + (a - 1)) & ~(a - 1))
  108. #define cs_align_ptr(p, a) (u_char *) (((uintptr_t) (p) + \
  109. ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1))
  110. #define cs_offsetof(type, member) ((size_t)&((type *)0)->member)
  111. #ifdef _WIN32
  112. #define cs_container_of(ptr, type, member) (type *)((char *)ptr - \
  113. cs_offsetof(type, member))
  114. #else
  115. #define cs_container_of(ptr, type, member) ({ \
  116. const typeof(((type *)0)->member) *__mptr = (ptr); \
  117. (type *)((char *)__mptr - cs_offsetof(type, member));})
  118. #endif
  119. CS_API const u_char *cs_libversion();
  120. #ifdef __cplusplus
  121. }
  122. #endif /* C++ support */
  123. #endif