src/platform_windows.h
author Hernâni Marques <hernani@pep.foundation>
Wed, 27 Jun 2018 00:52:09 +0200
changeset 2771 b0c0d39f643d
parent 2462 48b526a0daac
child 2830 d6f044e43e1a
permissions -rw-r--r--
typos (by reading for IETF)
     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 void *dlopen(const char *filename, int flag);
    34 int dlclose(void *handle);
    35 void *dlsym(void *handle, const char *symbol);
    36 int mkstemp(char *templ);
    37 
    38 time_t timegm(struct tm* tm);
    39 
    40 #ifndef strdup
    41 #define strdup(A) _strdup((A))
    42 #endif
    43 #ifndef snprintf
    44 #if _MSC_VER<1900 // Includes undefined case. This is a check for VS 2015, which throws an error.
    45 #define snprintf(...) _snprintf(__VA_ARGS__)
    46 #endif
    47 #endif
    48 #ifndef strtok_r
    49 #define strtok_r(A, B, C) strtok_s((A), (B), (C))
    50 #endif
    51 #ifndef strncasecmp
    52 #define strncasecmp(A, B, C) _strnicmp((A), (B), (C))
    53 #endif
    54 #ifndef strcasecmp
    55 #define strcasecmp(A, B) _stricmp((A), (B))
    56 #endif
    57 #ifndef gmtime_r
    58 #define gmtime_r(A, B) gmtime_s((B), (A))
    59 #endif
    60 #ifndef ftruncate
    61 #define ftruncate(A, B) _chsize((A), (B))
    62 #endif
    63 #ifndef ftello
    64 #define ftello(A) ((off_t) _ftelli64(A))
    65 #endif
    66 
    67 char *strndup(const char *s1, size_t n);
    68 char *stpcpy(char *dst, const char *src);
    69 
    70 size_t strlcpy(char* dst, const	char* src, size_t size);
    71 size_t strlcat(char* dst, const	char* src, size_t size);
    72 
    73 const char *windoze_local_db(void);
    74 const char *windoze_system_db(void);
    75 const char *gpg_conf(void);
    76 const char *gpg_agent_conf(void);
    77 
    78 long random(void);
    79 
    80 // on Windoze, uuid_t needs pointer semantics
    81 typedef UUID pEpUUID[1];
    82 #define _UUID_STRING_T
    83 typedef char uuid_string_t[37];
    84 
    85 void uuid_generate_random(pEpUUID out);
    86 int uuid_parse(char *in, pEpUUID uu);
    87 void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
    88 
    89 #ifndef __cplusplus
    90 #define inline __inline
    91 #endif
    92 
    93 #ifdef __cplusplus
    94 }
    95 #endif