# HG changeset patch # User Markus Bröker # Date 1239879039 -7200 # Node ID abe63a276a36759cc52ff1d15f627416ed936f2f # Parent 2b4f786d90732f65021467e7523a8dc0556d83fa file traversal demo && minor changes Traversal through a filesystem hierarchy made easy committer: Markus Bröker diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -55,6 +55,7 @@ TARGET += fork TARGET += duff TARGET += unicode +TARGET += fts .SUFFIXES: .c .cc .asm @@ -288,6 +289,12 @@ @echo Linking $< ... @$(CC) -std=c99 -o $@ $< +fts: fts.c + @echo Compiling \(NON-ANSI\) $<... + @$(CC) -c -Wall -O2 $< + @echo Linking $< ... + @$(CC) -o $@ $< + .PHONY: beauty clean uninstall clean: diff --git a/fts.c b/fts.c new file mode 100644 --- /dev/null +++ b/fts.c @@ -0,0 +1,59 @@ +/** + * fts.c file hierarchy browser + */ + +#include +#include + +#include +#include + +#include + +int compare (const FTSENT ** a, const FTSENT ** b) +{ + return 0; +} + +int main (int argc, char **argv) +{ + FTS *fts; + FTSENT *current = NULL; + + char **paths; + + int i; + + if (argc < 2) { + printf ("Usage: %s [dir]...\n", argv[0]); + return EXIT_FAILURE; + } + + if ((paths = calloc (argc + 1, sizeof (char *))) == NULL) { + perror ("CALLOC"); + return EXIT_FAILURE; + } + + for (i = 1; i < argc; i++) { + paths[i - 1] = argv[i]; + } + + paths[i] = NULL; + + if ((fts = fts_open (paths, FTS_NOSTAT, &compare)) == NULL) { + perror ("fts_open"); + return EXIT_FAILURE; + } + + while ((current = fts_read (fts)) != NULL) { + printf ("%s/%s\n", current->fts_path, current->fts_name); + } + + if (fts_close (fts) < 0) + perror ("fts_close"); + + if (paths != NULL) + free (paths); + + return EXIT_SUCCESS; +} diff --git a/prog_limit.c b/prog_limit.c --- a/prog_limit.c +++ b/prog_limit.c @@ -37,7 +37,7 @@ switch (pid) { case 0: if (set_limit (atoi (argv[1])) == 0) { - i = execvp (argv[2], args); + i = execvp (args[0], args); } else { perror ("Limit Error"); return EXIT_FAILURE;