Added inline function tpl_getenv() to replace getenv. 26/232026/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Mon, 27 Apr 2020 10:07:02 +0000 (19:07 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Mon, 27 Apr 2020 11:30:20 +0000 (20:30 +0900)
Change-Id: I1018d6f7c11bba4aaaee3e29cc53dd1660f70593
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl.c
src/tpl_utils.h

index 2a19d8d..8107b8f 100644 (file)
--- 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 {
index 7f55fec..9e0369f 100644 (file)
@@ -6,6 +6,7 @@
 #include <assert.h>
 #include <pthread.h>
 #include <string.h>
+#include <unistd.h>
 
 #if defined(__GNUC__) && __GNUC__ >= 4
 #   define TPL_API __attribute__ ((visibility("default")))
 /* 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;