src/platform_windows.h
author Volker Birk <vb@pep.foundation>
Wed, 29 Aug 2018 17:10:23 +0200
branchsync
changeset 2899 63b619aef131
parent 2830 d6f044e43e1a
child 3835 65f3c7d59eb1
child 3901 cdfe2dddb5da
permissions -rw-r--r--
somewhat bigger
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #pragma once
     5 
     6 // Windows platform specifica
     7 
     8 #define _EXPORT_PEP_ENGINE_DLL
     9 #pragma warning(disable : 4996)
    10 
    11 // We need to make sure winsock2 is included before windows.h, or we will get redefinitions of symbols
    12 // as windows.h includes winsock1.h, so we will have duplicate symbols if windows.h is included first.
    13 // It seems some of our code includes sync.h before including winsock.h, leading to the failure.
    14 // Including winsock2.h here fixes the problem for now...
    15 #ifdef WIN32 
    16 #include <winsock2.h>
    17 #endif // WIN32 
    18 
    19 #include <Rpc.h>
    20 #include <string.h>
    21 #include <io.h>
    22 #include <basetsd.h>
    23 #include <time.h>
    24 
    25 #ifdef __cplusplus
    26 extern "C" {
    27 #endif
    28 
    29 #define ssize_t SSIZE_T
    30 #define RTLD_LAZY 1
    31 #define mode_t int
    32 
    33 #ifndef MIN
    34 #define MIN(A, B) ((A)>(B) ? (B) : (A))
    35 #define MAX(A, B) ((A)>(B) ? (A) : (B))
    36 #endif
    37 
    38 void *dlopen(const char *filename, int flag);
    39 int dlclose(void *handle);
    40 void *dlsym(void *handle, const char *symbol);
    41 int mkstemp(char *templ);
    42 
    43 time_t timegm(struct tm* tm);
    44 
    45 #ifndef strdup
    46 #define strdup(A) _strdup((A))
    47 #endif
    48 #ifndef snprintf
    49 #if _MSC_VER<1900 // Includes undefined case. This is a check for VS 2015, which throws an error.
    50 #define snprintf(...) _snprintf(__VA_ARGS__)
    51 #endif
    52 #endif
    53 #ifndef strtok_r
    54 #define strtok_r(A, B, C) strtok_s((A), (B), (C))
    55 #endif
    56 #ifndef strncasecmp
    57 #define strncasecmp(A, B, C) _strnicmp((A), (B), (C))
    58 #endif
    59 #ifndef strcasecmp
    60 #define strcasecmp(A, B) _stricmp((A), (B))
    61 #endif
    62 #ifndef gmtime_r
    63 #define gmtime_r(A, B) gmtime_s((B), (A))
    64 #endif
    65 #ifndef ftruncate
    66 #define ftruncate(A, B) _chsize((A), (B))
    67 #endif
    68 #ifndef ftello
    69 #define ftello(A) ((off_t) _ftelli64(A))
    70 #endif
    71 
    72 char *strndup(const char *s1, size_t n);
    73 char *stpcpy(char *dst, const char *src);
    74 
    75 size_t strlcpy(char* dst, const	char* src, size_t size);
    76 size_t strlcat(char* dst, const	char* src, size_t size);
    77 
    78 const char *windoze_local_db(void);
    79 const char *windoze_system_db(void);
    80 const char *gpg_conf(void);
    81 const char *gpg_agent_conf(void);
    82 
    83 long random(void);
    84 
    85 // on Windoze, uuid_t needs pointer semantics
    86 typedef UUID pEpUUID[1];
    87 #define _UUID_STRING_T
    88 typedef char uuid_string_t[37];
    89 
    90 void uuid_generate_random(pEpUUID out);
    91 int uuid_parse(char *in, pEpUUID uu);
    92 void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
    93 
    94 #ifndef __cplusplus
    95 #define inline __inline
    96 #endif
    97 
    98 #ifdef __cplusplus
    99 }
   100 #endif