Skip to content

Commit 94b12a1

Browse files
committed
fix(android): check for __ANDROID__ macro instead of __linux__ macro
1 parent 131d6b6 commit 94b12a1

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/utils.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,11 @@
1616
#include <ntstatus.h> //for STATUS_SUCCESS
1717
#else
1818
#include <unistd.h>
19-
#ifdef __linux__
20-
#include <sys/random.h>
21-
#elif defined (__APPLE__)
19+
#if defined(__APPLE__)
2220
#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>
2923
#endif
30-
31-
#ifndef SQLITE_CORE
32-
SQLITE_EXTENSION_INIT3
3324
#endif
3425

3526
#define FNV_OFFSET_BASIS 0xcbf29ce484222325ULL
@@ -58,17 +49,20 @@ int cloudsync_uuid_v7 (uint8_t value[UUID_LEN]) {
5849
#elif defined(__APPLE__)
5950
// Use SecRandomCopyBytes for macOS/iOS
6051
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__)
6553
//arc4random_buf doesn't have a return value to check for success
6654
arc4random_buf(value, UUID_LEN);
55+
#else
56+
if (getentropy(value, UUID_LEN) != 0) return -1;
6757
#endif
6858

6959
// get current timestamp in ms
7060
struct timespec ts;
61+
#ifdef __ANDROID__
62+
if (clock_gettime(CLOCK_REALTIME, &ts) != 0) return -1;
63+
#else
7164
if (timespec_get(&ts, TIME_UTC) == 0) return -1;
65+
#endif
7266

7367
// add timestamp part to UUID
7468
uint64_t timestamp = (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;

0 commit comments

Comments
 (0)