[PATCH 8/9] commands: ln: accept -s option
Sascha Hauer
s.hauer at pengutronix.de
Tue Oct 20 00:09:33 PDT 2026
All links barebox creates are symbolic links, but ln does not accept
the -s option, so the common 'ln -s SRC DEST' fails with a usage error.
Accept -s and ignore it, so that users and scripts can use the familiar
syntax.
While at it, add a help text for the command.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
commands/ln.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/commands/ln.c b/commands/ln.c
index 9206480300..c907b306c9 100644
--- a/commands/ln.c
+++ b/commands/ln.c
@@ -9,22 +9,46 @@
#include <environment.h>
#include <fs.h>
#include <errno.h>
+#include <getopt.h>
static int do_ln(int argc, char *argv[])
{
- if (argc != 3)
+ int opt;
+
+ while ((opt = getopt(argc, argv, "s")) > 0) {
+ switch (opt) {
+ case 's':
+ /* all links are symbolic, accept -s for compatibility */
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 2)
return COMMAND_ERROR_USAGE;
- if (symlink(argv[1], argv[2]) < 0) {
+ if (symlink(argv[0], argv[1]) < 0) {
perror("ln");
return 1;
}
return 0;
}
+BAREBOX_CMD_HELP_START(ln)
+BAREBOX_CMD_HELP_TEXT("Create a symbolic link DEST pointing to SRC.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-s", "ignored, all links are symbolic links")
+BAREBOX_CMD_HELP_END
+
BAREBOX_CMD_START(ln)
.cmd = do_ln,
BAREBOX_CMD_DESC("create symlink (make a new name for a file)")
- BAREBOX_CMD_OPTS("SRC DEST")
+ BAREBOX_CMD_OPTS("[-s] SRC DEST")
BAREBOX_CMD_GROUP(CMD_GRP_FILE)
+ BAREBOX_CMD_HELP(cmd_ln_help)
BAREBOX_CMD_END
--
2.47.3
More information about the barebox
mailing list