diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-02-17 09:14:12 -0800 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-02-17 09:14:12 -0800 |
commit | 520a2b417410bed7db6f08a3a69f3bcccc55910b (patch) | |
tree | 2365774545ed145c307630b63cb5f075fca71c21 /nuttx/sched/env_removevar.c | |
parent | 2745c3276f5c2377a9713555c5941b17912b6ce7 (diff) | |
parent | caa11f0bbb7f30679c5c01a64e1d0f6d8627db9d (diff) | |
download | px4-firmware-520a2b417410bed7db6f08a3a69f3bcccc55910b.tar.gz px4-firmware-520a2b417410bed7db6f08a3a69f3bcccc55910b.tar.bz2 px4-firmware-520a2b417410bed7db6f08a3a69f3bcccc55910b.zip |
Merge pull request #198 from PX4/nuttx-merge-5596
Nuttx merge 5596
Diffstat (limited to 'nuttx/sched/env_removevar.c')
-rw-r--r-- | nuttx/sched/env_removevar.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/nuttx/sched/env_removevar.c b/nuttx/sched/env_removevar.c index e96aa7a37..811e6079e 100644 --- a/nuttx/sched/env_removevar.c +++ b/nuttx/sched/env_removevar.c @@ -59,7 +59,7 @@ * Remove the referenced name=value pair from the environment * * Parameters: - * envp The environment containing the name=value pair + * group The task group with the environment containing the name=value pair * pvar A pointer to the name=value pair in the restroom * * Return Value: @@ -72,42 +72,44 @@ * ****************************************************************************/ -int env_removevar(environ_t *envp, char *pvar) +int env_removevar(FAR struct task_group_s *group, FAR char *pvar) { + FAR char *end; /* Pointer to the end+1 of the environment */ + int alloc; /* Size of the allocated environment */ int ret = ERROR; - if (envp && pvar) - { - /* Verify that the pointer lies within the environment region */ - int alloc = envp->ev_alloc; /* Size of the allocated environment */ - char *end = &envp->ev_env[alloc]; /* Pointer to the end+1 of the environment */ + DEBUGASSERT(group && pvar); - if (pvar >= envp->ev_env && pvar < end) - { - /* Set up for the removal */ + /* Verify that the pointer lies within the environment region */ - int len = strlen(pvar) + 1; /* Length of name=value string to remove */ - char *src = &pvar[len]; /* Address of name=value string after */ - char *dest = pvar; /* Location to move the next string */ - int count = end - src; /* Number of bytes to move (might be zero) */ + alloc = group->tg_envsize; /* Size of the allocated environment */ + end = &group->tg_envp[alloc]; /* Pointer to the end+1 of the environment */ - /* Move all of the environment strings after the removed one 'down.' - * this is inefficient, but robably not high duty. - */ + if (pvar >= group->tg_envp && pvar < end) + { + /* Set up for the removal */ - while (count-- > 0) - { - *dest++ = *src++; - } + int len = strlen(pvar) + 1; /* Length of name=value string to remove */ + char *src = &pvar[len]; /* Address of name=value string after */ + char *dest = pvar; /* Location to move the next string */ + int count = end - src; /* Number of bytes to move (might be zero) */ - /* Then set to the new allocation size. The caller is expected to - * call realloc at some point but we don't do that here because the - * caller may add more stuff to the environment. - */ + /* Move all of the environment strings after the removed one 'down.' + * this is inefficient, but robably not high duty. + */ - envp->ev_alloc -= len; - ret = OK; + while (count-- > 0) + { + *dest++ = *src++; } + + /* Then set to the new allocation size. The caller is expected to + * call realloc at some point but we don't do that here because the + * caller may add more stuff to the environment. + */ + + group->tg_envsize -= len; + ret = OK; } return ret; |