diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-08-17 01:32:07 +0800 |
---|---|---|
committer | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-09-05 03:22:14 +0800 |
commit | dccdc2ed8889a791bb5f8151286975ad8a94ec1f (patch) | |
tree | d4f852b99a2736547caf192eaf69add230a08411 /commands | |
parent | 0939b7c549f6c4175efffcf3a18efc1197e9a2b0 (diff) | |
download | barebox-dccdc2ed8889a791bb5f8151286975ad8a94ec1f.tar.gz barebox-dccdc2ed8889a791bb5f8151286975ad8a94ec1f.tar.xz |
dirname: add -V option to return only path related to the mountpoint
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/dirname.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/commands/dirname.c b/commands/dirname.c index cf1d0a022d..f34d88d0fc 100644 --- a/commands/dirname.c +++ b/commands/dirname.c @@ -24,20 +24,38 @@ #include <command.h> #include <libgen.h> #include <environment.h> +#include <fs.h> +#include <getopt.h> static int do_dirname(int argc, char *argv[]) { - if (argc != 3) + int opt; + int path_fs = 0; + int len = 0; + + while ((opt = getopt(argc, argv, "V")) > 0) { + switch (opt) { + case 'V': + path_fs = 1; + break; + } + } + + if (argc < optind + 2) return COMMAND_ERROR_USAGE; - setenv(argv[2], dirname(argv[1])); + if (path_fs) + len = strlen(get_mounted_path(argv[optind])); + + setenv(argv[optind + 1], dirname(argv[optind]) + len); return 0; } BAREBOX_CMD_HELP_START(dirname) -BAREBOX_CMD_HELP_USAGE("dirname NAME DIRNAME\n") +BAREBOX_CMD_HELP_USAGE("dirname [-V] NAME DIRNAME\n") BAREBOX_CMD_HELP_SHORT("strip last componext of NAME and store into $DIRNAME\n") +BAREBOX_CMD_HELP_SHORT("-V return the path relative to the mountpoint.\n") BAREBOX_CMD_HELP_END BAREBOX_CMD_START(dirname) |