Skip to contentSkip to conversation

libdrm: Use readdir instead of readdir_r to avoid build warnings

PATCH In review John Stultz 3 participants 4 messages Mar 19, 2018 – Mar 20, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libdrm: Use readdir instead of readdir_r to avoid build warnings

Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]

    while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
           ^

Thus, this patch replaces readdir_r with readdir.

Cc Robert Foss <[email protected]>
Cc Rob Herring <[email protected]>
Cc Stefan Schake <[email protected]>
---
 xf86drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xf86drm.c +1 -1
index 344326d..b9058c2 100644
@@ -2858,7 +2858,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
     if (pent == NULL)
          goto out_close_dir;
 
-    while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
+    while ((ent = readdir(sysdir))) {
         if (strncmp(ent->d_name, name, len) == 0) {
             snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s",
                  ent->d_name);
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · John Stultz

Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]

    while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
           ^

Thus, this patch replaces readdir_r with readdir.

When C runtime suggests new behaviour before the manual/spec is updated... sigh.

readdir(3)
It is expected that a future version of POSIX.1 will require that readdir() be thread-safe when concurrently employed on different directory streams

readdir_r(3)
It is expected that a future version of POSIX.1 will make readdir_r() obsolete, and require that readdir(3) be thread-safe when concurrently employed on different directory streams.

Regardless, patch is

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
In reply to John Stultz
Quoted 20 lines · John Stultz

Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]

    while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
           ^

Thus, this patch replaces readdir_r with readdir.

Cc Robert Foss <[email protected]>
Cc Rob Herring <[email protected]>
Cc Stefan Schake <[email protected]>
---
 xf86drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xf86drm.c +0 -0
index 344326d..b9058c2 100644

xf86drm.c static char *drmGetMinorNameForFD(int fd, int type) · line 2861

Quoted 5 lines
xf86drm.c +1 -1
@@ -2858,7 +2858,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
     if (pent == NULL)
          goto out_close_dir;
 
-    while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
+    while ((ent = readdir(sysdir))) {

I've had the same patch locally for some time, and while this line is correct, it's missing other changes to clean up unnecessary code around.

I don't have the change on this machine, I'll look at it tonight, but if you beat me to it, from memory there's a malloc()+free() around, and a couple unused variables now that should be removed at the start of the scope.

Quoted 10 lines
xf86drm.c +0 -0
         if (strncmp(ent->d_name, name, len) == 0) {
             snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s",
                  ent->d_name);
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 30 lines · Eric Engestrom
Quoted 20 lines · John Stultz

Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated: readdir_r is deprecated; use readdir instead [-Wdeprecated-declarations]

    while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
           ^

Thus, this patch replaces readdir_r with readdir.

Cc Robert Foss <[email protected]>
Cc Rob Herring <[email protected]>
Cc Stefan Schake <[email protected]>
---
 xf86drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xf86drm.c +0 -0
index 344326d..b9058c2 100644

xf86drm.c static char *drmGetMinorNameForFD(int fd, int type) · line 2861

Quoted 5 lines
xf86drm.c +1 -1
@@ -2858,7 +2858,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
     if (pent == NULL)
          goto out_close_dir;
 
-    while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) {
+    while ((ent = readdir(sysdir))) {

I've had the same patch locally for some time, and while this line is correct, it's missing other changes to clean up unnecessary code around.

Quoted 5 lines

I don't have the change on this machine, I'll look at it tonight, but if you beat me to it, from memory there's a malloc()+free() around, and a couple unused variables now that should be removed at the start of the scope.

Right - updated patch should be in your inbox.

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel