From owner-freebsd-bugs Wed Jun 28 16:50: 7 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id B380C37B69C for ; Wed, 28 Jun 2000 16:50:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id QAA33702; Wed, 28 Jun 2000 16:50:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Wed, 28 Jun 2000 16:50:03 -0700 (PDT) Message-Id: <200006282350.QAA33702@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Kelly Yancey Subject: Re: bin/19536: patch to prevent head'ing directories Reply-To: Kelly Yancey Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/19536; it has been noted by GNATS. From: Kelly Yancey To: freebsd-gnats-submit@FreeBSD.org Cc: bde@zeta.org.au Subject: Re: bin/19536: patch to prevent head'ing directories Date: Wed, 28 Jun 2000 16:41:47 -0700 (PDT) Update to patch in response to comments from BDE. -Kelly Index: usr.bin/head/head.c =================================================================== RCS file: /home/cvs/src/usr.bin/head/head.c,v retrieving revision 1.10 diff -u -r1.10 head.c --- usr.bin/head/head.c 1999/08/28 01:01:58 1.10 +++ usr.bin/head/head.c 2000/06/28 23:36:45 @@ -45,6 +45,7 @@ "$FreeBSD: src/usr.bin/head/head.c,v 1.10 1999/08/28 01:01:58 peter Exp $"; #endif /* not lint */ +#include #include #include @@ -73,8 +74,9 @@ char *argv[]; { register int ch; + struct stat sb; FILE *fp; - int first, linecnt = -1, bytecnt = -1; + int first, linecnt = -1, bytecnt = -1, num = 0; char *ep; obsolete(argv); @@ -103,12 +105,24 @@ linecnt = 10; if (*argv) { for (first = 1; *argv; ++argv) { - if ((fp = fopen(*argv, "r")) == NULL) { + if ((fp = fopen(*argv, "r")) == NULL || + fstat(fileno(fp), &sb)) { warn("%s", *argv); eval = 1; continue; } - if (argc > 1) { + if (S_ISDIR(sb.st_mode)) { + warnx("%s is a directory", *argv); + continue; + } else if (S_ISLNK(sb.st_mode)) { + warnx("%s is a symlink", *argv); + continue; + } else if (S_ISWHT(sb.st_mode)) { + warnx("%s is a whiteout entry", *argv); + continue; + } + num++; + if (num > 1) { (void)printf("%s==> %s <==\n", first ? "" : "\n", *argv); first = 0; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message