summaryrefslogtreecommitdiffstats
path: root/test/misc/dirent.c
diff options
context:
space:
mode:
author"Steven J. Hill" <sjhill@realitydiluted.com>2006-08-22 01:56:31 +0000
committer"Steven J. Hill" <sjhill@realitydiluted.com>2006-08-22 01:56:31 +0000
commitc969ef4b8fc1d06c13203b36f8cf5bb61a7730f0 (patch)
treeeb2da173a5661b2b2e615045f26f7b69e774290d /test/misc/dirent.c
parentfea84e591f94b025ef7c2da843ae80b809f93dbe (diff)
downloaduClibc-alpine-c969ef4b8fc1d06c13203b36f8cf5bb61a7730f0.tar.bz2
uClibc-alpine-c969ef4b8fc1d06c13203b36f8cf5bb61a7730f0.tar.xz
Merge from trunk. Whoa crap.
Diffstat (limited to 'test/misc/dirent.c')
-rw-r--r--test/misc/dirent.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/test/misc/dirent.c b/test/misc/dirent.c
index 885990bf2..491e3cf75 100644
--- a/test/misc/dirent.c
+++ b/test/misc/dirent.c
@@ -1,25 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
-int main(int argc, char **argv)
+#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;
+ const char *mydir = (argc == 1 ? "/" : argv[1]);
- 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);
- }
+ closedir(dirh);
- closedir(dirh);
- return 0;
+ return 0;
}
-