support more than 2 billion file names for counting (-c) or limits (-l limit)

- this fix (harmless) integer overflows for very large partitions (>1PB)
- code cleanup
This commit is contained in:
Wolfram Schneider 2022-01-26 16:15:23 +00:00
parent e48156828f
commit 0c178a2a64
3 changed files with 8 additions and 16 deletions

View File

@ -326,7 +326,7 @@ fastfind
if (f_limit >= counter)
(void)printf("%s%c",path,separator);
else
errx(0, "[show only %d lines]", counter - 1);
errx(0, "[show only %ld lines]", counter - 1);
} else
(void)printf("%s%c",path,separator);
}

View File

@ -102,8 +102,8 @@ int f_icase; /* ignore case */
int f_stdin; /* read database from stdin */
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 */
u_int counter; /* counter for matches [-c] */
long f_limit; /* limit number of output lines, 0 == infinite */
long counter; /* counter for matches [-c] */
char separator='\n'; /* line separator */
u_char myctype[UCHAR_MAX + 1];
@ -119,7 +119,6 @@ void search_fopen(char *, char **);
unsigned long cputime(void);
extern char **colon(char **, char*, char*);
extern void print_matches(u_int);
extern int getwm(caddr_t);
extern int getwf(FILE *);
extern u_char *tolower_word(u_char *);
@ -146,7 +145,9 @@ main(int argc, char **argv)
f_statistic = 1;
break;
case 'l': /* limit number of output lines, 0 == infinite */
f_limit = atoi(optarg);
f_limit = atol(optarg);
if (f_limit < 0 )
errx(1, "invalid argument for -l: '%s'", optarg);
break;
case 'd': /* database */
dbv = colon(dbv, optarg, _PATH_FCODES);
@ -211,7 +212,7 @@ main(int argc, char **argv)
}
if (f_silent)
print_matches(counter);
printf("%ld\n", counter);
exit(0);
}

View File

@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
* Copyright (c) 1995-2022 Wolfram Schneider <wosch@FreeBSD.org>
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
@ -47,7 +47,6 @@
char **colon(char **, char*, char*);
char *patprep(char *);
void print_matches(u_int);
u_char *tolower_word(u_char *);
int getwm(caddr_t);
int getwf(FILE *);
@ -131,14 +130,6 @@ colon(char **dbv, char *path, char *dot)
return (dbv);
}
void
print_matches(counter)
u_int counter;
{
(void)printf("%d\n", counter);
}
/*
* extract last glob-free subpattern in name for fast pre-match; prepend
* '\0' for backwards match; return end of new pattern