From: Thomas Jarosch Date: Tue, 30 Dec 2025 08:54:15 +0000 (+0100) Subject: Replace deprecated readdir_r() with readdir() X-Git-Tag: v2.13~1^2~8 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=402cb5a1379a3392f73effe9e0155f5dd152ab52;p=libi2ncommon Replace deprecated readdir_r() with readdir() Original warnings: src/filefunc.cpp:318:21: error: 'int readdir_r(DIR*, dirent*, dirent**)' is deprecated [-Werror=deprecated-declarations] src/filefunc.cpp:360:21: error: 'int readdir_r(DIR*, dirent*, dirent**)' is deprecated [-Werror=deprecated-declarations] src/filefunc.cpp:362:27: error: the address of 'dirent::d_name' will never be NULL [-Werror=address] The readdir_r() function is deprecated in favor of readdir(), which is thread-safe on Linux with glibc since many years. I checked the glibc 2.17 source code and it uses a lock internally (and also traced it back to at least 2012). Also removed the unnecessary NULL check for d_name since it is never NULL per POSIX. --- diff --git a/src/filefunc.cpp b/src/filefunc.cpp index 9764521..fbb8903 100644 --- a/src/filefunc.cpp +++ b/src/filefunc.cpp @@ -314,8 +314,8 @@ bool get_dir( { return false; } - struct dirent store, *entry = NULL; - while (readdir_r(dir, &store, &entry) == 0 && entry != NULL) + struct dirent *entry = NULL; + while ((entry = readdir(dir)) != NULL) { std::string name( entry->d_name ); if (! include_dot_names && (name[0] == '.') ) @@ -356,12 +356,10 @@ int get_dir_count(const std::string& path, bool include_dot_names) DIR* dir = ::opendir( path.c_str()); if (!dir) return -1; - struct dirent store, *entry = NULL; - while (readdir_r(dir, &store, &entry) == 0 && entry != NULL) + struct dirent *entry = NULL; + while ((entry = readdir(dir)) != NULL) { - if (entry->d_name == NULL) - continue; // should not happen - else if (! include_dot_names && (entry->d_name)[0] == '.') + if (! include_dot_names && (entry->d_name)[0] == '.') continue; ++result; }