Subject: standards/33124: and POSIX compliance
To: None <standards-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <murray@river-styx.org>
List: netbsd-bugs
Date: 03/22/2006 06:30:01
>Number:         33124
>Category:       standards
>Synopsis:       <dirent.h> and POSIX compliance
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    standards-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 22 06:30:00 +0000 2006
>Originator:     Murray Armfield
>Release:        NetBSD-current
>Organization:
N/A
>Environment:
N/A
>Description:
NetBSD defines...
    int readdir_r(DIR *, struct dirent * __restrict,
        struct dirent ** __restrict) __RENAME(__readdir_r30);
in <dirent.h>

According to POSIX, the abovementioned thread safe functions first
parameter, DIR *, should be defined with __restrict.

Patches follow for include/dirent.h and lib/libc/compat/include/dirent.h
>How-To-Repeat:
Inspect /usr/include/dirent.h and POSIX standard.
>Fix:
--- include/dirent.h.orig       2006-01-25 06:33:35.000000000 +1100
+++ include/dirent.h
@@ -89,7 +89,7 @@ void rewinddir(DIR *);
 #ifndef __LIBC12_SOURCE__
 DIR *opendir(const char *) __RENAME(__opendir30);
 struct dirent *readdir(DIR *) __RENAME(__readdir30);
-int readdir_r(DIR *, struct dirent * __restrict,
+int readdir_r(DIR * __restrict, struct dirent * __restrict,
     struct dirent ** __restrict) __RENAME(__readdir_r30);
 #endif
 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)

--- lib/libc/compat/include/dirent.h.orig       2006-01-25 06:33:10.000000000 +1100
+++ lib/libc/compat/include/dirent.h
@@ -41,9 +41,9 @@ __BEGIN_DECLS
 DIR *opendir(const char *);
 DIR *__opendir30(const char *);

-int readdir_r(DIR *, struct dirent12 * __restrict,
+int readdir_r(DIR * __restrict, struct dirent12 * __restrict,
     struct dirent12 ** __restrict);
-int __readdir_r30(DIR *, struct dirent * __restrict,
+int __readdir_r30(DIR * __restrict, struct dirent * __restrict,
     struct dirent ** __restrict);

 struct dirent12 *readdir(DIR *);