From f732a89f74fc81f031fbd2d975a7bc35cf1ba343 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 17 Feb 2024 01:13:49 +0800 Subject: [PATCH] Fix compile with musl --- adb/Makefile | 2 +- adb/diagnose_usb.cpp | 4 ++++ base/file.cpp | 6 ++++++ base/logging.cpp | 6 +++--- include/cutils/android_reboot.h | 8 ++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/adb/Makefile b/adb/Makefile index a08b51f1b..8e363cfd2 100644 --- a/adb/Makefile +++ b/adb/Makefile @@ -70,7 +70,7 @@ LOCAL_STATIC_LIBRARIES := libcutils libc ################################ OBJS = $(LOCAL_SRC_FILES:.cpp=.o) $(LOCAL_SRC_C_FILES:.c=.o) -CXXFLAGS = $(OPT_CXXFLAGS) -std=c++14 $(LOCAL_CFLAGS) $(LOCAL_INCLUDES) +CXXFLAGS = $(OPT_CXXFLAGS) -std=gnu++14 $(LOCAL_CFLAGS) $(LOCAL_INCLUDES) CFLAGS= $(OPT_CFLAGS) $(LOCAL_CFLAGS) $(LOCAL_INCLUDES) %.o: %.cpp diff --git a/adb/diagnose_usb.cpp b/adb/diagnose_usb.cpp index 0f067b0ec..b190769b9 100644 --- a/adb/diagnose_usb.cpp +++ b/adb/diagnose_usb.cpp @@ -29,6 +29,10 @@ static const char kPermissionsHelpUrl[] = "http://developer.android.com/tools/device.html"; +__attribute__((weak)) int group_member(gid_t gid) { + return 0; +} + // Returns a message describing any potential problems we find with udev, or nullptr if we can't // find plugdev information (i.e. udev is not installed). static const char* GetUdevProblem() { diff --git a/base/file.cpp b/base/file.cpp index ed994b38b..a90137e1c 100644 --- a/base/file.cpp +++ b/base/file.cpp @@ -29,6 +29,12 @@ #define LOG_TAG "base.file" #include "cutils/log.h" #include "utils/Compat.h" +#include + +/* speciaally for musl c */ +#ifndef DEFFILEMODE +# define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/ +#endif namespace android { namespace base { diff --git a/base/logging.cpp b/base/logging.cpp index 8854f199d..b64fa9c7d 100644 --- a/base/logging.cpp +++ b/base/logging.cpp @@ -93,11 +93,11 @@ namespace { using std::mutex; using std::lock_guard; -#if defined(__GLIBC__) -const char* getprogname() { +//#if defined(__GLIBC__) +const char* __attribute__((weak)) getprogname() { return program_invocation_short_name; } -#endif +//#endif #else const char* getprogname() { diff --git a/include/cutils/android_reboot.h b/include/cutils/android_reboot.h index a3861a02d..26f934486 100644 --- a/include/cutils/android_reboot.h +++ b/include/cutils/android_reboot.h @@ -19,6 +19,14 @@ #include +#if defined(__cplusplus) + #define __BEGIN_DECLS extern "C" { + #define __END_DECLS } + #else + #define __BEGIN_DECLS + #define __END_DECLS +#endif + __BEGIN_DECLS /* Commands */