2007-06-30 21:39:17 +02:00
|
|
|
/****************************************************************************
|
2014-08-08 21:53:29 +02:00
|
|
|
* sched/environ/env_findvar.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
|
|
|
|
|
2009-12-14 22:15:18 +01:00
|
|
|
#include <stdbool.h>
|
2007-06-30 21:39:17 +02:00
|
|
|
#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
|
|
|
|
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
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: env_cmpname
|
2007-06-30 21:39:17 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2009-12-14 22:15:18 +01:00
|
|
|
static bool env_cmpname(const char *pszname, const char *peqname)
|
2007-06-30 21:39:17 +02:00
|
|
|
{
|
|
|
|
/* Search until we find anything different in the two names */
|
|
|
|
|
2018-08-10 18:16:39 +02:00
|
|
|
for (; *pszname == *peqname; pszname++, peqname++)
|
|
|
|
{
|
|
|
|
}
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2018-08-10 18:16:39 +02:00
|
|
|
/* On success, pszname will end with '\0' and peqname with '=' */
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
if (*pszname == '\0' && *peqname == '=')
|
2007-06-30 21:39:17 +02:00
|
|
|
{
|
2009-12-14 22:15:18 +01:00
|
|
|
return true;
|
2007-06-30 21:39:17 +02:00
|
|
|
}
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2009-12-14 22:15:18 +01:00
|
|
|
return false;
|
2007-06-30 21:39:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-07-14 21:30:31 +02:00
|
|
|
* Name: env_findvar
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Search the provided environment structure for the variable of the
|
|
|
|
* specified name.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-08-10 18:16:39 +02:00
|
|
|
* group - The task group containing environment array to be searched.
|
|
|
|
* pname - The variable name to find
|
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
|
|
|
* A index to the name=value string in the environment
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* - Not called from an interrupt handler
|
2018-08-10 18:16:39 +02:00
|
|
|
* - Pre-emption is disabled by caller
|
2007-06-30 21:39:17 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-02-09 07:59:03 +01:00
|
|
|
ssize_t env_findvar(FAR struct task_group_s *group, FAR const char *pname)
|
2007-06-30 21:39:17 +02:00
|
|
|
{
|
2023-02-09 07:59:03 +01:00
|
|
|
ssize_t i;
|
2007-06-30 21:39:17 +02:00
|
|
|
|
|
|
|
/* Verify input parameters */
|
|
|
|
|
2018-08-10 18:16:39 +02:00
|
|
|
DEBUGASSERT(group != NULL && pname != NULL);
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
if (group->tg_envp == NULL)
|
|
|
|
{
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
/* Search for a name=value string with matching name */
|
2007-06-30 21:39:17 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
for (i = 0; group->tg_envp[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
if (env_cmpname(pname, group->tg_envp[i]))
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2022-04-16 13:38:17 +02:00
|
|
|
return -ENOENT;
|
2007-06-30 21:39:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_DISABLE_ENVIRON */
|