-/* $OpenBSD: fastfind.c,v 1.8 2003/09/29 16:03:16 deraadt Exp $ */
+/* $OpenBSD: fastfind.c,v 1.9 2008/07/26 09:48:00 pyr Exp $ */
/*
* Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: fastfind.c,v 1.8 2003/09/29 16:03:16 deraadt Exp $
+ * $Id: fastfind.c,v 1.9 2008/07/26 09:48:00 pyr Exp $
*/
#ifndef _LOCATE_STATISTIC_
)
break;
if (*p == '\0') { /* fast match success */
+ char *shortpath;
+
found = 1;
- if (!globflag || !fnmatch(pathpart, path, 0)) {
+ shortpath = path;
+ if (f_basename)
+ shortpath = basename(path);
+
+ if ((!f_basename && (!globflag ||
+ !fnmatch(pathpart, shortpath, 0)))
+ || (strstr(shortpath, pathpart) !=
+ NULL)) {
if (f_silent)
counter++;
else if (f_limit) {
-.\" $OpenBSD: locate.1,v 1.25 2007/06/25 13:12:51 jmc Exp $
+.\" $OpenBSD: locate.1,v 1.26 2008/07/26 09:48:00 pyr Exp $
.\"
.\" Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
.\" Copyright (c) 1990, 1993
.\" SUCH DAMAGE.
.\"
.\" @(#)locate.1 8.1 (Berkeley) 6/6/93
-.\" $Id: locate.1,v 1.25 2007/06/25 13:12:51 jmc Exp $
+.\" $Id: locate.1,v 1.26 2008/07/26 09:48:00 pyr Exp $
.\"
-.Dd $Mdocdate: June 25 2007 $
+.Dd $Mdocdate: July 26 2008 $
.Dt LOCATE 1
.Os
.Sh NAME
.Pp
The options are as follows:
.Bl -tag -width Ds
+.It Fl b
+For each entry in the database, perform the search on the last
+component of path.
.It Fl c
Suppress normal output; instead print a count of matching file names.
.It Fl d Ar database
/*
- * $OpenBSD: locate.c,v 1.19 2006/08/05 23:05:13 ray Exp $
+ * $OpenBSD: locate.c,v 1.20 2008/07/26 09:48:00 pyr Exp $
*
* Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
* Copyright (c) 1989, 1993
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: locate.c,v 1.19 2006/08/05 23:05:13 ray Exp $
+ * $Id: locate.c,v 1.20 2008/07/26 09:48:00 pyr Exp $
*/
#ifndef lint
#if 0
static char sccsid[] = "@(#)locate.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: locate.c,v 1.19 2006/08/05 23:05:13 ray Exp $";
+static char rcsid[] = "$OpenBSD: locate.c,v 1.20 2008/07/26 09:48:00 pyr Exp $";
#endif
#endif /* not lint */
#include <ctype.h>
#include <err.h>
#include <fnmatch.h>
+#include <libgen.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
int f_statistic; /* print statistic */
int f_silent; /* suppress output, show only count of matches */
int f_limit; /* limit number of output lines, 0 == infinite */
+int f_basename; /* match only on the basename */
u_int counter; /* counter for matches [-c] */
#endif
(void) setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "Scd:il:ms")) != -1)
+ while ((ch = getopt(argc, argv, "bScd:il:ms")) != -1)
switch (ch) {
+ case 'b':
+ f_basename = 1;
+ break;
case 'S': /* statistic lines */
f_statistic = 1;
break;