From 544f32c939a2ea99d7a33a96582cfa58ff5ff8d3 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 27 Apr 2020 19:07:02 +0900 Subject: [PATCH] Added inline function tpl_getenv() to replace getenv. Change-Id: I1018d6f7c11bba4aaaee3e29cc53dd1660f70593 Signed-off-by: Joonbum Ko --- src/tpl.c | 2 ++ src/tpl_utils.h | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/tpl.c b/src/tpl.c index 2a19d8d..8107b8f 100644 --- a/src/tpl.c +++ b/src/tpl.c @@ -2,6 +2,8 @@ unsigned int tpl_log_lvl = 0; unsigned int tpl_log_initialized = 0; +unsigned int tpl_getenv_initialized = 0; +unsigned int tpl_getenv_enabled = 0; unsigned int tpl_dump_lvl = 0; struct _tpl_runtime { diff --git a/src/tpl_utils.h b/src/tpl_utils.h index 7f55fec..9e0369f 100644 --- a/src/tpl_utils.h +++ b/src/tpl_utils.h @@ -6,6 +6,7 @@ #include #include #include +#include #if defined(__GNUC__) && __GNUC__ >= 4 # define TPL_API __attribute__ ((visibility("default"))) @@ -53,8 +54,33 @@ /* 0:uninitialized, 1:initialized,no log, 2:user log */ extern unsigned int tpl_log_lvl; extern unsigned int tpl_log_initialized; +extern unsigned int tpl_getenv_initialized; +extern unsigned int tpl_getenv_enabled; extern unsigned int tpl_dump_lvl; +#define TPL_GETENV_INIT() \ + { \ + if (!tpl_getenv_initialized) \ + { \ + int ret = access("/opt/usr/tpl_env", F_OK); \ + if (ret == 0) \ + tpl_getenv_enabled = 1; \ + else \ + tpl_getenv_enabled = 0; \ + tpl_getenv_initialized = 1; \ + } \ + } + +inline char *tpl_getenv(const char *name) +{ + TPL_GETENV_INIT(); + if (tpl_getenv_enabled) + return getenv(name); + else + return NULL; +} + + #define FONT_DEFAULT "\033[0m" /* for reset to default color */ #define FONT_RED "\033[31m" /* for error logs */ #define FONT_YELLOW "\033[33m" /* for warning logs */ @@ -289,7 +315,6 @@ extern unsigned int tpl_dump_lvl; } #endif - typedef struct _tpl_list_node tpl_list_node_t; typedef struct _tpl_list tpl_list_t; typedef struct tpl_util_map_entry tpl_util_map_entry_t; -- 2.7.4