X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=plocate.cpp;h=a76c288a2bca86f0a11ebfec822d34721fa38335;hb=c427ecd63267946d66cf15808ed507d4f94c3566;hp=9f3928b1a8349e8db0e57d82bb31fd8df59171ef;hpb=8c55aee2b5a22c067989043e5adb1cfce4ffddbf;p=plocate diff --git a/plocate.cpp b/plocate.cpp index 9f3928b..a76c288 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -1,4 +1,5 @@ #include "db.h" +#include "dprintf.h" #include "io_uring_engine.h" #include "parse_trigrams.h" #include "turbopfor.h" @@ -11,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -33,13 +35,6 @@ using namespace std; using namespace std::chrono; -#define dprintf(...) \ - do { \ - if (use_debug) { \ - fprintf(stderr, __VA_ARGS__); \ - } \ - } while (false) - #define DEFAULT_DBPATH "/var/lib/mlocate/plocate.db" const char *dbpath = DEFAULT_DBPATH; @@ -438,7 +433,7 @@ void do_search_file(const vector &needles, const char *filename) // work for fairly unclear gain.) uint64_t matched = scan_all_docids(needles, fd, corpus, &engine); if (only_count) { - printf("%zu\n", matched); + printf("%" PRId64 "\n", matched); } return; } @@ -558,11 +553,11 @@ void do_search_file(const vector &needles, const char *filename) 1e3 * duration(steady_clock::now() - start).count()); uint64_t matched = scan_docids(needles, cur_candidates, corpus, &engine); - dprintf("Done in %.1f ms, found %zu matches.\n", + dprintf("Done in %.1f ms, found %" PRId64 " matches.\n", 1e3 * duration(steady_clock::now() - start).count(), matched); if (only_count) { - printf("%zu\n", matched); + printf("%" PRId64 "\n", matched); } } @@ -668,6 +663,10 @@ int main(int argc, char **argv) case 'l': case 'n': limit_matches = atoll(optarg); + if (limit_matches <= 0) { + fprintf(stderr, "Error: limit must be a strictly positive number.\n"); + exit(1); + } break; case '0': print_nul = true; @@ -705,7 +704,6 @@ int main(int argc, char **argv) Needle needle; needle.str = argv[i]; - // See if there are any wildcard characters, which indicates we should treat it // as an (anchored) glob. bool any_wildcard = false;