lib_builtin_isavail.c 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /****************************************************************************
  2. * libs/libc/builtin/lib_builtin_isavail.c
  3. *
  4. * Originally by:
  5. *
  6. * Copyright (C) 2011 Uros Platise. All rights reserved.
  7. * Author: Uros Platise <uros.platise@isotel.eu>
  8. *
  9. * With subsequent updates, modifications, and general maintenance by:
  10. *
  11. * Copyright (C) 2012-2013, 2019 Gregory Nutt. All rights reserved.
  12. * Author: Gregory Nutt <gnutt@nuttx.org>
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in
  22. * the documentation and/or other materials provided with the
  23. * distribution.
  24. * 3. Neither the name NuttX nor the names of its contributors may be
  25. * used to endorse or promote products derived from this software
  26. * without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  31. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  32. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  33. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  34. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  35. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  36. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  37. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  38. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ****************************************************************************/
  42. /****************************************************************************
  43. * Included Files
  44. ****************************************************************************/
  45. #include <nuttx/config.h>
  46. #include <string.h>
  47. #include <limits.h>
  48. #include <errno.h>
  49. #include <nuttx/lib/builtin.h>
  50. /****************************************************************************
  51. * Public Functions
  52. ****************************************************************************/
  53. /****************************************************************************
  54. * Name: builtin_isavail
  55. *
  56. * Description:
  57. * Checks for availability of an application named 'appname' registered
  58. * during compile time and, if available, returns the index into the table
  59. * of built-in applications.
  60. *
  61. * Input Parameters:
  62. * filename - Name of the linked-in binary to be started.
  63. *
  64. * Returned Value:
  65. * This is an internal function, used by by the NuttX binfmt logic and
  66. * by the application built-in logic. It returns a non-negative index to
  67. * the application entry in the table of built-in applications on success
  68. * or a negated errno value in the event of a failure.
  69. *
  70. ****************************************************************************/
  71. int builtin_isavail(FAR const char *appname)
  72. {
  73. FAR const char *name;
  74. int i;
  75. for (i = 0; (name = builtin_getname(i)) != NULL; i++)
  76. {
  77. if (strncmp(name, appname, NAME_MAX) == 0)
  78. {
  79. return i;
  80. }
  81. }
  82. return -ENOENT;
  83. }