[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/2] libxl: replace deprecated readdir_r() with readdir()



From: Chris Patterson <pattersonc@xxxxxxxxxxxx>

Replace the usage of readdir_r() with readdir() to address
a compilation error due to the deprecation of readdir_r.

glibc has deprecated this for their next release (2.24):
https://sourceware.org/bugzilla/show_bug.cgi?id=19056

This also removes the zalloc_dirent() helper function
which is no longer required.

Signed-off-by: Chris Patterson <pattersonc@xxxxxxxxxxxx>
---
 tools/libxl/libxl_pvusb.c | 26 ++++----------------------
 tools/libxl/libxl_utils.c |  9 ++-------
 2 files changed, 6 insertions(+), 29 deletions(-)

diff --git a/tools/libxl/libxl_pvusb.c b/tools/libxl/libxl_pvusb.c
index 9f1e842..d1397c4 100644
--- a/tools/libxl/libxl_pvusb.c
+++ b/tools/libxl/libxl_pvusb.c
@@ -508,19 +508,10 @@ int libxl_devid_to_device_usbctrl(libxl_ctx *ctx,
     return rc;
 }
 
-static void *zalloc_dirent(libxl__gc *gc, const char *dirpath)
-{
-    size_t need = offsetof(struct dirent, d_name) +
-                  pathconf(dirpath, _PC_NAME_MAX) + 1;
-
-    return libxl__zalloc(gc, need);
-}
-
 static char *usbdev_busaddr_to_busid(libxl__gc *gc, int bus, int addr)
 {
     DIR *dir;
     char *busid = NULL;
-    struct dirent *de_buf;
     struct dirent *de;
 
     /* invalid hostbus or hostaddr */
@@ -533,21 +524,17 @@ static char *usbdev_busaddr_to_busid(libxl__gc *gc, int 
bus, int addr)
         return NULL;
     }
 
-    de_buf = zalloc_dirent(gc, SYSFS_USB_DEV);
-
     for (;;) {
         char *filename;
         void *buf;
         int busnum = -1;
         int devnum = -1;
 
-        int r = readdir_r(dir, de_buf, &de);
-        if (r) {
+        de = readdir(dir);
+        if (!de) {
             LOGE(ERROR, "failed to readdir %s", SYSFS_USB_DEV);
             break;
         }
-        if (!de)
-            break;
 
         if (!strcmp(de->d_name, ".") ||
             !strcmp(de->d_name, ".."))
@@ -1157,7 +1144,6 @@ static int usbdev_get_all_interfaces(libxl__gc *gc, const 
char *busid,
 {
     DIR *dir;
     char *buf;
-    struct dirent *de_buf;
     struct dirent *de;
     int rc;
 
@@ -1172,18 +1158,14 @@ static int usbdev_get_all_interfaces(libxl__gc *gc, 
const char *busid,
         return ERROR_FAIL;
     }
 
-    de_buf = zalloc_dirent(gc, SYSFS_USB_DEV);
-
     for (;;) {
-        int r = readdir_r(dir, de_buf, &de);
+        de = readdir(dir);
 
-        if (r) {
+        if (!de) {
             LOGE(ERROR, "failed to readdir %s", SYSFS_USB_DEV);
             rc = ERROR_FAIL;
             goto out;
         }
-        if (!de)
-            break;
 
         if (!strcmp(de->d_name, ".") ||
             !strcmp(de->d_name, ".."))
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index ceb8825..613a9d6 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -548,20 +548,15 @@ int libxl__remove_directory(libxl__gc *gc, const char 
*dirpath)
         goto out;
     }
 
-    size_t need = offsetof(struct dirent, d_name) +
-        pathconf(dirpath, _PC_NAME_MAX) + 1;
-    struct dirent *de_buf = libxl__zalloc(gc, need);
     struct dirent *de;
 
     for (;;) {
-        int r = readdir_r(d, de_buf, &de);
-        if (r) {
+        de = readdir(d);
+        if (!de) {
             LOGE(ERROR, "failed to readdir %s for removal", dirpath);
             rc = ERROR_FAIL;
             break;
         }
-        if (!de)
-            break;
 
         if (!strcmp(de->d_name, ".") ||
             !strcmp(de->d_name, ".."))
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.