|
16 | 16 | #include <ntstatus.h> //for STATUS_SUCCESS |
17 | 17 | #else |
18 | 18 | #include <unistd.h> |
19 | | -#ifdef __linux__ |
20 | | -#include <sys/random.h> |
21 | | -#elif defined (__APPLE__) |
| 19 | +#if defined(__APPLE__) |
22 | 20 | #include <Security/Security.h> |
23 | | -#else //other platforms like Android |
24 | | -int timespec_get(struct timespec *ts, int base) { |
25 | | - if (base != TIME_UTC) return 0; |
26 | | - return clock_gettime(CLOCK_REALTIME, ts) == 0 ? base : 0; |
27 | | -} |
28 | | -#endif |
| 21 | +#elif !defined(__ANDROID__) |
| 22 | +#include <sys/random.h> |
29 | 23 | #endif |
30 | | - |
31 | | -#ifndef SQLITE_CORE |
32 | | -SQLITE_EXTENSION_INIT3 |
33 | 24 | #endif |
34 | 25 |
|
35 | 26 | #define FNV_OFFSET_BASIS 0xcbf29ce484222325ULL |
@@ -58,17 +49,20 @@ int cloudsync_uuid_v7 (uint8_t value[UUID_LEN]) { |
58 | 49 | #elif defined(__APPLE__) |
59 | 50 | // Use SecRandomCopyBytes for macOS/iOS |
60 | 51 | if (SecRandomCopyBytes(kSecRandomDefault, UUID_LEN, value) != errSecSuccess) return -1; |
61 | | - #elif defined(__linux__) |
62 | | - if (getentropy(value, UUID_LEN) != 0) return -1; |
63 | | - #else |
64 | | - //Fallback to arc4random_buf for other platforms such as Android |
| 52 | + #elif defined(__ANDROID__) |
65 | 53 | //arc4random_buf doesn't have a return value to check for success |
66 | 54 | arc4random_buf(value, UUID_LEN); |
| 55 | + #else |
| 56 | + if (getentropy(value, UUID_LEN) != 0) return -1; |
67 | 57 | #endif |
68 | 58 |
|
69 | 59 | // get current timestamp in ms |
70 | 60 | struct timespec ts; |
| 61 | + #ifdef __ANDROID__ |
| 62 | + if (clock_gettime(CLOCK_REALTIME, &ts) != 0) return -1; |
| 63 | + #else |
71 | 64 | if (timespec_get(&ts, TIME_UTC) == 0) return -1; |
| 65 | + #endif |
72 | 66 |
|
73 | 67 | // add timestamp part to UUID |
74 | 68 | uint64_t timestamp = (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000; |
|
0 commit comments