From: guenther Date: Wed, 11 Sep 2024 03:57:14 +0000 (+0000) Subject: fstat(2) can't return an S_IFLNK, so delete that test. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e291b8af02e5c2b53d7ddb1f0c9c0fd608b97d45;p=openbsd fstat(2) can't return an S_IFLNK, so delete that test. Also, switch to S_IS*() tests and update the manpage to reflect that POSIX-2024 has no substantive changes for wc(1) ok op@ millert@ --- diff --git a/usr.bin/wc/wc.1 b/usr.bin/wc/wc.1 index dcbb3b61311..4714c88fb5f 100644 --- a/usr.bin/wc/wc.1 +++ b/usr.bin/wc/wc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: wc.1,v 1.27 2016/10/24 13:46:58 schwarze Exp $ +.\" $OpenBSD: wc.1,v 1.28 2024/09/11 03:57:14 guenther Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" from: @(#)wc.1 8.2 (Berkeley) 4/19/94 .\" -.Dd $Mdocdate: October 24 2016 $ +.Dd $Mdocdate: September 11 2024 $ .Dt WC 1 .Os .Sh NAME @@ -125,7 +125,7 @@ has the same effect as The .Nm utility is compliant with the -.St -p1003.1-2008 +.St -p1003.1-2024 specification. .Pp The flag diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c index e6877f0cbec..a22188aff8e 100644 --- a/usr.bin/wc/wc.c +++ b/usr.bin/wc/wc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wc.c,v 1.31 2022/12/04 23:50:50 cheloha Exp $ */ +/* $OpenBSD: wc.c,v 1.32 2024/09/11 03:57:14 guenther Exp $ */ /* * Copyright (c) 1980, 1987, 1991, 1993 @@ -193,23 +193,19 @@ cnt(const char *path) } /* * If all we need is the number of characters and - * it's a directory or a regular or linked file, just - * stat the puppy. We avoid testing for it not being + * it's a directory or a regular file, just stat + * our handle. We avoid testing for it not being * a special device in case someone adds a new type * of inode. */ else if (dochar) { - mode_t ifmt; - if (fstat(fd, &sbuf)) { warn("%s", file); rval = 1; } else { - ifmt = sbuf.st_mode & S_IFMT; - if (ifmt == S_IFREG || ifmt == S_IFLNK - || ifmt == S_IFDIR) { + if (S_ISREG(sbuf.st_mode) || S_ISDIR(sbuf.st_mode)) charct = sbuf.st_size; - } else { + else { while ((len = read(fd, buf, _MAXBSIZE)) > 0) charct += len; if (len == -1) {