freebsd-nq/contrib/mdocml/test-fts.c
Baptiste Daroussin 7666f5006c Import mandoc cvs snapshot 20170121 (pre 1.14)
Note that mandoc does not use anymore sqlite3 but a home made database format
An important improvement has been made as well in makewhatis performance:
Tests on my laptop shows makewhatis on the entire system goes from 26s to 12s
2017-01-21 13:17:25 +00:00

60 lines
964 B
C

#include <sys/types.h>
#include <sys/stat.h>
#include <fts.h>
#include <stdio.h>
#include <string.h>
#ifdef FTS_COMPARE_CONST
int fts_compare(const FTSENT *const *, const FTSENT *const *);
#else
int fts_compare(const FTSENT **, const FTSENT **);
#endif
int
main(void)
{
const char *argv[2];
FTS *ftsp;
FTSENT *entry;
argv[0] = ".";
argv[1] = (char *)NULL;
ftsp = fts_open((char * const *)argv,
FTS_PHYSICAL | FTS_NOCHDIR, fts_compare);
if (ftsp == NULL) {
perror("fts_open");
return 1;
}
entry = fts_read(ftsp);
if (entry == NULL) {
perror("fts_read");
return 1;
}
if (fts_set(ftsp, entry, FTS_SKIP) != 0) {
perror("fts_set");
return 1;
}
if (fts_close(ftsp) != 0) {
perror("fts_close");
return 1;
}
return 0;
}
int
#ifdef FTS_COMPARE_CONST
fts_compare(const FTSENT *const *a, const FTSENT *const *b)
#else
fts_compare(const FTSENT **a, const FTSENT **b)
#endif
{
return strcmp((*a)->fts_name, (*b)->fts_name);
}