From b1c47a347c37fedfefc70eb156edb1ce6886c67e Mon Sep 17 00:00:00 2001 From: yaomanhai Date: Wed, 23 Feb 2022 07:34:11 +0000 Subject: [PATCH] Make some functions visibility hidden Signed-off-by: yaomanhai --- frameworks/native/hilog_base.cpp | 46 +++++------------------- frameworks/native/include/hilog_common.h | 7 ++++ frameworks/native/output_p.inl | 2 +- frameworks/native/vsnprintf_s_p.cpp | 2 +- frameworks/native/vsnprintf_s_p.h | 2 +- 5 files changed, 18 insertions(+), 41 deletions(-) diff --git a/frameworks/native/hilog_base.cpp b/frameworks/native/hilog_base.cpp index dc6e785..ef2e9d1 100644 --- a/frameworks/native/hilog_base.cpp +++ b/frameworks/native/hilog_base.cpp @@ -22,38 +22,17 @@ #include #include #include -#include #include #include #include #include #include -#ifdef DEBUG -static const int MAX_PATH_LEN = 1024; - -static size_t GetExecutablePath(char *processdir, char *processname, size_t len) -{ - char* path_end = nullptr; - if (readlink("/proc/self/exe", processdir, len) <= 0) - return -1; - path_end = strrchr(processdir, '/'); - if (path_end == NULL) - return -1; - ++path_end; - if (strncpy_s(processname, MAX_PATH_LEN, path_end, MAX_PATH_LEN - 1)) { - return 0; - } - *path_end = '\0'; - return (size_t)(path_end - processdir); -} -#endif - namespace { -constexpr int SOCKET_TYPE = SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC; -constexpr int INVALID_SOCKET = -1; -constexpr sockaddr_un SOCKET_ADDR = {AF_UNIX, SOCKET_FILE_DIR INPUT_SOCKET_NAME}; +static constexpr int SOCKET_TYPE = SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC; +static constexpr int INVALID_SOCKET = -1; +static constexpr sockaddr_un SOCKET_ADDR = {AF_UNIX, SOCKET_FILE_DIR INPUT_SOCKET_NAME}; struct SocketHandler { std::atomic_int socketFd {INVALID_SOCKET}; @@ -67,7 +46,7 @@ struct SocketHandler { } }; -int GenerateFD() +static int GenerateFD() { int tmpFd = TEMP_FAILURE_RETRY(socket(AF_UNIX, SOCKET_TYPE, 0)); int res = tmpFd; @@ -78,7 +57,7 @@ int GenerateFD() return res; } -int CheckSocket(SocketHandler& socketHandler) +static int CheckSocket(SocketHandler& socketHandler) { int currentFd = socketHandler.socketFd.load(); if (currentFd >= 0) { @@ -99,7 +78,7 @@ int CheckSocket(SocketHandler& socketHandler) return fd; } -int CheckConnection(SocketHandler& socketHandler) +static int CheckConnection(SocketHandler& socketHandler) { bool isConnected = socketHandler.isConnected.load(); if (isConnected) { @@ -121,7 +100,7 @@ int CheckConnection(SocketHandler& socketHandler) return 0; } -int SendMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen) +static int SendMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, int fmtLen) { SocketHandler socketHandler; int ret = CheckSocket(socketHandler); @@ -151,18 +130,9 @@ int SendMessage(HilogMsg *header, const char *tag, int tagLen, const char *fmt, return ret; } -int HiLogBasePrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, +static int HiLogBasePrintArgs(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, const char *fmt, va_list ap) { -#ifdef DEBUG - char dir[MAX_PATH_LEN] = {0}; - char name[MAX_PATH_LEN] = {0}; - (void)GetExecutablePath(dir, name, MAX_PATH_LEN); - if (strcmp(name, "hilog_test") != 0) { - return -1; - } -#endif - if (!HiLogBaseIsLoggable(domain, tag, level)) { return -1; } diff --git a/frameworks/native/include/hilog_common.h b/frameworks/native/include/hilog_common.h index 7381915..74c722c 100644 --- a/frameworks/native/include/hilog_common.h +++ b/frameworks/native/include/hilog_common.h @@ -98,6 +98,13 @@ using OptCRef = std::optional>; #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) +#ifdef __GNUC__ >= 4 + #define HILOG_PUBLIC_API __attribute__((visibility ("default"))) + #define HILOG_LOCAL_API __attribute__((visibility("hidden"))) +#else + #error "!!! HiLog requires gcc version >= 4.0 !!!" +#endif + /* * ******************************************** * Error codes list diff --git a/frameworks/native/output_p.inl b/frameworks/native/output_p.inl index 3ecf34d..816b1b9 100755 --- a/frameworks/native/output_p.inl +++ b/frameworks/native/output_p.inl @@ -400,7 +400,7 @@ static int SecDecodeTypeS(SecFormatAttr *attr, char *argPtr, SecFormatBuf *forma return textLen; } -int SecOutputPS(SecPrintfStream *stream, int priv, const char *cformat, va_list arglist) +HILOG_LOCAL_API int SecOutputPS(SecPrintfStream *stream, int priv, const char *cformat, va_list arglist) { const SecChar *format = cformat; diff --git a/frameworks/native/vsnprintf_s_p.cpp b/frameworks/native/vsnprintf_s_p.cpp index d207714..cf059a0 100644 --- a/frameworks/native/vsnprintf_s_p.cpp +++ b/frameworks/native/vsnprintf_s_p.cpp @@ -214,7 +214,7 @@ static inline int SecVsnprintfPImpl(char *string, size_t count, int priv, const * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid ******************************************************************************* */ -int vsnprintfp_s(char *strDest, size_t destMax, size_t count, int priv, const char *format, va_list arglist) +HILOG_LOCAL_API int vsnprintfp_s(char *strDest, size_t destMax, size_t count, int priv, const char *format, va_list arglist) { int retVal; diff --git a/frameworks/native/vsnprintf_s_p.h b/frameworks/native/vsnprintf_s_p.h index 5820a0a..dd5373e 100644 --- a/frameworks/native/vsnprintf_s_p.h +++ b/frameworks/native/vsnprintf_s_p.h @@ -31,6 +31,6 @@ * @return:return the number of characters printed(not including the terminating null byte ('\0')), * If an error occurred return -1.Pay special attention to returning -1 when truncation occurs */ -int vsnprintfp_s(char *strDest, size_t destMax, size_t count, int priv, const char *format, va_list arglist); +HILOG_LOCAL_API int vsnprintfp_s(char *strDest, size_t destMax, size_t count, int priv, const char *format, va_list arglist); #endif /* __VSNPRINTFP_S_H__ */ -- Gitee