diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-24 18:09:18 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-24 18:09:18 +0200 |
commit | 996cbb5f2bc4a6dc2a9168052efb730ade59f902 (patch) | |
tree | 254a98039d8e0481aa75581f1232fca862c5c035 /app/tools | |
parent | 8028d708cbf7d19f4bb6312eac731ad8c16182f0 (diff) |
tools: support ancient NDKs
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/tools')
-rw-r--r-- | app/tools/CMakeLists.txt | 8 | ||||
-rw-r--r-- | app/tools/ndk-compat/compat.c | 77 | ||||
-rw-r--r-- | app/tools/ndk-compat/compat.h | 16 | ||||
m--------- | app/tools/wireguard | 0 |
4 files changed, 97 insertions, 4 deletions
diff --git a/app/tools/CMakeLists.txt b/app/tools/CMakeLists.txt index 840e9f59..f390163f 100644 --- a/app/tools/CMakeLists.txt +++ b/app/tools/CMakeLists.txt @@ -8,12 +8,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") # Work around https://github.com/android-ndk/ndk/issues/602 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") -add_executable(libwg-quick.so wireguard/src/tools/wg-quick/android.c) -target_compile_options(libwg-quick.so PUBLIC -O3 -std=gnu11 -Wall -pedantic -Wno-missing-field-initializers -DWG_PACKAGE_NAME=\"${ANDROID_PACKAGE_NAME}\") +add_executable(libwg-quick.so wireguard/src/tools/wg-quick/android.c ndk-compat/compat.c) +target_compile_options(libwg-quick.so PUBLIC -O3 -std=gnu11 -Wall -pedantic -Wno-missing-field-initializers -include ${CMAKE_CURRENT_SOURCE_DIR}/ndk-compat/compat.h -DWG_PACKAGE_NAME=\"${ANDROID_PACKAGE_NAME}\") -file(GLOB WG_SOURCES wireguard/src/tools/*.c libmnl/src/*.c) +file(GLOB WG_SOURCES wireguard/src/tools/*.c libmnl/src/*.c ndk-compat/compat.c) add_executable(libwg.so ${WG_SOURCES}) -target_compile_options(libwg.so PUBLIC -idirafter "${CMAKE_CURRENT_SOURCE_DIR}/libmnl/include/" -I "${CMAKE_CURRENT_SOURCE_DIR}/wireguard/src/tools/" -O3 -std=gnu11 -D_GNU_SOURCE -DHAVE_VISIBILITY_HIDDEN -DRUNSTATEDIR=\"/data/data/${ANDROID_PACKAGE_NAME}/cache\" -Wno-pointer-arith -Wno-unused-parameter) +target_compile_options(libwg.so PUBLIC -idirafter "${CMAKE_CURRENT_SOURCE_DIR}/libmnl/include/" -I "${CMAKE_CURRENT_SOURCE_DIR}/wireguard/src/tools/" -O3 -std=gnu11 -D_GNU_SOURCE -include ${CMAKE_CURRENT_SOURCE_DIR}/ndk-compat/compat.h -DHAVE_VISIBILITY_HIDDEN -DRUNSTATEDIR=\"/data/data/${ANDROID_PACKAGE_NAME}/cache\" -Wno-pointer-arith -Wno-unused-parameter) add_custom_target(libwg-go.so WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libwg-go" COMMENT "Building wireguard-go" VERBATIM COMMAND make ANDROID_ARCH_NAME=${ANDROID_ARCH_NAME} diff --git a/app/tools/ndk-compat/compat.c b/app/tools/ndk-compat/compat.c new file mode 100644 index 00000000..ecf653f8 --- /dev/null +++ b/app/tools/ndk-compat/compat.c @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: BSD + * + * Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + * + */ + +#define FILE_IS_EMPTY + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 18 +#undef FILE_IS_EMPTY +#include <stdio.h> +#include <stdlib.h> + +ssize_t getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp) +{ + char *ptr, *eptr; + + if (*buf == NULL || *bufsiz == 0) { + *bufsiz = BUFSIZ; + if ((*buf = malloc(*bufsiz)) == NULL) + return -1; + } + + for (ptr = *buf, eptr = *buf + *bufsiz;;) { + int c = fgetc(fp); + if (c == -1) { + if (feof(fp)) { + ssize_t diff = (ssize_t)(ptr - *buf); + if (diff != 0) { + *ptr = '\0'; + return diff; + } + } + return -1; + } + *ptr++ = c; + if (c == delimiter) { + *ptr = '\0'; + return ptr - *buf; + } + if (ptr + 2 >= eptr) { + char *nbuf; + size_t nbufsiz = *bufsiz * 2; + ssize_t d = ptr - *buf; + if ((nbuf = realloc(*buf, nbufsiz)) == NULL) + return -1; + *buf = nbuf; + *bufsiz = nbufsiz; + eptr = nbuf + nbufsiz; + ptr = nbuf + d; + } + } +} + +ssize_t getline(char **buf, size_t *bufsiz, FILE *fp) +{ + return getdelim(buf, bufsiz, '\n', fp); +} +#endif + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 24 +#undef FILE_IS_EMPTY +#include <string.h> + +char *strchrnul(const char *s, int c) +{ + char *x = strchr(s, c); + if (!x) + return (char *)s + strlen(s); + return x; +} +#endif + +#ifdef FILE_IS_EMPTY +#undef FILE_IS_EMPTY +static char ____x __attribute__((unused)); +#endif diff --git a/app/tools/ndk-compat/compat.h b/app/tools/ndk-compat/compat.h new file mode 100644 index 00000000..91f5e7c9 --- /dev/null +++ b/app/tools/ndk-compat/compat.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: BSD + * + * Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + * + */ + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 18 +#include <stdio.h> +ssize_t getdelim(char **buf, size_t *bufsiz, int delimiter, FILE *fp); +ssize_t getline(char **buf, size_t *bufsiz, FILE *fp); +#endif + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 24 +char *strchrnul(const char *s, int c); +#endif + diff --git a/app/tools/wireguard b/app/tools/wireguard -Subproject be3e2a9134e1833c313e700132018de12fe2839 +Subproject f52f9d045f5a6dceea2bbe70e22405ea07c6296 |