[PATCH libdrm v2] libdrm: Use readdir instead of readdir_r to avoid build warnings
Emil Velikov
emil.l.velikov at gmail.com
Tue Mar 20 17:48:23 UTC 2018
From: John Stultz <john.stultz at linaro.org>
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
Cc: Robert Foss <robert.foss at collabora.com>
Cc: Rob Herring <robh at kernel.org>
Cc: Stefan Schake <stschake at gmail.com>
Cc: John Stultz <john.stultz at linaro.org>
Cc: Eric Engestrom <eric.engestrom at imgtec.com>
Signed-off-by: John Stultz <john.stultz at linaro.org>
Reviewed-by: Emil Velikov <emil.velikov at collabora.com>
[Emil Velikov: remove unused variables, Eric]
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
xf86drm.c | 22 +++-------------------
1 file changed, 3 insertions(+), 19 deletions(-)
diff --git a/xf86drm.c b/xf86drm.c
index 9328bf5a..97f87e02 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -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)
--
2.16.0
More information about the dri-devel
mailing list