Skip to content

Commit 549c3bf

Browse files
committed
fix(android): random and time
1 parent 196a7ed commit 549c3bf

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/utils.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
#include <ntstatus.h> //for STATUS_SUCCESS
1717
#else
1818
#include <unistd.h>
19-
#if defined(__linux__) || defined(__ANDROID__)
19+
#ifdef __linux__
2020
#include <sys/random.h>
21-
#endif
22-
#if defined(__APPLE__)
21+
#elif defined (__APPLE__)
2322
#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+
}
2428
#endif
2529
#endif
2630

@@ -54,8 +58,12 @@ int cloudsync_uuid_v7 (uint8_t value[UUID_LEN]) {
5458
#elif defined(__APPLE__)
5559
// Use SecRandomCopyBytes for macOS/iOS
5660
if (SecRandomCopyBytes(kSecRandomDefault, UUID_LEN, value) != errSecSuccess) return -1;
57-
#else
61+
#elif defined(__linux__)
5862
if (getentropy(value, UUID_LEN) != 0) return -1;
63+
#else
64+
//Fallback to arc4random_buf for other platforms such as Android
65+
//arc4random_buf doesn't have a return value to check for success
66+
arc4random_buf(value, UUID_LEN);
5967
#endif
6068

6169
// get current timestamp in ms

0 commit comments

Comments
 (0)