src/platform_windows.h
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:30:19 +0200
branchENGINE-233
changeset 2727 b8b0443804da
parent 1513 e7f7e42385b5
child 2117 964ed4c8a7c1
permissions -rw-r--r--
close branch
     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 #pragma warning(disable : 4996)
     9 
    10 // We need to make sure winsock2 is included before windows.h, or we will get redefinitions of symbols
    11 // as windows.h includes winsock1.h, so we will have duplicate symbols if windows.h is included first.
    12 // It seems some of our code includes sync.h before including winsock.h, leading to the failure.
    13 // Including winsock2.h here fixes the problem for now...
    14 #ifdef WIN32 
    15 #include <winsock2.h>
    16 #endif // WIN32 
    17 
    18 #include <Rpc.h>
    19 #include <string.h>
    20 #include <io.h>
    21 #include <basetsd.h>
    22 #include <time.h>
    23 
    24 #ifdef __cplusplus
    25 extern "C" {
    26 #endif
    27 
    28 #define ssize_t SSIZE_T
    29 #define RTLD_LAZY 1
    30 #define mode_t int
    31 
    32 void *dlopen(const char *filename, int flag);
    33 int dlclose(void *handle);
    34 void *dlsym(void *handle, const char *symbol);
    35 int mkstemp(char *templ);
    36 
    37 time_t timegm(struct tm* tm);
    38 
    39 #ifndef strdup
    40 #define strdup(A) _strdup((A))
    41 #endif
    42 #ifndef snprintf
    43 #if _MSC_VER<1900 // Includes undefined case. This is a check for VS 2015, which throws an error.
    44 #define snprintf(...) _snprintf(__VA_ARGS__)
    45 #endif
    46 #endif
    47 #ifndef strtok_r
    48 #define strtok_r(A, B, C) strtok_s((A), (B), (C))
    49 #endif
    50 #ifndef strncasecmp
    51 #define strncasecmp(A, B, C) _strnicmp((A), (B), (C))
    52 #endif
    53 #ifndef strcasecmp
    54 #define strcasecmp(A, B) _stricmp((A), (B))
    55 #endif
    56 #ifndef gmtime_r
    57 #define gmtime_r(A, B) gmtime_s((B), (A))
    58 #endif
    59 #ifndef ftruncate
    60 #define ftruncate(A, B) _chsize((A), (B))
    61 #endif
    62 #ifndef ftello
    63 #define ftello(A) ((off_t) _ftelli64(A))
    64 #endif
    65 
    66 char *strndup(const char *s1, size_t n);
    67 char *stpcpy(char *dst, const char *src);
    68 
    69 size_t strlcpy(char* dst, const	char* src, size_t size);
    70 size_t strlcat(char* dst, const	char* src, size_t size);
    71 
    72 const char *windoze_local_db(void);
    73 const char *windoze_system_db(void);
    74 const char *gpg_conf(void);
    75 const char *gpg_agent_conf(void);
    76 
    77 long random(void);
    78 
    79 // on Windoze, uuid_t needs pointer semantics
    80 typedef UUID pEpUUID[1];
    81 #define _UUID_STRING_T
    82 typedef char uuid_string_t[37];
    83 
    84 void uuid_generate_random(pEpUUID out);
    85 int uuid_parse(char *in, pEpUUID uu);
    86 void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
    87 
    88 #ifndef inline
    89 #define inline __inline
    90 #endif
    91 
    92 #ifdef __cplusplus
    93 }
    94 #endif