From: guenther Date: Thu, 15 Aug 2024 06:27:24 +0000 (+0000) Subject: unifdef for S_I{FLNK,FIFO,FSOCK}. For the operations where we use X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=18d6208093ce062ee231bbf33610d37f3f9bf910;p=openbsd unifdef for S_I{FLNK,FIFO,FSOCK}. For the operations where we use access() (-r, -w, -x, -e) do them without requiring stat() to succeed first. ok tb@ deraadt@ --- diff --git a/bin/test/test.c b/bin/test/test.c index 5756645574d..21c27642455 100644 --- a/bin/test/test.c +++ b/bin/test/test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test.c,v 1.21 2024/06/18 16:41:39 schwarze Exp $ */ +/* $OpenBSD: test.c,v 1.22 2024/08/15 06:27:24 guenther Exp $ */ /* $NetBSD: test.c,v 1.15 1995/03/21 07:04:06 cgd Exp $ */ /* @@ -424,13 +424,24 @@ filstat(char *nm, enum token mode) struct stat s; mode_t i; + switch (mode) { + case FILRD: + return access(nm, R_OK) == 0; + case FILWR: + return access(nm, W_OK) == 0; + case FILEX: + return access(nm, X_OK) == 0; + case FILEXIST: + return access(nm, F_OK) == 0; + default: + break; + } + if (mode == FILSYM) { -#ifdef S_IFLNK if (lstat(nm, &s) == 0) { i = S_IFLNK; goto filetype; } -#endif return 0; } @@ -438,14 +449,6 @@ filstat(char *nm, enum token mode) return 0; switch (mode) { - case FILRD: - return access(nm, R_OK) == 0; - case FILWR: - return access(nm, W_OK) == 0; - case FILEX: - return access(nm, X_OK) == 0; - case FILEXIST: - return access(nm, F_OK) == 0; case FILREG: i = S_IFREG; goto filetype; @@ -459,19 +462,11 @@ filstat(char *nm, enum token mode) i = S_IFBLK; goto filetype; case FILFIFO: -#ifdef S_IFIFO i = S_IFIFO; goto filetype; -#else - return 0; -#endif case FILSOCK: -#ifdef S_IFSOCK i = S_IFSOCK; goto filetype; -#else - return 0; -#endif case FILSUID: i = S_ISUID; goto filebit;