libs/libc/builtin/: builtint_isavail() should not set the errno variable because this functions may be used by internal OS logic for which setting the rrno variable would be inappropriate.

This commit is contained in:
Gregory Nutt 2019-09-11 12:37:29 -06:00
parent d8adf712a2
commit 254a906409
7 changed files with 61 additions and 23 deletions

1
TODO
View File

@ -286,6 +286,7 @@ o Task/Scheduler (sched/)
open() used within the OS. There are places under libs/ and
boards/ that have not been converted. I also note cases
where fopen() is called under libs/libc/netdb/.
2019-09-11: built_isavail() no longer sets the errno varaible.
Status: Open
Priority: Low. Things are working OK the way they are. But the design

View File

@ -123,11 +123,9 @@ static int builtin_loadbinary(struct binary_s *binp)
index = builtin_isavail(filename);
if (index < 0)
{
int errval = get_errno();
berr("ERROR: %s is not a builtin application\n", filename);
close(fd);
return -errval;
return index;
}
/* Return the load information. NOTE: that there is no way to configure

View File

@ -131,9 +131,9 @@ EXTERN const int g_builtin_count;
*
* Input Parameters:
* builtins - The list of built-in functions. Each entry is a name-value
* pair that maps a builtin function name to its user-space
* pair that maps a built-in function name to its user-space
* entry point address.
* count - The number of name-value pairs in the builtin list.
* count - The number of name-value pairs in the built-in list.
*
* Returned Value:
* None
@ -149,15 +149,18 @@ void builtin_setlist(FAR const struct builtin_s *builtins, int count);
* Name: builtin_isavail
*
* Description:
* Checks for availability of application registered during compile time.
* Checks for availability of an application named 'appname' registered
* during compile time and, if available, returns the index into the table
* of built-in applications.
*
* Input Parameters:
* filename - Name of the linked-in binary to be started.
*
* Returned Value:
* This is an end-user function, so it follows the normal convention:
* Returns index of builtin application. If it is not found then it
* returns -1 (ERROR) and sets errno appropriately.
* This is an internal function, used by by the NuttX binfmt logic and
* by the application built-in logic. It returns a non-negative index to
* the application entry in the table of built-in applications on success
* or a negated errno value in the event of a failure.
*
****************************************************************************/
@ -185,9 +188,10 @@ FAR const char *builtin_getname(int index);
* Name: builtin_for_index
*
* Description:
* Returns the builtin_s structure for the selected builtin.
* If support for builtin functions is enabled in the NuttX configuration,
* then this function must be provided by the application code.
* Returns the builtin_s structure for the selected built-in.
* If support for built-in functions is enabled in the NuttX
* configuration, then this function must be provided by the application
* code.
*
* Input Parameters:
* index, from 0 and on...

View File

@ -49,6 +49,25 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_for_index
*
* Description:
* Returns the builtin_s structure for the selected built-in.
* If support for built-in functions is enabled in the NuttX
* configuration, then this function must be provided by the application
* code.
*
* Input Parameters:
* index, from 0 and on...
*
* Returned Value:
* Returns valid pointer pointing to the builtin_s structure if index is
* valid.
* Otherwise, NULL is returned.
*
****************************************************************************/
FAR const struct builtin_s *builtin_for_index(int index)
{
if (index < g_builtin_count)

View File

@ -58,8 +58,15 @@
* Name: builtin_getname
*
* Description:
* Return the name of the application at index in the table of builtin
* applications.
* Returns pointer the a name of the application at 'index' in the table
* of built-in applications.
*
* Input Parameters:
* index - From 0 and on ...
*
* Returned Value:
* Returns valid pointer pointing to the app name if index is valid.
* Otherwise NULL is returned.
*
****************************************************************************/

View File

@ -8,7 +8,7 @@
*
* With subsequent updates, modifications, and general maintenance by:
*
* Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2012-2013, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -62,8 +62,18 @@
* Name: builtin_isavail
*
* Description:
* Return the index into the table of applications for the application with
* the name 'appname'.
* Checks for availability of an application named 'appname' registered
* during compile time and, if available, returns the index into the table
* of built-in applications.
*
* Input Parameters:
* filename - Name of the linked-in binary to be started.
*
* Returned Value:
* This is an internal function, used by by the NuttX binfmt logic and
* by the application built-in logic. It returns a non-negative index to
* the application entry in the table of built-in applications on success
* or a negated errno value in the event of a failure.
*
****************************************************************************/
@ -72,16 +82,15 @@ int builtin_isavail(FAR const char *appname)
FAR const char *name;
int i;
for (i = 0; (name = builtin_getname(i)); i++)
for (i = 0; (name = builtin_getname(i)) != NULL; i++)
{
if (!strncmp(name, appname, NAME_MAX))
if (strncmp(name, appname, NAME_MAX) == 0)
{
return i;
}
}
set_errno(ENOENT);
return ERROR;
return -ENOENT;
}
#endif /* HAVE_BUILTIN_CONTEXT */

View File

@ -78,9 +78,9 @@ int g_builtin_count;
*
* Input Parameters:
* builtins - The list of built-in functions. Each entry is a name-value
* pair that maps a builtin function name to its user-space
* pair that maps a built-in function name to its user-space
* entry point address.
* count - The number of name-value pairs in the builtin list.
* count - The number of name-value pairs in the built-in list.
*
* Returned Value:
* None