p≡p engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
6.3 KiB

8 years ago
8 years ago
8 years ago
6 years ago
7 years ago
2 years ago
7 years ago
3 years ago
8 years ago
8 years ago
8 years ago
4 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
6 years ago
6 years ago
6 years ago
7 years ago
8 years ago
  1. /**
  2. * @file platform_windows.h
  3. * @brief Windows platform-specific implementation details
  4. * @license GNU General Public License 3.0 - see LICENSE.txt
  5. */
  6. #ifndef PLATFORM_WINDOWS_H
  7. #define PLATFORM_WINDOWS_H
  8. // Windows platform specifica
  9. // The windows compiler used by default does not support GNU-style attributes;
  10. // let us just disable them altogether with a CPP defintition, so that
  11. // attributes become no-ops on windows but keep functioning on the other
  12. // platforms.
  13. // Notice that this definition is extremely conservative: supporting exactly
  14. // one argument would suffice.
  15. #define __attribute__(...) /* nothing */
  16. #define attribute __attribute__
  17. #ifndef _EXPORT_PEP_ENGINE_DLL
  18. #define _EXPORT_PEP_ENGINE_DLL
  19. #endif
  20. #pragma warning(disable : 4996)
  21. // We need to make sure winsock2 is included before windows.h, or we will get redefinitions of symbols
  22. // as windows.h includes winsock1.h, so we will have duplicate symbols if windows.h is included first.
  23. // It seems some of our code includes sync.h before including winsock.h, leading to the failure.
  24. // Including winsock2.h here fixes the problem for now...
  25. #ifdef WIN32
  26. // winsock2.h includes windows.h and that leads to the definition of `min` and `max`
  27. // which causes compile errors elsewhere.
  28. #define NOMINMAX
  29. #include <winsock2.h>
  30. #endif // WIN32
  31. #include <Rpc.h>
  32. #include <string.h>
  33. #include <io.h>
  34. #include <basetsd.h>
  35. #include <time.h>
  36. #include "timestamp.h"
  37. // pEp files and directories
  38. #ifndef PER_USER_DIRECTORY
  39. #define PER_USER_DIRECTORY "%LOCALAPPDATA%\\pEp"
  40. #endif
  41. #ifndef PER_MACHINE_DIRECTORY
  42. #define PER_MACHINE_DIRECTORY "%ALLUSERSPROFILE%\\pEp"
  43. #endif
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. #define ssize_t SSIZE_T
  48. #define RTLD_LAZY 1
  49. #define mode_t int
  50. #ifndef MIN
  51. #define MIN(A, B) ((A)>(B) ? (B) : (A))
  52. #define MAX(A, B) ((A)>(B) ? (A) : (B))
  53. #endif
  54. /**
  55. * <!-- dlopen() -->
  56. *
  57. * @brief TODO
  58. *
  59. * @param[in] filename const char*
  60. * @param[in] flag int
  61. *
  62. */
  63. void *dlopen(const char *filename, int flag);
  64. /**
  65. * <!-- dlclose() -->
  66. *
  67. * @brief TODO
  68. *
  69. * @param[in] handle void*
  70. *
  71. */
  72. int dlclose(void *handle);
  73. /**
  74. * <!-- dlsym() -->
  75. *
  76. * @brief TODO
  77. *
  78. * @param[in] handle void*
  79. * @param[in] symbol const char*
  80. *
  81. */
  82. void *dlsym(void *handle, const char *symbol);
  83. /**
  84. * <!-- mkstemp() -->
  85. *
  86. * @brief TODO
  87. *
  88. * @param[in] templ char*
  89. *
  90. */
  91. int mkstemp(char *templ);
  92. // Nota bene: It does _not_ respect timeptr->tm_gmtoff, so it behaves the same as its POSIX original.
  93. // Use timegm_with_gmtoff() from <pEp/timestamp.h> or that.
  94. /**
  95. * <!-- timegm() -->
  96. *
  97. * @brief TODO
  98. *
  99. * @param[in] timeptr timestamp*
  100. *
  101. */
  102. DYNAMIC_API time_t timegm(timestamp *timeptr);
  103. #ifndef strdup
  104. #define strdup(A) _strdup((A))
  105. #endif
  106. #ifndef snprintf
  107. #if _MSC_VER<1900 // Includes undefined case. This is a check for VS 2015, which throws an error.
  108. #define snprintf(...) _snprintf(__VA_ARGS__)
  109. #endif
  110. #endif
  111. #ifndef strtok_r
  112. #define strtok_r(A, B, C) strtok_s((A), (B), (C))
  113. #endif
  114. #ifndef strncasecmp
  115. #define strncasecmp(A, B, C) _strnicmp((A), (B), (C))
  116. #endif
  117. #ifndef strcasecmp
  118. #define strcasecmp(A, B) _stricmp((A), (B))
  119. #endif
  120. #ifndef gmtime_r
  121. #define gmtime_r(A, B) gmtime_s((B), (A))
  122. #endif
  123. #ifndef ftruncate
  124. #define ftruncate(A, B) _chsize((A), (B))
  125. #endif
  126. #ifndef ftello
  127. #define ftello(A) ((off_t) _ftelli64(A))
  128. #endif
  129. /**
  130. * <!-- strndup() -->
  131. *
  132. * @brief TODO
  133. *
  134. * @param[in] s1 const char*
  135. * @param[in] n size_t
  136. *
  137. */
  138. char *strndup(const char *s1, size_t n);
  139. /**
  140. * <!-- stpcpy() -->
  141. *
  142. * @brief TODO
  143. *
  144. * @param[in] dst char*
  145. * @param[in] src const char*
  146. *
  147. */
  148. char *stpcpy(char *dst, const char *src);
  149. /**
  150. * <!-- strlcpy() -->
  151. *
  152. * @brief TODO
  153. *
  154. * @param[in] dst char*
  155. * @param[in] src const char*
  156. * @param[in] size size_t
  157. *
  158. */
  159. size_t strlcpy(char* dst, const char* src, size_t size);
  160. /**
  161. * <!-- strlcat() -->
  162. *
  163. * @brief TODO
  164. *
  165. * @param[in] dst char*
  166. * @param[in] src const char*
  167. * @param[in] size size_t
  168. *
  169. */
  170. size_t strlcat(char* dst, const char* src, size_t size);
  171. /**
  172. * <!-- strnstr() -->
  173. *
  174. * @brief TODO
  175. *
  176. * @param[in] big const char*
  177. * @param[in] little const char*
  178. * @param[in] len size_t
  179. *
  180. */
  181. char *strnstr(const char *big, const char *little, size_t len);
  182. /**
  183. * <!-- windoze_keys_db() -->
  184. *
  185. * @brief TODO
  186. *
  187. *
  188. */
  189. const char *windoze_keys_db(void);
  190. /**
  191. * <!-- windoze_local_db() -->
  192. *
  193. * @brief TODO
  194. *
  195. *
  196. */
  197. const char *windoze_local_db(void);
  198. /**
  199. * <!-- windoze_system_db() -->
  200. *
  201. * @brief TODO
  202. *
  203. *
  204. */
  205. const char *windoze_system_db(void);
  206. /**
  207. * <!-- log_output_debug() -->
  208. *
  209. * @brief TODO
  210. *
  211. * @param[in] title const char*
  212. * @param[in] entity const char*
  213. * @param[in] description const char*
  214. * @param[in] comment const char*
  215. *
  216. */
  217. void log_output_debug(const char *title, const char *entity, const char *description, const char *comment);
  218. /**
  219. * <!-- random() -->
  220. *
  221. * @brief TODO
  222. *
  223. *
  224. */
  225. long random(void);
  226. // on Windoze, uuid_t needs pointer semantics
  227. typedef UUID pEpUUID[1];
  228. #define _UUID_STRING_T
  229. typedef char uuid_string_t[37];
  230. /**
  231. * <!-- uuid_generate_random() -->
  232. *
  233. * @brief TODO
  234. *
  235. * @param[in] out pEpUUID
  236. *
  237. */
  238. void uuid_generate_random(pEpUUID out);
  239. /**
  240. * <!-- uuid_parse() -->
  241. *
  242. * @brief TODO
  243. *
  244. * @param[in] in char*
  245. * @param[in] uu pEpUUID
  246. *
  247. */
  248. int uuid_parse(char *in, pEpUUID uu);
  249. /**
  250. * <!-- uuid_unparse_upper() -->
  251. *
  252. * @brief TODO
  253. *
  254. * @param[in] uu pEpUUID
  255. * @param[in] out uuid_string_t
  256. *
  257. */
  258. void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
  259. #ifndef __cplusplus
  260. #define inline __inline
  261. #endif
  262. #ifdef __cplusplus
  263. }
  264. #endif
  265. #endif