summaryrefslogtreecommitdiff
path: root/usr.bin/readlink/readlink.c
diff options
context:
space:
mode:
authorkstailey <kstailey@cvs.openbsd.org>1997-07-01 15:09:37 +0000
committerkstailey <kstailey@cvs.openbsd.org>1997-07-01 15:09:37 +0000
commitf39efef560d4553e799a37d8e67b35523075161a (patch)
tree4aca4c191c98d44ec074e46f0dd3c0db08eabe34 /usr.bin/readlink/readlink.c
parentff382109a56e8c8217c50d652f6ef78a4e5b7155 (diff)
Change default behavior to print newline after contents of symlink.
Add "-n" flag to get old behavior.
Diffstat (limited to 'usr.bin/readlink/readlink.c')
-rw-r--r--usr.bin/readlink/readlink.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/usr.bin/readlink/readlink.c b/usr.bin/readlink/readlink.c
index 8dbc4a80caa..7ceeb004623 100644
--- a/usr.bin/readlink/readlink.c
+++ b/usr.bin/readlink/readlink.c
@@ -1,5 +1,5 @@
/*
- * $OpenBSD: readlink.c,v 1.7 1997/06/29 19:20:31 kstailey Exp $
+ * $OpenBSD: readlink.c,v 1.8 1997/07/01 15:09:36 kstailey Exp $
*
* Copyright (c) 1997
* Kenneth Stailey (hereinafter referred to as the author)
@@ -37,17 +37,33 @@ int argc;
char **argv;
{
char buf[PATH_MAX];
- int n;
+ int n, ch, nflag = 0;
+ extern int optind;
- if (argc != 2) {
- fprintf(stderr, "usage: readlink symlink");
+ while ((ch = getopt(argc, argv, "n")) != -1)
+ switch (ch) {
+ case 'n':
+ nflag = 1;
+ break;
+ default:
+ (void)fprintf(stderr,
+ "usage: readlink [-n] symlink\n");
+ exit(1);
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 1) {
+ fprintf(stderr, "usage: readlink [-n] symlink\n");
exit(1);
}
- if ((n = readlink(argv[1], buf, PATH_MAX)) < 0)
+ if ((n = readlink(argv[0], buf, PATH_MAX)) < 0)
exit(1);
buf[n] = '\0';
printf("%s", buf);
+ if (!nflag)
+ putchar('\n');
exit(0);
}