From b0e8ced3589c601ad5c15e74d6f82b1928e1eb8f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 21 Mar 2011 12:36:35 +0100 Subject: [PATCH] ln: explain why we use xstrdup Signed-off-by: Denys Vlasenko --- coreutils/ln.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/coreutils/ln.c b/coreutils/ln.c index ddad120d1..6da290c11 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c @@ -40,8 +40,12 @@ int ln_main(int argc, char **argv) last = argv[argc - 1]; argv += optind; - if (argc == optind + 1) { + if (!argv[1]) { + /* "ln PATH/TO/FILE" -> "ln PATH/TO/FILE FILE" */ *--argv = last; + /* xstrdup is needed: "ln -s PATH/TO/FILE/" is equivalent to + * "ln -s PATH/TO/FILE/ FILE", not "ln -s PATH/TO/FILE FILE" + */ last = bb_get_last_path_component_strip(xstrdup(last)); } -- 2.25.1