getdents.2: Remove unneeded HAVE_D_TYPE from example program

Since d_type will always just return DT_UNKNOWN before
kernel 2.6.4, we don't need to use a conditional for
determining whether we use this flag.

Reported-by: Bastien ROUCARIES <roucaries.bastien@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2009-01-22 20:56:50 +01:00
parent 14adeb6d28
commit 6197b465ef
1 changed files with 1 additions and 6 deletions

View File

@ -24,7 +24,7 @@
.\" Modified 22 July 1995 by Michael Chastain <mec@duracef.shout.net>:
.\" Derived from 'readdir.2'.
.\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
.TH GETDENTS 2 2009-01-19 "Linux" "Linux Programmer's Manual"
.TH GETDENTS 2 2009-01-23 "Linux" "Linux Programmer's Manual"
.SH NAME
getdents \- get directory entries
.SH SYNOPSIS
@ -191,7 +191,6 @@ i-node# file type d_reclen d_off d_name
.SS Program source
\&
.nf
#define HAVE_D_TYPE /* Remove for kernels < 2.6.4 */
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
@ -220,9 +219,7 @@ main(int argc, char *argv[])
char buf[BUF_SIZE];
struct linux_dirent *d;
int bpos;
#ifdef HAVE_D_TYPE
char d_type;
#endif
fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY);
if (fd == \-1)
@ -241,7 +238,6 @@ main(int argc, char *argv[])
for (bpos = 0; bpos < nread;) {
d = (struct linux_dirent *) (buf + bpos);
printf("%8ld ", d\->d_ino);
#ifdef HAVE_D_TYPE
d_type = *(buf + bpos + d\->d_reclen - 1);
printf("%\-10s ", (d_type == DT_REG) ? "regular" :
(d_type == DT_DIR) ? "directory" :
@ -250,7 +246,6 @@ main(int argc, char *argv[])
(d_type == DT_LNK) ? "symlink" :
(d_type == DT_BLK) ? "block dev" :
(d_type == DT_CHR) ? "char dev" : "???");
#endif
printf("%4d %10lld %s\\n", d\->d_reclen,
(long long) d\->d_off, (char *) d->d_name);
bpos += d\->d_reclen;