Debian Codegraph @

upstream/debian-unstable/man2/readdir.2

raw
1 .\" Copyright 1995, Andries E. Brouwer <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH readdir 2 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 readdir \- read directory entry
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ,\~ \-lc )
12 .SH SYNOPSIS
13 .nf
14 .BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
15 .B #include <unistd.h>
16 .P
17 .BI "int syscall(SYS_readdir, unsigned int " fd ,
18 .BI " struct old_linux_dirent *" dirp ", unsigned int " count );
19 .fi
20 .P
21 .IR Note :
22 There is no definition of
23 .BR "struct old_linux_dirent" ;
24 see VERSIONS.
25 .SH DESCRIPTION
26 This is not the function you are interested in.
27 Look at
28 .BR readdir (3)
29 for the POSIX conforming C library interface.
30 This page documents the bare kernel system call interface,
31 which is superseded by
32 .BR getdents (2).
33 .P
34 .BR readdir ()
35 reads one
36 .I old_linux_dirent
37 structure from the directory
38 referred to by the file descriptor
39 .I fd
40 into the buffer pointed to by
41 .IR dirp .
42 The argument
43 .I count
44 is ignored;
45 at most one
46 .I old_linux_dirent
47 structure is read.
48 .P
49 The
50 .I old_linux_dirent
51 structure is declared (privately in Linux kernel file
52 .BR fs/readdir.c )
53 as follows:
54 .P
55 .in +4n
56 .EX
57 struct old_linux_dirent {
58 unsigned long d_ino; /* inode number */
59 unsigned long d_offset; /* offset to this \f[I]old_linux_dirent\f[] */
60 unsigned short d_namlen; /* length of this \f[I]d_name\f[] */
61 char d_name[1]; /* filename (null\-terminated) */
62 }
63 .EE
64 .in
65 .P
66 .I d_ino
67 is an inode number.
68 .I d_offset
69 is the distance from the start of the directory to this
70 .IR old_linux_dirent .
71 .I d_reclen
72 is the size of
73 .IR d_name ,
74 not counting the terminating null byte (\[aq]\[rs]0\[aq]).
75 .I d_name
76 is a null-terminated filename.
77 .SH RETURN VALUE
78 On success, 1 is returned.
79 On end of directory, 0 is returned.
80 On error, \-1 is returned, and
81 .I errno
82 is set to indicate the error.
83 .SH ERRORS
84 .TP
85 .B EBADF
86 Invalid file descriptor
87 .IR fd .
88 .TP
89 .B EFAULT
90 Argument points outside the calling process's address space.
91 .TP
92 .B EINVAL
93 Result buffer is too small.
94 .TP
95 .B ENOENT
96 No such directory.
97 .TP
98 .B ENOTDIR
99 File descriptor does not refer to a directory.
100 .SH VERSIONS
101 You will need to define the
102 .I old_linux_dirent
103 structure yourself.
104 However, probably you should use
105 .BR readdir (3)
106 instead.
107 .P
108 This system call does not exist on x86-64.
109 .SH STANDARDS
110 Linux.
111 .SH SEE ALSO
112 .BR getdents (2),
113 .BR readdir (3)