aboutsummaryrefslogtreecommitdiff
path: root/manual/examples/dir2.c
blob: e3157694bdaa6818a6c6aa302bd18711059d3b2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}