From owner-freebsd-arch Thu Jul 4 14:49:28 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2C38537B400 for ; Thu, 4 Jul 2002 14:49:23 -0700 (PDT) Received: from numeri.campus.luth.se (numeri.campus.luth.se [130.240.197.103]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0A77243E31 for ; Thu, 4 Jul 2002 14:49:22 -0700 (PDT) (envelope-from k@numeri.campus.luth.se) Received: (from k@localhost) by numeri.campus.luth.se (8.11.6/8.11.6) id g64LnKS61453 for arch@freebsd.org; Thu, 4 Jul 2002 23:49:20 +0200 (CEST) (envelope-from k) Date: Thu, 4 Jul 2002 23:49:20 +0200 From: Johan Karlsson To: arch@freebsd.org Subject: Re: importing readlink(1) from OpenBSD Message-ID: <20020704234920.D52250@numeri.campus.luth.se> References: <20020704194314.A52250@numeri.campus.luth.se> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="opJtzjQTFsWo+cga" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20020704194314.A52250@numeri.campus.luth.se>; from johan@freebsd.org on Thu, Jul 04, 2002 at 07:43:14PM +0200 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --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