logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 68c9683469b491fe0599d7c3edd250377ba885b8
parent bf6d020575b1d951a9d6d01104f1ec5ab9221af6
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed,  2 Jul 2025 22:57:36 +0200

cmd/which: no lookup on slash presence

Diffstat:

Mcmd/which.15++++-
Mcmd/which.c6++++++
Atest-cmd/which.sh19+++++++++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/cmd/which.1 b/cmd/which.1 @@ -17,7 +17,10 @@ The utility scans .Ev PATH for each given executable -.Ar name . +.Ar name , +unless it contains a slash where then +.Ar name +is simply printed out. .Pp .Nm shall not be used when the standard diff --git a/cmd/which.c b/cmd/which.c @@ -59,6 +59,12 @@ main(int argc, char *argv[]) bool found = false; char *start = path; + if(strchr(cmd, '/')) + { + puts(cmd); + continue; + } + const char *prev = start; while(true) { diff --git a/test-cmd/which.sh b/test-cmd/which.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +plans=3 +WD="$(dirname "$0")" +target="${WD}/../cmd/which" +. "${WD}/tap.sh" + +CMD_DIR="$(realpath "${WD}/../cmd/")" + +t_cmd normal "${CMD_DIR}/which +" env PATH="/var/empty:${CMD_DIR}" "$target" which + +t_cmd enoent "${CMD_DIR}/which +" env PATH="/var/empty:/var/empty/enoent:${CMD_DIR}" "$target" which + +t_args slash "games/doom +" "games/doom"