Skip to content

Commit d549de7

Browse files
committed
libc: Remove readdir_r(3)
This function was never safe to use. We marked it deprecated in the manual page in 2016, and it is marked obsolete in POSIX 2024. We previously added a linker warning and annotated the prototype; now that stable/15 has been branched, we can remove it from main. Relnotes: yes Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D52474
1 parent c1532f7 commit d549de7

File tree

9 files changed

+13
-61
lines changed

9 files changed

+13
-61
lines changed

ObsoleteFiles.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
# xargs -n1 | sort | uniq -d;
5252
# done
5353

54+
# 20250910: readdir_r(3) removed
55+
OLD_FILES+=usr/share/man/man3/readdir_r.3.gz
56+
5457
# 20250826: Remove a misspelled manual
5558
OLD_FILES+=usr/share/man/man3/sysdecode_syscallnames.3.gz
5659

include/dirent.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ DIR *opendir(const char *);
115115
DIR *fdopendir(int);
116116
struct dirent *
117117
readdir(DIR *);
118-
#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500
119-
int readdir_r(DIR *, struct dirent *, struct dirent **)
120-
__deprecated1("Does not take variable {NAME_MAX} into account");
121-
#endif
122118
void rewinddir(DIR *);
123119
#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
124120
int scandir(const char *, struct dirent ***,

lib/libc/gen/Makefile.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ MLINKS+=directory.3 closedir.3 \
342342
directory.3 fdopendir.3 \
343343
directory.3 opendir.3 \
344344
directory.3 readdir.3 \
345-
directory.3 readdir_r.3 \
346345
directory.3 rewinddir.3 \
347346
directory.3 seekdir.3 \
348347
directory.3 telldir.3

lib/libc/gen/Symbol.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ FBSD_1.5 {
418418
globfree;
419419
nftw;
420420
readdir;
421-
readdir_r;
422421
scandir;
423422
sem_clockwait_np;
424423
setproctitle_fast;

lib/libc/gen/directory.3

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd August 1, 2020
28+
.Dd September 5, 2025
2929
.Dt DIRECTORY 3
3030
.Os
3131
.Sh NAME
3232
.Nm opendir ,
3333
.Nm fdopendir ,
3434
.Nm readdir ,
35-
.Nm readdir_r ,
3635
.Nm telldir ,
3736
.Nm seekdir ,
3837
.Nm rewinddir ,
@@ -50,8 +49,6 @@
5049
.Fn fdopendir "int fd"
5150
.Ft struct dirent *
5251
.Fn readdir "DIR *dirp"
53-
.Ft int
54-
.Fn readdir_r "DIR *dirp" "struct dirent *entry" "struct dirent **result"
5552
.Ft long
5653
.Fn telldir "DIR *dirp"
5754
.Ft void
@@ -65,15 +62,6 @@
6562
.Ft int
6663
.Fn dirfd "DIR *dirp"
6764
.Sh DESCRIPTION
68-
.Bf -symbolic
69-
The
70-
.Fn readdir_r
71-
interface is deprecated
72-
because it cannot be used correctly unless
73-
.Brq Va NAME_MAX
74-
is a fixed value.
75-
.Ef
76-
.Pp
7765
The
7866
.Fn opendir
7967
function
@@ -112,7 +100,6 @@ or to modify the state of the associated description other than by means
112100
of
113101
.Fn closedir ,
114102
.Fn readdir ,
115-
.Fn readdir_r ,
116103
or
117104
.Fn rewinddir ,
118105
the behavior is undefined.
@@ -144,34 +131,6 @@ may be set to any of the values documented for the
144131
system call.
145132
.Pp
146133
The
147-
.Fn readdir_r
148-
function
149-
provides the same functionality as
150-
.Fn readdir ,
151-
but the caller must provide a directory
152-
.Fa entry
153-
buffer to store the results in.
154-
The buffer must be large enough for a
155-
.Vt struct dirent
156-
with a
157-
.Va d_name
158-
array with
159-
.Brq Va NAME_MAX
160-
+ 1 elements.
161-
If the read succeeds,
162-
.Fa result
163-
is pointed at the
164-
.Fa entry ;
165-
upon reaching the end of the directory
166-
.Fa result
167-
is set to
168-
.Dv NULL .
169-
The
170-
.Fn readdir_r
171-
function
172-
returns 0 on success or an error number to indicate failure.
173-
.Pp
174-
The
175134
.Fn telldir
176135
function
177136
returns a token representing the current location associated with the named
@@ -305,9 +264,7 @@ is not associated with a directory.
305264
.Pp
306265
The
307266
.Fn readdir
308-
and
309-
.Fn readdir_r
310-
functions may also fail and set
267+
function may also fail and set
311268
.Va errno
312269
for any of the errors specified for the routine
313270
.Xr getdents 2 .
@@ -338,7 +295,6 @@ The
338295
.Fn fdopendir ,
339296
.Fn opendir ,
340297
.Fn readdir ,
341-
.Fn readdir_r ,
342298
.Fn rewinddir ,
343299
.Fn seekdir
344300
and
@@ -391,7 +347,8 @@ will always set the correct location to return the same value as that last
391347
.Fn readdir
392348
performed.
393349
This is enough for some applications which want to
394-
"push back the last entry read", e.g., Samba.
350+
.Dq push back the last entry read ,
351+
e.g. Samba.
395352
Seeks back to any other location,
396353
other than the beginning of the directory,
397354
may result in unexpected behaviour if deletes are present.

lib/libc/gen/gen-compat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct freebsd11_dirent;
3737
struct freebsd11_stat;
3838
struct freebsd11_statfs;
3939

40+
int freebsd15_readdir_r(DIR *, struct dirent *, struct dirent **);
4041
struct freebsd11_dirent *freebsd11_readdir(DIR *);
4142
int freebsd11_readdir_r(DIR *, struct freebsd11_dirent *,
4243
struct freebsd11_dirent **);

lib/libc/gen/gen-private.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,4 @@ struct _dirdesc {
6060

6161
#define _dirfd(dirp) ((dirp)->dd_fd)
6262

63-
struct dirent;
64-
int __readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
65-
6663
#endif /* !_GEN_PRIVATE_H_ */

lib/libc/gen/readdir-compat11.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ freebsd11_readdir_r(DIR *dirp, struct freebsd11_dirent *entry,
9595
struct dirent xentry, *xresult;
9696
int error;
9797

98-
error = __readdir_r(dirp, &xentry, &xresult);
98+
error = freebsd15_readdir_r(dirp, &xentry, &xresult);
9999
if (error != 0)
100100
return (error);
101101
if (xresult != NULL) {

lib/libc/gen/readdir.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "gen-private.h"
4242
#include "telldir.h"
4343

44+
#include "gen-compat.h"
45+
4446
/*
4547
* get next entry in a directory.
4648
*/
@@ -104,7 +106,7 @@ readdir(DIR *dirp)
104106
}
105107

106108
int
107-
__readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
109+
freebsd15_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
108110
{
109111
struct dirent *dp;
110112
int saved_errno;
@@ -133,6 +135,4 @@ __readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
133135
return (0);
134136
}
135137

136-
__strong_reference(__readdir_r, readdir_r);
137-
__warn_references(readdir_r,
138-
"warning: this program uses readdir_r(), which is unsafe.");
138+
__sym_compat(readdir_r, freebsd15_readdir_r, FBSD_1.5);

0 commit comments

Comments
 (0)