libdrm: Use readdir instead of readdir_r to avoid build warnings
PATCH v2 1/1 libdrm: Use readdir instead of readdir_r to avoid build warnings
From: John Stultz <[email protected]>
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) {
^Building on Linux with glibc produces the same warning. Thus, this patch replaces readdir_r with readdir.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
--- xf86drm.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
xf86drm.c +3 -19
@@ -2822,12 +2822,11 @@ static char *drmGetMinorNameForFD(int fd, int type) {#ifdef __linux__DIR *sysdir; -struct dirent *pent, *ent; +struct dirent *ent;struct stat sbuf;const char *name =drmGetMinorName (type);int len;char dev_name[64 ], buf[64 ]; -long name_max;int maj, min;if (!name)
@@ -2850,30 +2849,16 @@ static char *drmGetMinorNameForFD(int fd, int type)if (!sysdir)return NULL ; - name_max =fpathconf (dirfd (sysdir), _PC_NAME_MAX); -if (name_max ==-1 ) - goto out_close_dir; - - pent =malloc (offsetof(struct dirent , d_name) + name_max +1 ); -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); -free (pent);closedir (sysdir); -return strdup (dev_name); } } - -free (pent); - -out_close_dir: -closedir (sysdir); +return NULL ;#else struct stat sbuf;char buf[PATH_MAX +1 ];
@@ -2914,7 +2899,6 @@ out_close_dir:return strdup (buf);#endif -return NULL ; }char *drmGetPrimaryDeviceNameFromFd (int fd)
Signature · 6 lines
2.16.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 11 lines · Emil Velikov
From: John Stultz <[email protected]>
Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated:readdir_ris deprecated; use readdir instead [-Wdeprecated-declarations]while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) { ^Building on Linux with glibc produces the same warning. Thus, this patch replaces
readdir_rwith readdir.Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
Quoted 9 lines
Cc Robert Foss <[email protected]>Cc Rob Herring <[email protected]>Cc Stefan Schake <[email protected]>Cc John Stultz <[email protected]>Cc Eric Engestrom <[email protected]>Signed-off-by John Stultz <[email protected]>Reviewed-by Emil Velikov <[email protected]>[Emil Velikov: remove unused variables, Eric]Signed-off-by Emil Velikov <[email protected]>
I think that's pretty much exactly the patch I have at home :) (and that I forgot to send out last night)
Quoted 42 lines
--- xf86drm.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)xf86drm.c +2
-12@@ -2822,12 +2822,11 @@ static char *drmGetMinorNameForFD(int fd, int type) {#ifdef __linux__DIR *sysdir; -struct dirent *pent, *ent; +struct dirent *ent;struct stat sbuf;const char *name =drmGetMinorName (type);int len;char dev_name[64 ], buf[64 ]; -long name_max;int maj, min;if (!name)@@ -2850,30 +2849,16 @@ static char *drmGetMinorNameForFD(int fd, int type)if (!sysdir)return NULL ; - name_max =fpathconf (dirfd (sysdir), _PC_NAME_MAX); -if (name_max ==-1 ) - goto out_close_dir; - - pent =malloc (offsetof(struct dirent , d_name) + name_max +1 ); -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); -free (pent);closedir (sysdir);
xf86drm.c static char *drmGetMinorNameForFD(int fd, int type) · line 2861
Quoted 10 lines
xf86drm.c +1
-6-return strdup (dev_name); } } - -free (pent); - -out_close_dir: -closedir (sysdir); +return NULL ;
This return and the hunk below are the one bit that I didn't have in my patch; it's unreachable on the other branch, so you're entirely right to move it!
Quoted 14 lines
xf86drm.c +0
-1#else struct stat sbuf;char buf[PATH_MAX +1 ];@@ -2914,7 +2899,6 @@ out_close_dir:return strdup (buf);#endif -return NULL ; }char *drmGetPrimaryDeviceNameFromFd (int fd)Signature · 1 line
2.16.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 22 lines · Eric Engestrom
Quoted 11 lines · Emil Velikov
From: John Stultz <[email protected]>
Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated:readdir_ris deprecated; use readdir instead [-Wdeprecated-declarations]while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) { ^Building on Linux with glibc produces the same warning. Thus, this patch replaces
readdir_rwith readdir.Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
Quoted 9 lines
Cc Robert Foss <[email protected]>Cc Rob Herring <[email protected]>Cc Stefan Schake <[email protected]>Cc John Stultz <[email protected]>Cc Eric Engestrom <[email protected]>Signed-off-by John Stultz <[email protected]>Reviewed-by Emil Velikov <[email protected]>[Emil Velikov: remove unused variables, Eric]Signed-off-by Emil Velikov <[email protected]>
Quoted 5 lines
I think that's pretty much exactly the patch I have at home :) (and that I forgot to send out last night)
Reviewed-by Eric Engestrom <[email protected]>
Thanks pushed to master.
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 23 lines · Emil Velikov
Quoted 22 lines · Eric Engestrom
Quoted 20 lines · Emil Velikov
From: John Stultz <[email protected]>
Building libdrm under AOSP, we see the following build warning:
external/libdrm/xf86drm.c:2861:12: warning: 'readdir_r' is deprecated:readdir_ris deprecated; use readdir instead [-Wdeprecated-declarations]while (readdir_r(sysdir, pent, &ent) == 0 && ent != NULL) { ^Building on Linux with glibc produces the same warning. Thus, this patch replaces
readdir_rwith readdir.Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102031
Cc Robert Foss <[email protected]>Cc Rob Herring <[email protected]>Cc Stefan Schake <[email protected]>Cc John Stultz <[email protected]>Cc Eric Engestrom <[email protected]>Signed-off-by John Stultz <[email protected]>Reviewed-by Emil Velikov <[email protected]>[Emil Velikov: remove unused variables, Eric]Signed-off-by Emil Velikov <[email protected]>
Quoted 6 lines
Quoted 5 lines
I think that's pretty much exactly the patch I have at home :) (and that I forgot to send out last night)
Reviewed-by Eric Engestrom <[email protected]>Thanks pushed to master.
Sorry again for the slow response here, but an after-the-fact thanks for sending out the much improved version!
I really appreciate it!
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel