]> git.ipfire.org Git - thirdparty/glibc.git/blame - dirent/list.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / dirent / list.c
CommitLineData
b168057a 1/* Copyright (C) 1991-2015 Free Software Foundation, Inc.
c84142e8 2 This file is part of the GNU C Library.
28f540f4 3
c84142e8 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4 8
c84142e8
UD
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
41bdb6e2 12 Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
28f540f4 17
28f540f4
RM
18#include <errno.h>
19#include <stddef.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <dirent.h>
23
24
de149cdb 25static int
c84142e8 26test (const char *name)
28f540f4
RM
27{
28 DIR *dirp;
29 struct dirent *entp;
80a18298 30 int retval = 0;
28f540f4 31
c84142e8 32 puts (name);
28f540f4 33
c84142e8 34 dirp = opendir (name);
28f540f4
RM
35 if (dirp == NULL)
36 {
c84142e8 37 perror ("opendir");
80a18298 38 return 1;
28f540f4
RM
39 }
40
41 errno = 0;
c84142e8
UD
42 while ((entp = readdir (dirp)) != NULL)
43 printf ("%s\tfile number %lu\n",
44 entp->d_name, (unsigned long int) entp->d_fileno);
28f540f4
RM
45
46 if (errno)
80a18298
UD
47 {
48 perror ("readdir");
49 retval = 1;
50 }
28f540f4 51
c84142e8 52 if (closedir (dirp) < 0)
80a18298
UD
53 {
54 perror ("closedir");
55 retval = 1;
56 }
57
58 return retval;
28f540f4
RM
59}
60
61int
c84142e8 62main (int argc, char **argv)
28f540f4 63{
80a18298 64 int retval = 0;
28f540f4
RM
65 --argc;
66 ++argv;
67
68 if (argc == 0)
80a18298 69 retval = test (".");
28f540f4
RM
70 else
71 while (argc-- > 0)
80a18298 72 retval |= test (*argv++);
28f540f4 73
80a18298 74 return retval;
28f540f4 75}