diff --git a/ChangeLog b/ChangeLog
index 46ed65e940..9e2b426029 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -810,8 +810,9 @@
typical embeddd system.
* sched/: Added gettimeofday(). This implementation is simply a thin
wrapper around clock_gettimer().
- * lib/: Add gmtime() and localtime()
-
-
-
+ * lib/: Add gmtime(), localtime(), and strftime()
+ * binfmt/: Add exec(). This is just a wrapper that executes both
+ load_ and exec_module() in a more familiar manner. It is not consistent
+ with more standard exec() functions, however, because (1) it returns
+ and (2) it requires symbol table arguments.
diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html
index e91143d811..f1bf734e98 100644
--- a/Documentation/NuttX.html
+++ b/Documentation/NuttX.html
@@ -8,7 +8,7 @@
NuttX RTOS
- Last Updated: July 11, 2009
+ Last Updated: July 12, 2009
|
@@ -1483,7 +1483,11 @@ nuttx-0.4.10 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
typical embeddd system.
* sched/: Added gettimeofday(). This implementation is simply a thin
wrapper around clock_gettimer().
- * lib/: Add gmtime() and localtime()
+ * lib/: Add gmtime(), localtime(), and strftime()
+ * binfmt/: Add exec(). This is just a wrapper that executes both
+ load_ and exec_module() in a more familiar manner. It is not consistent
+ with more standard exec() functions, however, because (1) it returns
+ and (2) it requires symbol table arguments.
nuttx-0.4.10 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
diff --git a/binfmt/Makefile b/binfmt/Makefile
index 0ba0c28622..dd9e459ced 100644
--- a/binfmt/Makefile
+++ b/binfmt/Makefile
@@ -48,11 +48,11 @@ endif
BINFMT_ASRCS =
BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c \
binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c \
- binfmt_dumpmodule.c
+ binfmt_exec.c binfmt_dumpmodule.c
SYMTAB_ASRCS =
SYMTAB_CSRCS = symtab_findbyname.c symtab_findbyvalue.c \
- symtab_findorderedbyname.c symtab_findorderedbyvalue.c
+ symtab_findorderedbyname.c symtab_findorderedbyvalue.c
SUBDIRS = libnxflat
diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c
new file mode 100644
index 0000000000..8a25445c02
--- /dev/null
+++ b/binfmt/binfmt_exec.c
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * binfmt/binfmt_exec.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include
+
+#include "binfmt_internal.h"
+
+#ifndef CONFIG_BINFMT_DISABLE
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: exec
+ *
+ * Description:
+ * This is a convenience function that wraps load_ and exec_module into
+ * one call.
+ *
+ * Input Parameter:
+ * filename - Fulll path to the binary to be loaded
+ * argv - Argument list
+ * exports - Table of exported symbols
+ * nexports - The number of symbols in exports
+ *
+ * Returned Value:
+ * This is an end-user function, so it follows the normal convention:
+ * Returns the PID of the exec'ed module. On failure, it.returns
+ * -1 (ERROR) and sets errno appropriately.
+ *
+ ****************************************************************************/
+
+int exec(FAR const char *filename, FAR const char **argv,
+ FAR const struct symtab_s *exports, int nexports)
+{
+ struct binary_s bin;
+ int ret;
+ int i;
+
+ memset(&bin, 0, sizeof(struct binary_s));
+ bin.filename = filename;
+ bin.exports = exports;
+ bin.nexports = NEXPORTS;
+
+ ret = load_module(&bin);
+ if (ret < 0)
+ {
+ bdbg("ERROR: Failed to load program '%s'\n", dirlist[i]);
+ return ERROR;
+ }
+
+ ret = exec_module(&bin, 50);
+ if (ret < 0)
+ {
+ bdbg("ERROR: Failed to execute program '%s'\n", dirlist[i]);
+ unload_module(&bin);
+ return ERROR;
+ }
+
+ return ret;
+}
+
+#endif /* CONFIG_BINFMT_DISABLE */
+
diff --git a/include/nuttx/binfmt.h b/include/nuttx/binfmt.h
index 3fe0b3a382..7029ca161a 100644
--- a/include/nuttx/binfmt.h
+++ b/include/nuttx/binfmt.h
@@ -85,7 +85,7 @@ struct binfmt_s
};
/****************************************************************************
- * Public Functions
+ * Public Data
****************************************************************************/
#undef EXTERN
@@ -96,6 +96,10 @@ extern "C" {
#define EXTERN extern
#endif
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
/****************************************************************************
* Name: register_binfmt
*
@@ -173,6 +177,29 @@ EXTERN int unload_module(FAR const struct binary_s *bin);
EXTERN int exec_module(FAR const struct binary_s *bin, int priority);
+/****************************************************************************
+ * Name: exec
+ *
+ * Description:
+ * This is a convenience function that wraps load_ and exec_module into
+ * one call.
+ *
+ * Input Parameter:
+ * filename - Fulll path to the binary to be loaded
+ * argv - Argument list
+ * exports - Table of exported symbols
+ * nexports - The number of symbols in exports
+ *
+ * Returned Value:
+ * This is an end-user function, so it follows the normal convention:
+ * Returns the PID of the exec'ed module. On failure, it.returns
+ * -1 (ERROR) and sets errno appropriately.
+ *
+ ****************************************************************************/
+
+EXTERN int exec(FAR const char *filename, FAR const char **argv,
+ FAR const struct symtab_s *exports, int nexports);
+
#undef EXTERN
#if defined(__cplusplus)
}