From 6d059f65bf23f912ec4ebb12022dd3b25b26dd6f Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Fri, 3 Aug 2018 15:56:03 +0800 Subject: [PATCH] [osal]: Change mpp_env string interface Set get environment string parameter to const char to avoid modification. Change-Id: Ib5308407fcac2fa58b194fb8df33380efc1487f9 Signed-off-by: Herman Chen --- osal/android/os_env.c | 2 +- osal/inc/mpp_env.h | 2 +- osal/linux/os_env.c | 2 +- osal/mpp_env.cpp | 2 +- osal/os_env.h | 2 +- osal/test/mpp_env_test.c | 13 ++++++------- osal/windows/os_env.c | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/osal/android/os_env.c b/osal/android/os_env.c index af2bdb13..b06fff6f 100644 --- a/osal/android/os_env.c +++ b/osal/android/os_env.c @@ -45,7 +45,7 @@ RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value) return 0; } -RK_S32 os_get_env_str(const char *name, char **value, char *default_value) +RK_S32 os_get_env_str(const char *name, const char **value, const char *default_value) { // use unsigned char to avoid warnning static unsigned char env_str[2][PROP_VALUE_MAX + 1]; diff --git a/osal/inc/mpp_env.h b/osal/inc/mpp_env.h index 1fe96108..b2fb7338 100644 --- a/osal/inc/mpp_env.h +++ b/osal/inc/mpp_env.h @@ -24,7 +24,7 @@ extern "C" { #endif RK_S32 mpp_env_get_u32(const char *name, RK_U32 *value, RK_U32 default_value); -RK_S32 mpp_env_get_str(const char *name, char **value, char *default_value); +RK_S32 mpp_env_get_str(const char *name, const char **value, const char *default_value); RK_S32 mpp_env_set_u32(const char *name, RK_U32 value); RK_S32 mpp_env_set_str(const char *name, char *value); diff --git a/osal/linux/os_env.c b/osal/linux/os_env.c index afe10d65..96e68d5c 100644 --- a/osal/linux/os_env.c +++ b/osal/linux/os_env.c @@ -40,7 +40,7 @@ RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value) return 0; } -RK_S32 os_get_env_str(const char *name, char **value, char *default_value) +RK_S32 os_get_env_str(const char *name, const char **value, const char *default_value) { *value = getenv(name); if (NULL == *value) { diff --git a/osal/mpp_env.cpp b/osal/mpp_env.cpp index 98d98170..9e4d9d11 100644 --- a/osal/mpp_env.cpp +++ b/osal/mpp_env.cpp @@ -24,7 +24,7 @@ RK_S32 mpp_env_get_u32(const char *name, RK_U32 *value, RK_U32 default_value) return os_get_env_u32(name, value, default_value); } -RK_S32 mpp_env_get_str(const char *name, char **value, char *default_value) +RK_S32 mpp_env_get_str(const char *name, const char **value, const char *default_value) { return os_get_env_str(name, value, default_value); } diff --git a/osal/os_env.h b/osal/os_env.h index 35aeab58..f039c469 100644 --- a/osal/os_env.h +++ b/osal/os_env.h @@ -24,7 +24,7 @@ extern "C" { #endif RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value); -RK_S32 os_get_env_str(const char *name, char **value, char *default_value); +RK_S32 os_get_env_str(const char *name, const char **value, const char *default_value); RK_S32 os_set_env_u32(const char *name, RK_U32 value); RK_S32 os_set_env_str(const char *name, char *value); diff --git a/osal/test/mpp_env_test.c b/osal/test/mpp_env_test.c index f3ce2bc1..29721cfd 100644 --- a/osal/test/mpp_env_test.c +++ b/osal/test/mpp_env_test.c @@ -25,22 +25,21 @@ char env_test_string[] = "just for debug"; int main() { RK_U32 env_debug_u32 = 0x100; - char *env_string_str = env_test_string; + const char *env_str_out = NULL; mpp_env_set_u32(env_debug, env_debug_u32); - mpp_env_set_str(env_string, env_string_str); + mpp_env_set_str(env_string, env_test_string); mpp_log("set env: %s to %u\n", env_debug, env_debug_u32); - mpp_log("set env: %s to %s\n", env_string, env_string_str); + mpp_log("set env: %s to %s\n", env_string, env_test_string); env_debug_u32 = 0; - env_string_str = NULL; - mpp_log("clear local value to zero\n"); + mpp_log("start reading env:\n"); mpp_env_get_u32(env_debug, &env_debug_u32, 0); - mpp_env_get_str(env_string, &env_string_str, NULL); + mpp_env_get_str(env_string, &env_str_out, NULL); mpp_log("get env: %s is %u\n", env_debug, env_debug_u32); - mpp_log("get env: %s is %s\n", env_string, env_string_str); + mpp_log("get env: %s is %s\n", env_string, env_str_out); return 0; } diff --git a/osal/windows/os_env.c b/osal/windows/os_env.c index dfd55467..67c919fa 100644 --- a/osal/windows/os_env.c +++ b/osal/windows/os_env.c @@ -39,7 +39,7 @@ RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value) return 0; } -RK_S32 os_get_env_str(const char *name, char **value, char *default_value) +RK_S32 os_get_env_str(const char *name, const char **value, const char *default_value) { *value = getenv(name); if (NULL == *value) {