Code

OS utils: Use readdir() instead of the now deprecated readdir_r().
authorSebastian Harl <sh@tokkee.org>
Sun, 25 Sep 2016 18:49:43 +0000 (20:49 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 25 Sep 2016 18:49:43 +0000 (20:49 +0200)
Cf. https://sourceware.org/ml/libc-alpha/2016-02/msg00093.html

src/utils/os.c

index 8ab52c75bc023c2bc5b68ca61d2cc0f13ce0f916..70142f7ba8d6ab093bf907e38e47cc8e8ae30159 100644 (file)
@@ -172,26 +172,25 @@ sdb_remove_all(const char *pathname)
                        return -1;
 
                while (42) {
-                       struct dirent de;
-                       struct dirent *res = NULL;
+                       struct dirent *de;
+                       char filename[strlen(pathname) + sizeof(de->d_name) + 2];
 
-                       char filename[strlen(pathname) + sizeof(de.d_name) + 2];
+                       errno = 0;
+                       de = readdir(d);
+                       if (! de) {
+                               if (errno == 0)
+                                       break;
 
-                       memset(&de, 0, sizeof(de));
-                       if (readdir_r(d, &de, &res)) {
                                closedir(d);
                                return -1;
                        }
 
-                       if (! res)
-                               break;
-
-                       if ((de.d_name[0] == '.') && ((de.d_name[1] == '\0')
-                                               || ((de.d_name[1] == '.')&& (de.d_name[2] == '\0'))))
+                       if ((de->d_name[0] == '.') && ((de->d_name[1] == '\0')
+                                               || ((de->d_name[1] == '.')&& (de->d_name[2] == '\0'))))
                                continue;
 
                        snprintf(filename, sizeof(filename),
-                                       "%s/%s", pathname, de.d_name);
+                                       "%s/%s", pathname, de->d_name);
                        if (sdb_remove_all(filename)) {
                                closedir(d);
                                return -1;