Start of man-pages-5.14: renaming .Announce and .lsm files
[man-pages.git] / man2 / readdir.2
blobfde142413fb51434e26b253a0ad2466810337479
1 .\" Copyright (C) 1995 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Written 11 June 1995 by Andries Brouwer <aeb@cwi.nl>
26 .\" Modified 22 July 1995 by Michael Chastain <mec@duracef.shout.net>:
27 .\"   In 1.3.X, returns only one entry each time; return value is different.
28 .\" Modified 2004-12-01, mtk, fixed headers listed in SYNOPSIS
29 .\"
30 .TH READDIR 2  2021-03-22 "Linux" "Linux Programmer's Manual"
31 .SH NAME
32 readdir \- read directory entry
33 .SH SYNOPSIS
34 .nf
35 .BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
36 .B #include <unistd.h>
37 .PP
38 .BI "int syscall(SYS_readdir, unsigned int " fd ,
39 .BI "            struct old_linux_dirent *" dirp ", unsigned int " count );
40 .fi
41 .PP
42 .IR Note :
43 There is no definition of
44 .BR "struct old_linux_dirent" ;
45 see NOTES.
46 .SH DESCRIPTION
47 This is not the function you are interested in.
48 Look at
49 .BR readdir (3)
50 for the POSIX conforming C library interface.
51 This page documents the bare kernel system call interface,
52 which is superseded by
53 .BR getdents (2).
54 .PP
55 .BR readdir ()
56 reads one
57 .I old_linux_dirent
58 structure from the directory
59 referred to by the file descriptor
60 .I fd
61 into the buffer pointed to by
62 .IR dirp .
63 The argument
64 .I count
65 is ignored; at most one
66 .I old_linux_dirent
67 structure is read.
68 .PP
69 The
70 .I old_linux_dirent
71 structure is declared (privately in Linux kernel file
72 .BR fs/readdir.c )
73 as follows:
74 .PP
75 .in +4n
76 .EX
77 struct old_linux_dirent {
78     unsigned long d_ino;     /* inode number */
79     unsigned long d_offset;  /* offset to this \fIold_linux_dirent\fP */
80     unsigned short d_namlen; /* length of this \fId_name\fP */
81     char  d_name[1];         /* filename (null\-terminated) */
83 .EE
84 .in
85 .PP
86 .I d_ino
87 is an inode number.
88 .I d_offset
89 is the distance from the start of the directory to this
90 .IR old_linux_dirent .
91 .I d_reclen
92 is the size of
93 .IR d_name ,
94 not counting the terminating null byte (\(aq\e0\(aq).
95 .I d_name
96 is a null-terminated filename.
97 .SH RETURN VALUE
98 On success, 1 is returned.
99 On end of directory, 0 is returned.
100 On error, \-1 is returned, and
101 .I errno
102 is set to indicate the error.
103 .SH ERRORS
105 .B EBADF
106 Invalid file descriptor
107 .IR fd .
109 .B EFAULT
110 Argument points outside the calling process's address space.
112 .B EINVAL
113 Result buffer is too small.
115 .B ENOENT
116 No such directory.
118 .B ENOTDIR
119 File descriptor does not refer to a directory.
120 .SH CONFORMING TO
121 This system call is Linux-specific.
122 .SH NOTES
123 You will need to define the
124 .I old_linux_dirent
125 structure yourself.
126 However, probably you should use
127 .BR readdir (3)
128 instead.
130 This system call does not exist on x86-64.
131 .SH SEE ALSO
132 .BR getdents (2),
133 .BR readdir (3)