Date: Wed, 28 Jun 2000 16:50:03 -0700 (PDT) From: Kelly Yancey <kbyanc@egroups.net> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/19536: patch to prevent head'ing directories Message-ID: <200006282350.QAA33702@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/19536; it has been noted by GNATS. From: Kelly Yancey <kbyanc@egroups.net> 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 <sys/stat.h> #include <sys/types.h> #include <ctype.h> @@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006282350.QAA33702>