about summary refs log tree commit diff
path: root/manual/examples
diff options
context:
space:
mode:
Diffstat (limited to 'manual/examples')
-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;
+}