summaryrefslogtreecommitdiff
path: root/usr.bin/which/which.c
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2013-04-10 02:57:21 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2013-04-10 02:57:21 +0000
commit0af05f03b2178d4ed66d756df0d7ec72c16248c7 (patch)
treeb82e48967e15c5685f8b5549b013606be66caf7e /usr.bin/which/which.c
parentae8b0483dbf4c7520407bab46a41e05336e0f899 (diff)
Get the standard path from _PATH_STDPATH instead of
sysctl({CTL_USER,USER_CS_PATH}). Expand that into the manpage too. _PATH_STDPATH suggested by miod@ Corrections from schwarze@ and jmc@ ok millert@ miod@ schwarze@ jmc@
Diffstat (limited to 'usr.bin/which/which.c')
-rw-r--r--usr.bin/which/which.c20
1 files changed, 3 insertions, 17 deletions
diff --git a/usr.bin/which/which.c b/usr.bin/which/which.c
index 782e94a96a7..44bbd73bb53 100644
--- a/usr.bin/which/which.c
+++ b/usr.bin/which/which.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: which.c,v 1.17 2011/03/11 04:30:21 guenther Exp $ */
+/* $OpenBSD: which.c,v 1.18 2013/04/10 02:57:20 guenther Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -23,6 +23,7 @@
#include <err.h>
#include <errno.h>
#include <locale.h>
+#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -69,24 +70,9 @@ main(int argc, char *argv[])
if (argc == 0)
usage();
- /*
- * which(1) uses user's $PATH.
- * whereis(1) uses user.cs_path from sysctl(3).
- */
if (strcmp(__progname, "whereis") == 0) {
- int mib[2];
-
progmode = PROG_WHEREIS;
- mib[0] = CTL_USER;
- mib[1] = USER_CS_PATH;
- if (sysctl(mib, 2, NULL, &n, NULL, 0) == -1)
- err(1, "unable to get length of user.cs_path");
- if (n == 0)
- errx(1, "user.cs_path was zero length!");
- if ((path = (char *)malloc(n)) == NULL)
- errx(1, "can't allocate memory.");
- if (sysctl(mib, 2, path, &n, NULL, 0) == -1)
- err(1, "unable to get user.cs_path");
+ path = _PATH_STDPATH;
} else {
if ((path = getenv("PATH")) == NULL)
err(1, "can't get $PATH from environment");