【修改】保留原ef_set_env()中value == NULL的删除条件

Signed-off-by: outely <834843362@qq.com>
pull/24/head
outely 8 years ago
parent 93fb6dd777
commit 988a11325c

@ -52,11 +52,11 @@ char *ef_get_env(const char *key)
#### 1.2.4 设置环境变量
使用此方法可以实现对环境变量的增加、修改功能。(注意:此处的环境变量指代的已加载到内存中的环境变量)
使用此方法可以实现对环境变量的增加、修改及删除功能。(注意:此处的环境变量指代的已加载到内存中的环境变量)
- **增加** :当环境变量表中不存在该名称的环境变量时,则会执行新增操作;
- **修改** :入参中的环境变量名称在当前环境变量表中存在,则把该环境变量值修改为入参中的值;
- **删除**当入参中的value为NULL时则会删除入参名对应的环境变量。
```C

@ -478,7 +478,7 @@ static EfErrCode del_env(const char *key) {
}
/**
* Set an ENV.
* Set an ENV.If it value is NULL, delete it.
* If not find it in ENV table, then create it.
*
* @param key ENV name
@ -498,22 +498,28 @@ EfErrCode ef_set_env(const char *key, const char *value) {
/* lock the ENV cache */
ef_port_env_lock();
old_env = find_env(key);
/* If find this ENV, then compare the new value and old value. */
if (old_env) {
/* find the old value address */
old_env = strchr(old_env, '=');
old_value = old_env + 1;
/* If it is changed then delete it and recreate it */
if (strcmp(old_value, value)) {
result = del_env(key);
if (result == EF_NO_ERR) {
result = create_env(key, value);
/* if ENV value is NULL, delete it */
if (value == NULL) {
result = del_env(key);
} else {
old_env = find_env(key);
/* If find this ENV, then compare the new value and old value. */
if (old_env) {
/* find the old value address */
old_env = strchr(old_env, '=');
old_value = old_env + 1;
/* If it is changed then delete it and recreate it */
if (strcmp(old_value, value)) {
result = del_env(key);
if (result == EF_NO_ERR) {
result = create_env(key, value);
}
}
} else {
result = create_env(key, value);
}
} else {
result = create_env(key, value);
}
/* unlock the ENV cache */
ef_port_env_unlock();

@ -494,7 +494,7 @@ static EfErrCode del_env(const char *key) {
}
/**
* Set an ENV.
* Set an ENV.If it value is NULL, delete it.
* If not find it in ENV table, then create it.
*
* @param key ENV name
@ -514,21 +514,26 @@ EfErrCode ef_set_env(const char *key, const char *value) {
/* lock the ENV cache */
ef_port_env_lock();
old_env = find_env(key);
/* If find this ENV, then compare the new value and old value. */
if (old_env) {
/* find the old value address */
old_env = strchr(old_env, '=');
old_value = old_env + 1;
/* If it is changed then delete it and recreate it */
if (strcmp(old_value, value)) {
result = del_env(key);
if (result == EF_NO_ERR) {
result = create_env(key, value);
/* if ENV value is NULL, delete it */
if (value == NULL) {
result = del_env(key);
} else {
old_env = find_env(key);
/* If find this ENV, then compare the new value and old value. */
if (old_env) {
/* find the old value address */
old_env = strchr(old_env, '=');
old_value = old_env + 1;
/* If it is changed then delete it and recreate it */
if (strcmp(old_value, value)) {
result = del_env(key);
if (result == EF_NO_ERR) {
result = create_env(key, value);
}
}
} else {
result = create_env(key, value);
}
} else {
result = create_env(key, value);
}
/* unlock the ENV cache */
ef_port_env_unlock();

Loading…
Cancel
Save