2007-06-30 21:39:17 +02:00
|
|
|
/****************************************************************************
|
2014-08-08 21:53:29 +02:00
|
|
|
* sched/environ/env_removevar.c
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <sched.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
|
2014-08-08 21:53:29 +02:00
|
|
|
#include "environ/environ.h"
|
2014-01-14 20:30:22 +01:00
|
|
|
|
2007-06-30 21:39:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: env_removevar
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Remove the referenced name=value pair from the environment
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-08-10 18:16:39 +02:00
|
|
|
* group - The task group with the environment containing the name=value
|
|
|
|
* pair
|
2022-04-16 13:38:17 +02:00
|
|
|
* index - A index to the name=value pair in the restroom
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2022-04-16 13:38:17 +02:00
|
|
|
* None
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - Not called from an interrupt handler
|
2018-08-10 18:16:39 +02:00
|
|
|
* - Caller has pre-emption disabled
|
2007-06-30 21:39:17 +02:00
|
|
|
* - Caller will reallocate the environment structure to the correct size
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
void env_removevar(FAR struct task_group_s *group, int index)
|
2007-06-30 21:39:17 +02:00
|
|
|
{
|
2022-04-16 13:38:17 +02:00
|
|
|
DEBUGASSERT(group != NULL && index >= 0);
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
/* Free the allocate environment string */
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
group_free(group, group->tg_envp[index]);
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
/* Move all of the environment strings after the removed one 'down.'
|
|
|
|
* this is inefficient, but robably not high duty.
|
|
|
|
*/
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
do
|
2013-01-26 00:21:27 +01:00
|
|
|
{
|
2022-04-16 13:38:17 +02:00
|
|
|
group->tg_envp[index] = group->tg_envp[index + 1];
|
|
|
|
}
|
|
|
|
while (group->tg_envp[++index] != NULL);
|
2013-01-26 00:21:27 +01:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
/* Free the old environment (if there was one) */
|
2013-01-26 00:21:27 +01:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
if (index == 1)
|
|
|
|
{
|
|
|
|
group_free(group, group->tg_envp);
|
|
|
|
group->tg_envp = NULL;
|
2007-06-30 21:39:17 +02:00
|
|
|
}
|
2022-04-16 13:38:17 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Reallocate the environment to reclaim a little memory */
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
group->tg_envp = group_realloc(group, group->tg_envp,
|
|
|
|
sizeof(*group->tg_envp) * (index + 1));
|
|
|
|
DEBUGASSERT(group->tg_envp != NULL);
|
|
|
|
}
|
2007-06-30 21:39:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_DISABLE_ENVIRON */
|