From: Sebastian Harl Date: Sun, 25 Sep 2016 18:49:43 +0000 (+0200) Subject: OS utils: Use readdir() instead of the now deprecated readdir_r(). X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2d74729ad602709cae9f48c96c2810ee0c5e340b;p=sysdb.git OS utils: Use readdir() instead of the now deprecated readdir_r(). Cf. https://sourceware.org/ml/libc-alpha/2016-02/msg00093.html --- diff --git a/src/utils/os.c b/src/utils/os.c index 8ab52c7..70142f7 100644 --- a/src/utils/os.c +++ b/src/utils/os.c @@ -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;