summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-03-17 03:55:21 +0000
committerUlrich Drepper <drepper@redhat.com>1997-03-17 03:55:21 +0000
commit77055d99e4fc6d319fa746d8730e5c6a484202e5 (patch)
tree3e6e7e33ce0ef28c70f49a92f1b0bf7ca9b65050
parentfb63ae13d021389b3e96bc1183ec7f84a054553a (diff)
New example for scandir function.
-rw-r--r--manual/examples/dir2.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/manual/examples/dir2.c b/manual/examples/dir2.c
new file mode 100644
index 0000000000..e3157694bd
--- /dev/null
+++ b/manual/examples/dir2.c
@@ -0,0 +1,29 @@
+/*@group*/
+#include <stdio.h>
+#include <dirent.h>
+/*@end group*/
+
+static int
+one (struct dirent *unused)
+{
+ return 1;
+}
+
+int
+main (void)
+{
+ struct dirent **eps;
+ int n;
+
+ n = scandir ("./", &eps, one, alphasort);
+ if (n >= 0)
+ {
+ int cnt;
+ for (cnt = 0; cnt < n; ++cnt)
+ puts (eps[cnt]->d_name);
+ }
+ else
+ perror ("Couldn't open the directory");
+
+ return 0;
+}