From 254a906409d6b224b134b67b2ad9c9942ccc8a7a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 11 Sep 2019 12:37:29 -0600 Subject: [PATCH] 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. --- TODO | 1 + binfmt/builtin.c | 4 +--- include/nuttx/lib/builtin.h | 22 +++++++++++++--------- libs/libc/builtin/lib_builtin_forindex.c | 19 +++++++++++++++++++ libs/libc/builtin/lib_builtin_getname.c | 11 +++++++++-- libs/libc/builtin/lib_builtin_isavail.c | 23 ++++++++++++++++------- libs/libc/builtin/lib_builtin_setlist.c | 4 ++-- 7 files changed, 61 insertions(+), 23 deletions(-) diff --git a/TODO b/TODO index 7fa8af1b59..289faee022 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/binfmt/builtin.c b/binfmt/builtin.c index 52eaf534bc..f32145736f 100644 --- a/binfmt/builtin.c +++ b/binfmt/builtin.c @@ -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 diff --git a/include/nuttx/lib/builtin.h b/include/nuttx/lib/builtin.h index 1c516b1d0c..8e853d5e8a 100644 --- a/include/nuttx/lib/builtin.h +++ b/include/nuttx/lib/builtin.h @@ -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... diff --git a/libs/libc/builtin/lib_builtin_forindex.c b/libs/libc/builtin/lib_builtin_forindex.c index 80409ca903..e8f14718d8 100644 --- a/libs/libc/builtin/lib_builtin_forindex.c +++ b/libs/libc/builtin/lib_builtin_forindex.c @@ -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) diff --git a/libs/libc/builtin/lib_builtin_getname.c b/libs/libc/builtin/lib_builtin_getname.c index 5b10ca1e98..56278561e9 100644 --- a/libs/libc/builtin/lib_builtin_getname.c +++ b/libs/libc/builtin/lib_builtin_getname.c @@ -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. * ****************************************************************************/ diff --git a/libs/libc/builtin/lib_builtin_isavail.c b/libs/libc/builtin/lib_builtin_isavail.c index 29c4ae065a..3a99fe04f9 100644 --- a/libs/libc/builtin/lib_builtin_isavail.c +++ b/libs/libc/builtin/lib_builtin_isavail.c @@ -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 * * 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 */ diff --git a/libs/libc/builtin/lib_builtin_setlist.c b/libs/libc/builtin/lib_builtin_setlist.c index 63577650be..776b8780b4 100644 --- a/libs/libc/builtin/lib_builtin_setlist.c +++ b/libs/libc/builtin/lib_builtin_setlist.c @@ -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