1/* Copyright (C) 1991-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#include <errno.h>
19#include <stddef.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <dirent.h>
23
24
25static int
26test (const char *name)
27{
28 DIR *dirp;
29 struct dirent *entp;
30 int retval = 0;
31
32 puts (s: name);
33
34 dirp = opendir (name: name);
35 if (dirp == NULL)
36 {
37 perror ("opendir");
38 return 1;
39 }
40
41 errno = 0;
42 while ((entp = readdir (dirp: dirp)) != NULL)
43 printf (format: "%s\tfile number %lu\n",
44 entp->d_name, (unsigned long int) entp->d_fileno);
45
46 if (errno)
47 {
48 perror ("readdir");
49 retval = 1;
50 }
51
52 if (closedir (dirp: dirp) < 0)
53 {
54 perror ("closedir");
55 retval = 1;
56 }
57
58 return retval;
59}
60
61int
62main (int argc, char **argv)
63{
64 int retval = 0;
65 --argc;
66 ++argv;
67
68 if (argc == 0)
69 retval = test (name: ".");
70 else
71 while (argc-- > 0)
72 retval |= test (name: *argv++);
73
74 return retval;
75}
76

source code of glibc/dirent/list.c