Remove use of deprecated readdir_r
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 5 Jan 2017 16:09:55 +0000 (17:09 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Thu, 5 Jan 2017 16:11:36 +0000 (17:11 +0100)
Change-Id: I55bd335f1a731e3a02fdb598c8bd869686269aab
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afm-db.c
src/utils-dir.c

index 638713e..a15255b 100644 (file)
@@ -231,7 +231,7 @@ static int enumentries(struct enumdata *data, int (*callto)(struct enumdata *))
        DIR *dir;
        int rc;
        char *beg;
-       struct dirent entry, *e;
+       struct dirent *e;
        size_t len;
 
        /* opens the directory */
@@ -244,24 +244,28 @@ static int enumentries(struct enumdata *data, int (*callto)(struct enumdata *))
        *beg++ = '/';
 
        /* enumerate entries */
-       rc = readdir_r(dir, &entry, &e);
-       while (!rc && e) {
-               if (entry.d_name[0] != '.' || (entry.d_name[1]
-                       && (entry.d_name[1] != '.' || entry.d_name[2]))) {
+       for(;;) {
+               errno = 0;
+               e = readdir(dir);
+               if (!e) {
+                       rc = !errno - 1;
+                       break;
+               }
+               if (e->d_name[0] != '.' || (e->d_name[1]
+                       && (e->d_name[1] != '.' || e->d_name[2]))) {
                        /* prepare callto */
-                       len = strlen(entry.d_name);
+                       len = strlen(e->d_name);
                        if (beg + len >= data->path + sizeof data->path) {
                                errno = ENAMETOOLONG;
                                return -1;
                        }
-                       data->length = (int)(stpcpy(beg, entry.d_name)
+                       data->length = (int)(stpcpy(beg, e->d_name)
                                                                - data->path);
                        /* call the function */
                        rc = callto(data);
                        if (rc)
                                break;
                }       
-               rc = readdir_r(dir, &entry, &e);
        }
        closedir(dir);
        return rc;
index aef0a65..3c934fc 100644 (file)
@@ -33,10 +33,6 @@ static int clean_dirfd(int dirfd)
        int rc;
        DIR *dir;
        struct dirent *ent;
-       struct {
-               struct dirent entry;
-               char spare[PATH_MAX];
-       } entry;
 
        dir = fdopendir(dirfd);
        if (dir == NULL) {
@@ -45,10 +41,13 @@ static int clean_dirfd(int dirfd)
        }
        for (;;) {
                rc = -1;
-               if (readdir_r(dir, &entry.entry, &ent) != 0)
-                       goto error;
-               if (ent == NULL)
+               errno = 0;
+               ent = readdir(dir);
+               if (ent == NULL) {
+                       if (errno)
+                               goto error;
                        break;
+               }
                if (ent->d_name[0] == '.' && (ent->d_name[1] == 0
                                || (ent->d_name[1] == '.' && ent->d_name[2] == 0)))
                        continue;