From owner-freebsd-audit Tue May 14 23:18:48 2002 Delivered-To: freebsd-audit@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id 5AA8137B405 for ; Tue, 14 May 2002 23:18:38 -0700 (PDT) Received: from hades.hell.gr (patr530-a051.otenet.gr [212.205.215.51]) by mailsrv.otenet.gr (8.12.3/8.12.3) with ESMTP id g4F6IY1b017425 for ; Wed, 15 May 2002 09:18:35 +0300 (EEST) Received: from hades.hell.gr (hades [127.0.0.1]) by hades.hell.gr (8.12.3/8.12.3) with ESMTP id g4F6IWtQ048018 for ; Wed, 15 May 2002 09:18:32 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from charon@localhost) by hades.hell.gr (8.12.3/8.12.3/Submit) id g4F6IU3A048017 for freebsd-audit@FreeBSD.org; Wed, 15 May 2002 09:18:30 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Wed, 15 May 2002 09:18:28 +0300 From: Giorgos Keramidas To: freebsd-audit@FreeBSD.org Subject: RFC: Port of NetBSD cat(1)'s -f option. Message-ID: <20020515061827.GA47688@hades.hell.gr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.99i Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Here's a patch that adds to our cat(1) the same functionality as NetBSD cat(1) when passed -f on the command line. The original commit log from NetBSD's CVS tree is: ---------------------------- revision 1.18 date: 2000/01/15 01:13:15; author: christos; state: Exp; lines: +4 -2 branches: 1.18.4; Add a -f fflag that makes sure that we only try to read from plain files so that there is no chance to block. What do you all think of this? %%% Index: cat.1 =================================================================== RCS file: /home/ncvs/src/bin/cat/cat.1,v retrieving revision 1.19 diff -u -r1.19 cat.1 --- cat.1 25 Sep 2001 18:10:18 -0000 1.19 +++ cat.1 15 May 2002 05:57:28 -0000 @@ -82,6 +82,8 @@ option), and display a dollar sign .Pq Ql \&$ at the end of each line. +.It Fl f +Only attempt to display regular files. .It Fl n Number the output lines, starting at 1. .It Fl s Index: cat.c =================================================================== RCS file: /home/ncvs/src/bin/cat/cat.c,v retrieving revision 1.21 diff -u -r1.21 cat.c --- cat.c 22 Feb 2002 20:42:57 -0000 1.21 +++ cat.c 15 May 2002 05:56:26 -0000 @@ -66,7 +66,7 @@ #include #include -int bflag, eflag, nflag, sflag, tflag, vflag; +int bflag, eflag, fflag, nflag, sflag, tflag, vflag; int rval; const char *filename; @@ -85,7 +85,7 @@ setlocale(LC_CTYPE, ""); - while ((ch = getopt(argc, argv, "benstuv")) != -1) + while ((ch = getopt(argc, argv, "befnstuv")) != -1) switch (ch) { case 'b': bflag = nflag = 1; /* -b implies -n */ @@ -93,6 +93,9 @@ case 'e': eflag = vflag = 1; /* -e implies -v */ break; + case 'f': + fflag = 1; + break; case 'n': nflag = 1; break; @@ -110,12 +113,12 @@ break; default: fprintf(stderr, - "usage: cat [-benstuv] [-] [file ...]\n"); + "usage: cat [-befnstuv] [-] [file ...]\n"); exit(1); } argv += optind; - if (bflag || eflag || nflag || sflag || tflag || vflag) + if (bflag || eflag || fflag || nflag || sflag || tflag || vflag) scanfiles(argv, 1); else scanfiles(argv, 0); @@ -138,7 +141,15 @@ filename = "stdin"; fd = STDIN_FILENO; } else { + struct stat st; + filename = path; + if (stat(path, &st) < 0 || + S_ISREG(st.st_mode) == 0) { + i++; /* Skip to next file. */ + continue; + } + fd = open(path, O_RDONLY); #ifndef NO_UDOM_SUPPORT if (fd < 0 && errno == EOPNOTSUPP) %%% -- Giorgos Keramidas - http://www.FreeBSD.org keramida@FreeBSD.org - The Power to Serve To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message