diff options
author | Mike Frysinger <vapier@gentoo.org> | 2006-02-04 01:26:24 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2006-02-04 01:26:24 +0000 |
commit | 0f8c0e81b64aeb8e1523f7ffa09a88c6eae04cfb (patch) | |
tree | a7f69f2c41287aa3985404f9dbf09d7fa11841d1 | |
parent | c429bf3057c87dd9545fc2d824b5930c52f7dfb8 (diff) |
touchup test to have some more helpful output
-rw-r--r-- | test/misc/dirent.c | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/test/misc/dirent.c b/test/misc/dirent.c index 885990bf2..f8832f6bd 100644 --- a/test/misc/dirent.c +++ b/test/misc/dirent.c @@ -1,25 +1,47 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> #include <fcntl.h> #include <dirent.h> +#define _DTIFY(DT) [DT] #DT +const char const *types[] = { + _DTIFY(DT_UNKNOWN), + _DTIFY(DT_FIFO), + _DTIFY(DT_CHR), + _DTIFY(DT_DIR), + _DTIFY(DT_BLK), + _DTIFY(DT_REG), + _DTIFY(DT_LNK), + _DTIFY(DT_SOCK), + _DTIFY(DT_WHT) +}; + int main(int argc, char **argv) { + DIR *dirh; + struct dirent *de; + struct dirent64 *de64; + const char const mydir[] = "."; - DIR *dirh; - struct dirent *dirp; - static char mydir[20] = "/tmp"; + if ((dirh = opendir(mydir)) == NULL) { + perror("opendir"); + return 1; + } - if ((dirh = opendir(mydir)) == NULL) { - perror("opendir"); - return 1; - } + printf("readdir() says:\n"); + while ((de = readdir(dirh)) != NULL) + printf("\tdir entry %s: %s\n", types[de->d_type], de->d_name); - for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh)) { - printf("Got dir entry: %s\n",dirp->d_name); - } + rewinddir(dirh); - closedir(dirh); - return 0; -} + printf("readdir64() says:\n"); + while ((de64 = readdir64(dirh)) != NULL) + printf("\tdir entry %s: %s\n", types[de64->d_type], de64->d_name); + + closedir(dirh); + + return 0; +} |