|
31 | 31 | #cmakedefine01 BLADERF_OS_FREEBSD |
32 | 32 | #cmakedefine01 BLADERF_OS_OSX |
33 | 33 | #cmakedefine01 BLADERF_OS_WINDOWS |
| 34 | +#cmakedefine01 BLADERF_OS_ANDROID |
34 | 35 | #cmakedefine01 BLADERF_BIG_ENDIAN |
35 | 36 |
|
36 | | -#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD) |
| 37 | + |
| 38 | +#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD || BLADERF_OS_ANDROID) |
37 | 39 | # error "Build not configured for any supported operating systems" |
38 | 40 | #endif |
39 | 41 |
|
40 | 42 | #if 1 < (BLADERF_OS_LINUX + BLADERF_OS_OSX + BLADERF_OS_WINDOWS + BLADERF_OS_FREEBSD) |
41 | 43 | #error "Build configured for multiple operating systems" |
42 | 44 | #endif |
43 | 45 |
|
| 46 | +#ifdef BLADERF_OS_ANDROID |
| 47 | +#include <unistd.h> |
| 48 | +#include <sys/types.h> |
| 49 | +#include <stdlib.h> |
| 50 | +#include <pwd.h> |
| 51 | + |
| 52 | +static inline struct passwd *bladerf_android_getpwuid_stub(uid_t uid) |
| 53 | +{ |
| 54 | + static struct passwd pwd; |
| 55 | + static char fallback_dir[] = "/"; |
| 56 | + const char *home; |
| 57 | + |
| 58 | + (void)uid; |
| 59 | + |
| 60 | + home = getenv("HOME"); |
| 61 | + pwd.pw_dir = (char *)(home != NULL ? home : fallback_dir); |
| 62 | + |
| 63 | + return &pwd; |
| 64 | +} |
| 65 | + |
| 66 | +#define getpwuid(uid) bladerf_android_getpwuid_stub(uid) |
| 67 | + |
| 68 | +#endif |
| 69 | + |
44 | 70 | #cmakedefine01 HAVE_CLOCK_GETTIME |
45 | 71 |
|
46 | 72 | /******************************************************************************* |
|
61 | 87 | /*----------------------- |
62 | 88 | * Linux |
63 | 89 | *---------------------*/ |
64 | | -#if BLADERF_OS_LINUX |
| 90 | +#if BLADERF_OS_LINUX || BLADERF_OS_ANDROID |
65 | 91 | #include <endian.h> |
66 | 92 |
|
67 | 93 | #define HOST_TO_LE16(val) htole16(val) |
|
153 | 179 | #error "Encountered an OS that we do not have endian wrappers for?" |
154 | 180 | #endif |
155 | 181 |
|
| 182 | +#if BLADERF_OS_ANDROID |
| 183 | +#define usleep(usec) do { \ |
| 184 | + struct timespec ts; \ |
| 185 | + ts.tv_sec = (usec) / 1000000; \ |
| 186 | + ts.tv_nsec = ((usec) % 1000000) * 1000; \ |
| 187 | + nanosleep(&ts, NULL); \ |
| 188 | +} while (0) |
| 189 | +#define pthread_cancel(val) pthread_kill(val, SIGTERM) |
| 190 | +#endif |
| 191 | + |
156 | 192 | /******************************************************************************* |
157 | 193 | * Endianness conversions for constants |
158 | 194 | * |
|
0 commit comments