src/platform_unix.h
author Volker Birk <vb@pep-project.org>
Thu, 28 May 2020 11:48:42 +0200
changeset 4716 f8a5313261e6
parent 4639 09116d12e937
permissions -rw-r--r--
making it an extra test for ENGINE-755
     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 // pEp files and directories
    20 
    21 #ifndef PER_USER_DIRECTORY
    22 #define PER_USER_DIRECTORY ".pEp"
    23 #endif
    24 
    25 #ifndef PER_MACHINE_DIRECTORY
    26 #if defined(__APPLE__) && !defined(TARGET_OS_IPHONE)
    27 #define PER_MACHINE_DIRECTORY "/Library/Application Support/pEp"
    28 #else
    29 #define PER_MACHINE_DIRECTORY "/usr/local/share/pEp"
    30 #endif
    31 #endif
    32 
    33 
    34 #ifdef __cplusplus
    35 extern "C" {
    36 #endif
    37 
    38 #ifdef NDEBUG
    39 const char *unix_local_db(void);
    40 #else
    41 const char *unix_local_db(int reset);
    42 #endif
    43 const char *unix_system_db(void);
    44 
    45 
    46 #ifdef ANDROID
    47 
    48 time_t timegm(struct tm* const t);
    49 
    50 char *stpncpy(char *, const char *, size_t);
    51 char *stpcpy(char *, const char *);
    52 
    53 // Beware: predictable pseudo random with static seed!
    54 // Only the lowest 31 bits are filled randomly.
    55 //long int random(void);
    56 
    57 const char *android_system_db(void);
    58 #define SYSTEM_DB android_system_db()
    59 
    60 #elif __APPLE__
    61 #include "TargetConditionals.h"
    62 #include <string.h>
    63 #if TARGET_OS_IPHONE //read as `if iOS`
    64     extern char* perMachineDirectory;
    65 #define PER_MACHINE_DIRECTORY perMachineDirectory
    66     // It has been decided not to define PER_USER_DIRECTORY for iOS but HOME (which is defined by
    67     // the OS), at least temporarely.
    68 #endif
    69 #endif
    70 
    71 #if !defined(BSD) && !defined(__APPLE__)
    72 size_t strlcpy(char* dst, const	char* src, size_t size);
    73 size_t strlcat(char* dst, const	char* src, size_t size);
    74 char *strnstr(const char *big, const char *little, size_t len);
    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