diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-09-20 07:57:01 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-11-13 13:22:36 +0100 |
commit | afaeccc05a556f6aa25ba044a7e49d6aa634a59e (patch) | |
tree | 09021686e43641fe7f2ec89996a808a5ca3f06e4 /freebsd/sbin/nvmecontrol/comnd.c | |
parent | NVMECONTROL(8): Add to build (diff) | |
download | rtems-libbsd-afaeccc05a556f6aa25ba044a7e49d6aa634a59e.tar.bz2 |
NVMECONTROL(8): Port to RTEMS
Update #3821.
Diffstat (limited to 'freebsd/sbin/nvmecontrol/comnd.c')
-rw-r--r-- | freebsd/sbin/nvmecontrol/comnd.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/freebsd/sbin/nvmecontrol/comnd.c b/freebsd/sbin/nvmecontrol/comnd.c index 3074cfb9..a4fa686f 100644 --- a/freebsd/sbin/nvmecontrol/comnd.c +++ b/freebsd/sbin/nvmecontrol/comnd.c @@ -27,6 +27,11 @@ * SUCH DAMAGE. */ +#ifdef __rtems__ +#define __need_getopt_newlib +#include <getopt.h> +#include <machine/rtems-bsd-program.h> +#endif /* __rtems__ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -182,6 +187,16 @@ arg_parse(int argc, char * const * argv, const struct cmd *f) char *shortopts, *p; const struct opts *opts = f->opts; const struct args *args = f->args; +#ifdef __rtems__ + struct getopt_data getopt_data; + memset(&getopt_data, 0, sizeof(getopt_data)); +#define optind getopt_data.optind +#define optarg getopt_data.optarg +#define opterr getopt_data.opterr +#define optopt getopt_data.optopt +#define getopt_long(argc, argv, shortopts, longopts, longind) \ + getopt_long_r(argc, argv, shortopts, longopts, longind, &getopt_data) +#endif /* __rtems__ */ if (opts == NULL) n = 0; @@ -191,9 +206,16 @@ arg_parse(int argc, char * const * argv, const struct cmd *f) lopts = malloc((n + 2) * sizeof(struct option)); if (lopts == NULL) err(1, "option memory"); - p = shortopts = malloc((n + 3) * sizeof(char)); +#ifndef __rtems__ + p = shortopts = malloc((2 * n + 2) * sizeof(char)); +#else /* __rtems__ */ + p = shortopts = malloc((2 * n + 3) * sizeof(char)); +#endif /* __rtems__ */ if (shortopts == NULL) err(1, "shortopts memory"); +#ifdef __rtems__ + *p++ = '+'; +#endif /* __rtems__ */ idx = 0; for (i = 0; i < n; i++) { lopts[i].name = opts[i].long_arg; @@ -284,6 +306,7 @@ bad_arg: exit(1); } +#ifndef __rtems__ /* * Loads all the .so's from the specified directory. */ @@ -315,6 +338,7 @@ cmd_load_dir(const char *dir __unused, cmd_load_cb_t cb __unused, void *argp __u } closedir(d); } +#endif /* __rtems__ */ void cmd_register(struct cmd *up, struct cmd *cmd) |