[BACK]Return to test-fts.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

File: [cvsweb.bsd.lv] / mandoc / test-fts.c (download)

Revision 1.1, Mon Aug 11 01:39:00 2014 UTC (9 years, 8 months ago) by schwarze
Branch: MAIN

Provide a fallback version of fts(3) for systems lacking it.
I chose the OpenBSD version because it apparently contains various
bugfixes that never made it into libnbcompat.  To reduce size and
complexity, i stripped out the features we don't need.

#include <sys/types.h>
#include <sys/stat.h>
#include <fts.h>
#include <stdio.h>

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, NULL);

	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(NULL) != 0) {
		perror("fts_close");
		return(1);
	}

	return(0);
}