commit: 27edf1b9663766b4a7c74aa880e42224e6ba296b
parent 175295c6b53ee6d7ea1aea5c9e69d74f62523a28
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 17 Nov 2024 10:36:02 +0100
cmd/ln: add -v option
Diffstat:
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/cmd/ln.1 b/cmd/ln.1
@@ -9,7 +9,7 @@
.Nd create hard links and symbolic links
.Sh SYNOPSIS
.Nm
-.Op Fl fn
+.Op Fl fnv
.Op Fl L Ns | Ns Fl P
.Ar source...
.Ar target
@@ -63,6 +63,8 @@ is a symbolic link, hard link it.
This is the default.
.It Fl s
Create symbolic links instead of hard links.
+.It Fl v
+Print successfully created links.
.El
.Sh EXIT STATUS
.Ex -std
@@ -73,6 +75,8 @@ IEEE Std 1003.1-2024 (“POSIX.1”)
specification.
The
.Fl n
-option is an extension.
+and
+.Fl v
+options are extensions.
.Sh AUTHORS
.An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me
diff --git a/cmd/ln.c b/cmd/ln.c
@@ -134,16 +134,18 @@ static void
usage(void)
{
fprintf(stderr, "\
-Usage: ln [-f] [-L|-P] source... target\n\
- ln -s [-f] reference... target\n\
+Usage: ln [-fv] [-L|-P] source... target\n\
+ ln -s [-fv] reference... target\n\
");
}
int
main(int argc, char *argv[])
{
+ bool verbose = false;
+
int c = -1;
- while((c = getopt(argc, argv, ":fnsLP")) != -1)
+ while((c = getopt(argc, argv, ":fnsLPv")) != -1)
{
switch(c)
{
@@ -162,6 +164,9 @@ main(int argc, char *argv[])
case 'P':
FIELD_CLR(link_flags, AT_SYMLINK_FOLLOW);
break;
+ case 'v':
+ verbose = true;
+ break;
case '?':
fprintf(stderr, "ln: error: Unknown option '-%c'\n", optopt);
usage();
@@ -208,6 +213,8 @@ main(int argc, char *argv[])
}
if(do_link(src, target) < 0) return 1;
+
+ if(verbose) printf("'%s' -> '%s'\n", src, dest);
}
return 0;