src/platform_unix.h
author Claudio Luck <claudio.luck@pep.foundation>
Mon, 20 May 2019 13:13:46 +0200
branchENGINE-524
changeset 3736 b28bcc5b8c0c
parent 3638 4ba9bd8b80c1
child 3836 f7ec3ffc9487
permissions -rw-r--r--
WIP: ENGINE-524: use new fn signature
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #ifndef __APPLE__
     5 #define _POSIX_C_SOURCE 200809L
     6 #endif
     7 
     8 #include <time.h>
     9 #include <unistd.h>
    10 #include <strings.h>
    11 #include <sys/select.h>
    12 #include <sys/param.h>
    13 #include <regex.h>
    14 
    15 #ifndef ANDROID
    16 #include <uuid/uuid.h>
    17 #endif
    18 
    19 #include "pEpEngine.h"
    20 
    21 #ifdef __cplusplus
    22 extern "C" {
    23 #endif
    24 
    25 #ifdef NDEBUG
    26 int unix_local_db_file(const char *buffer, const char *fname);
    27 const char *unix_local_db(void);
    28 const char *unix_system_db(void);
    29 const char *gpg_conf(void);
    30 const char *gpg_agent_conf(void);
    31 const char *gpg_home(void);
    32 #else
    33 int unix_local_db_file(const char *buffer, const char *fname, int reset);
    34 const char *unix_local_db(int reset);
    35 const char *unix_system_db(int reset);
    36 const char *gpg_conf(int reset);
    37 const char *gpg_agent_conf(int reset);
    38 const char *gpg_home(int reset);
    39 #endif
    40 
    41 
    42 #ifdef ANDROID
    43 
    44 time_t timegm(struct tm* const t);
    45 
    46 char *stpncpy(char *, const char *, size_t);
    47 char *stpcpy(char *, const char *);
    48 
    49 // Beware: predictable pseudo random with static seed!
    50 // Only the lowest 31 bits are filled randomly.
    51 //long int random(void);
    52 
    53 const char *android_system_db(void);
    54 #define SYSTEM_DB android_system_db()
    55 #ifdef __APPLE__
    56 #define LIBGPGME "libgpgme.11.dylib"
    57 #else
    58 #define LIBGPGME "libgpgme.so"
    59 #endif
    60 
    61 #elif __APPLE__
    62 #include "TargetConditionals.h"
    63 #include <string.h>
    64 #if TARGET_OS_IPHONE
    65 
    66 extern char* SystemDB;
    67 #define SYSTEM_DB SystemDB
    68     
    69 #endif
    70 #endif
    71 
    72 #if !defined(BSD) && !defined(__APPLE__)
    73 size_t strlcpy(char* dst, const	char* src, size_t size);
    74 size_t strlcat(char* dst, const	char* src, size_t size);
    75 
    76 // N.B. This is ifdef'd out because NDK users sometimes have trouble finding regex functions in
    77 //      the library in spite of the inclusion of regex.h - this is a FIXME, but since iOS is
    78 //      *currently* the only netpgp user, we will ifdef this so that we don't block Android.
    79 #ifdef USE_NETPGP
    80 int regnexec(const regex_t* preg, const char* string,
    81              size_t len, size_t nmatch, regmatch_t pmatch[], int eflags);
    82 #endif
    83 
    84 #endif
    85 
    86 #ifndef _UUID_STRING_T
    87 #define _UUID_STRING_T
    88 typedef char uuid_string_t[37];
    89 #endif
    90 #ifdef UUID
    91 #undef UUID
    92 #endif
    93 // on *nix, uuid_t is an array and already implements pointer semantics
    94 #define UUID uuid_t
    95 
    96 #ifdef ANDROID
    97 typedef char pEpUUID[16];
    98 void uuid_generate_random(pEpUUID out);
    99 void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
   100 #else
   101 typedef uuid_t pEpUUID;
   102 #endif
   103 
   104 #ifdef __cplusplus
   105 }
   106 #endif