Date: Thu, 4 Jul 2002 23:49:20 +0200 From: Johan Karlsson <k@numeri.campus.luth.se> To: arch@freebsd.org Subject: Re: importing readlink(1) from OpenBSD Message-ID: <20020704234920.D52250@numeri.campus.luth.se> In-Reply-To: <20020704194314.A52250@numeri.campus.luth.se>; from johan@freebsd.org on Thu, Jul 04, 2002 at 07:43:14PM %2B0200 References: <20020704194314.A52250@numeri.campus.luth.se>
next in thread | previous in thread | raw e-mail | index | archive | help
--opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jul 04, 2002 at 19:43 (+0200) +0000, Johan Karlsson wrote: > I would like to import readlink(1) from OpenBSD into > usr.bin. Another option is to teach stat(1) how to double as readlink(1) (suggested by wollman). The attached patch does that (it does not implement -f since realpath(1) does that). Is that a better option? /Johan K -- Johan Karlsson mailto:k@numeri.campus.luth.se --opJtzjQTFsWo+cga Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="stat.diff" Index: stat.c =================================================================== RCS file: /home/ncvs/src/usr.bin/stat/stat.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 stat.c --- stat.c 6 Jun 2002 19:27:17 -0000 1.1.1.1 +++ stat.c 4 Jul 2002 21:36:33 -0000 @@ -130,7 +130,7 @@ #define SHOW_filename 'N' #define SHOW_sizerdev 'Z' -void usage(void); +void usage(const char *); void output(const struct stat *, const char *, const char *, int, int); int format1(const struct stat *, /* stat info */ @@ -156,7 +156,7 @@ struct stat st; int ch, rc, errs; int lsF, fmtchar, usestat, fn, nonl; - char *statfmt; + char *statfmt, *options, *synopsis; lsF = 0; fmtchar = '\0'; @@ -165,7 +165,17 @@ statfmt = NULL; timefmt = NULL; - while ((ch = getopt(argc, argv, "f:FlLnrst:x")) != -1) + if (strcmp(getprogname(), "readlink") == 0) { + options = "n"; + synopsis = "[-n] [file ...]"; + statfmt = "%Y"; + fmtchar = 'f'; + } else { + options = "f:FlLnrst:x"; + synopsis = "[-FlLnrsx] [-f format] [-t timefmt] [file ...]"; + } + + while ((ch = getopt(argc, argv, options)) != -1) switch (ch) { case 'F': lsF = 1; @@ -192,7 +202,7 @@ timefmt = optarg; break; default: - usage(); + usage(synopsis); } argc -= optind; @@ -230,7 +240,7 @@ timefmt = "%c"; break; default: - usage(); + usage(synopsis); /*NOTREACHED*/ } @@ -262,12 +272,12 @@ } void -usage(void) +usage(const char *synopsis) { (void)fprintf(stderr, - "usage: %s [-FlLnrsx] [-f format] [-t timefmt] [file ...]\n", - getprogname()); + "usage: %s %s\n", + getprogname(), synopsis); exit(1); } @@ -457,7 +467,7 @@ } (void)write(STDOUT_FILENO, buf, len); - if (!nl && !nonl) + if (len && !nl && !nonl) (void)write(STDOUT_FILENO, "\n", sizeof("\n") - 1); } --opJtzjQTFsWo+cga-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020704234920.D52250>