fts.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:51:15 +0200
changeset 84 f59d8a8e786f
parent 77 49e0babccb23
child 112 9bfb339a8156
permissions -rw-r--r--
struct hostent has no longer a member h_addr Current netdb.h lacks support for the old h_addr pointer without special USE_GNU defines... committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * fts.c
 * Copyright (C) 2008 Markus Broeker
 *
 * file hierarchy browser
 */

#include <stdio.h>
#include <stdlib.h>

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

#include <fts.h>
#include <errno.h>

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) {
        if (!errno)
            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;
}