src/platform_windows.h
author Markus Schaber <markus@pep-security.net>
Fri, 30 Sep 2016 21:16:56 +0200
branchkeysync-windows
changeset 1226 a4e082c43cdd
parent 1001 42e0841b71f0
child 1258 9c376b153898
permissions -rw-r--r--
Make the pEp Engine keysync branch compile on Windows again.

Warning: The changes are not yet tested. Especially the ones in platform_unix.*.
     1 #pragma once
     2 
     3 // Windows platform specifica
     4 
     5 #pragma warning(disable : 4996)
     6 
     7 // We need to make sure winsock2 is included before windows.h, or we will get redefinitions of symbols
     8 // as windows.h includes winsock1.h, so we will have duplicate symbols if windows.h is included first.
     9 // It seems some of our code includes sync.h before including winsock.h, leading to the failure.
    10 // Including winsock2.h here fixes the problem for now...
    11 #ifdef WIN32 
    12 #include <winsock2.h>
    13 #endif // WIN32 
    14 
    15 #include <Rpc.h>
    16 #include <string.h>
    17 #include <io.h>
    18 #include <basetsd.h>
    19 
    20 #ifdef __cplusplus
    21 extern "C" {
    22 #endif
    23 
    24 #define ssize_t SSIZE_T
    25 #define RTLD_LAZY 1
    26 #define mode_t int
    27 
    28 void *dlopen(const char *filename, int flag);
    29 int dlclose(void *handle);
    30 void *dlsym(void *handle, const char *symbol);
    31 int mkstemp(char *templ);
    32 
    33 #ifndef strdup
    34 #define strdup(A) _strdup((A))
    35 #endif
    36 #ifndef snprintf
    37 #if _MSC_VER<1900 // Includes undefined case. This is a check for VS 2015, which throws an error.
    38 #define snprintf(...) _snprintf(__VA_ARGS__)
    39 #endif
    40 #endif
    41 #ifndef strtok_r
    42 #define strtok_r(A, B, C) strtok_s((A), (B), (C))
    43 #endif
    44 #ifndef strncasecmp
    45 #define strncasecmp(A, B, C) _strnicmp((A), (B), (C))
    46 #endif
    47 #ifndef strcasecmp
    48 #define strcasecmp(A, B) _stricmp((A), (B))
    49 #endif
    50 #ifndef gmtime_r
    51 #define gmtime_r(A, B) gmtime_s((B), (A))
    52 #endif
    53 #ifndef ftruncate
    54 #define ftruncate(A, B) _chsize((A), (B))
    55 #endif
    56 #ifndef ftello
    57 #define ftello(A) ((off_t) _ftelli64(A))
    58 #endif
    59 
    60 char *strndup(const char *s1, size_t n);
    61 char *stpcpy(char *dst, const char *src);
    62 
    63 size_t strlcpy(char* dst, const	char* src, size_t size);
    64 size_t strlcat(char* dst, const	char* src, size_t size);
    65 
    66 const char *windoze_local_db(void);
    67 const char *windoze_system_db(void);
    68 const char *gpg_conf(void);
    69 
    70 long random(void);
    71 
    72 // on Windoze, uuid_t needs pointer semantics
    73 typedef UUID pEpUUID[1];
    74 #define _UUID_STRING_T
    75 typedef char uuid_string_t[37];
    76 
    77 void uuid_generate_random(pEpUUID out);
    78 int uuid_parse(char *in, pEpUUID uu);
    79 void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
    80 
    81 #ifndef inline
    82 #define inline __inline
    83 #endif
    84 
    85 #ifdef __cplusplus
    86 }
    87 #endif