Example for scandir and alphasort function.
authordrepper <drepper>
Mon, 10 Mar 1997 19:53:37 +0000 (19:53 +0000)
committerdrepper <drepper>
Mon, 10 Mar 1997 19:53:37 +0000 (19:53 +0000)
manual/examples/dir2.c [new file with mode: 0644]

diff --git a/manual/examples/dir2.c b/manual/examples/dir2.c
new file mode 100644 (file)
index 0000000..e315769
--- /dev/null
@@ -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;
+}