summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjohan <johan@FreeBSD.org>2002-07-03 19:06:36 +0000
committerjohan <johan@FreeBSD.org>2002-07-03 19:06:36 +0000
commit2a23d05df6b872454aeb2142296f9ca3ff049157 (patch)
tree5dffde5d712aae6cf08065652936dbe3bea3e8b4
parent2b1df32ae52c7e7830a302cc5f465fd2b9b1b136 (diff)
downloadFreeBSD-src-2a23d05df6b872454aeb2142296f9ca3ff049157.zip
FreeBSD-src-2a23d05df6b872454aeb2142296f9ca3ff049157.tar.gz
Vendor import of NetBSDs whereis.{c,1}
Approved by: sheldonh (mentor) Obtained from: NetBSD
-rw-r--r--usr.bin/whereis/whereis.126
-rw-r--r--usr.bin/whereis/whereis.c56
2 files changed, 56 insertions, 26 deletions
diff --git a/usr.bin/whereis/whereis.1 b/usr.bin/whereis/whereis.1
index ee90db0..7304934 100644
--- a/usr.bin/whereis/whereis.1
+++ b/usr.bin/whereis/whereis.1
@@ -1,3 +1,5 @@
+.\" $NetBSD: whereis.1,v 1.12 2001/12/01 16:43:27 wiz Exp $
+.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -33,31 +35,41 @@
.\"
.Dd April 27, 1995
.Dt WHEREIS 1
-.Os BSD 3
+.Os
.Sh NAME
.Nm whereis
.Nd locate programs
.Sh SYNOPSIS
-.Nm whereis
+.Nm
+.Op Fl p
+.Ar program
.Op Ar program ...
.Sh DESCRIPTION
The
-.Nm whereis
+.Nm
utility checks the standard binary directories for the specified programs,
printing out the paths of any it finds.
.Pp
-The path searched is the string returned by the
+The default path searched is the string returned by the
.Xr sysctl 8
utility for the
.Dq user.cs_path
string.
+If the
+.Op Fl p
+option is specified, then the value of the environment
+variable
+.Ev PATH
+is used instead.
.Sh SEE ALSO
+.Xr which 1 ,
.Xr sysctl 8
.Sh COMPATIBILITY
The historic flags and arguments for the
-.Nm whereis
+.Nm
utility are no longer available in this version.
.Sh HISTORY
The
-.Nm whereis
-command appeared in 3.0BSD.
+.Nm
+command appeared in
+.Bx 3.0 .
diff --git a/usr.bin/whereis/whereis.c b/usr.bin/whereis/whereis.c
index 4e39cda..c780136 100644
--- a/usr.bin/whereis/whereis.c
+++ b/usr.bin/whereis/whereis.c
@@ -1,3 +1,5 @@
+/* $NetBSD: whereis.c,v 1.11 2002/06/11 06:06:21 itojun Exp $ */
+
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@@ -31,14 +33,17 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1993\n\
+ The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)whereis.c 8.3 (Berkeley) 5/4/95";
+#endif
+__RCSID("$NetBSD: whereis.c,v 1.11 2002/06/11 06:06:21 itojun Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -53,6 +58,7 @@ static char sccsid[] = "@(#)whereis.c 8.3 (Berkeley) 5/4/95";
#include <unistd.h>
void usage __P((void));
+int main __P((int, char *[]));
int
main(argc, argv)
@@ -63,9 +69,14 @@ main(argc, argv)
size_t len;
int ch, sverrno, mib[2];
char *p, *t, *std, path[MAXPATHLEN];
+ int useenvpath = 0;
- while ((ch = getopt(argc, argv, "")) != EOF)
+ while ((ch = getopt(argc, argv, "p")) != -1)
switch (ch) {
+ case 'p':
+ useenvpath = 1; /* use environment for PATH */
+ break;
+
case '?':
default:
usage();
@@ -76,20 +87,25 @@ main(argc, argv)
if (argc == 0)
usage();
- /* Retrieve the standard path. */
- mib[0] = CTL_USER;
- mib[1] = USER_CS_PATH;
- if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1)
- return (-1);
- if (len == 0)
- err(1, "user_cs_path: sysctl: zero length\n");
- if ((std = malloc(len)) == NULL)
- err(1, NULL);
- if (sysctl(mib, 2, std, &len, NULL, 0) == -1) {
- sverrno = errno;
- free(std);
- errno = sverrno;
- err(1, "sysctl: user_cs_path");
+ if (useenvpath) {
+ if ((std = getenv("PATH")) == NULL)
+ err(1, "getenv: PATH" );
+ } else {
+ /* Retrieve the standard path. */
+ mib[0] = CTL_USER;
+ mib[1] = USER_CS_PATH;
+ if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1)
+ return (-1);
+ if (len == 0)
+ err(1, "user_cs_path: sysctl: zero length");
+ if ((std = malloc(len)) == NULL)
+ err(1, NULL);
+ if (sysctl(mib, 2, std, &len, NULL, 0) == -1) {
+ sverrno = errno;
+ free(std);
+ errno = sverrno;
+ err(1, "sysctl: user_cs_path");
+ }
}
/* For each path, for each program... */
@@ -109,12 +125,14 @@ main(argc, argv)
if (p == NULL)
break;
}
+
+ return (0);
}
void
usage()
{
- (void)fprintf(stderr, "usage: whereis program [...]\n");
+ (void)fprintf(stderr, "usage: whereis [-p] program [...]\n");
exit (1);
}
OpenPOWER on IntegriCloud