From: Arvin Schnell Date: Thu, 22 Nov 2018 08:49:03 +0000 (+0100) Subject: - avoid deprecated readdir_r X-Git-Tag: v0.8.1~1^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79b83896e9b54f4c2c8a33be6b62467257b0d06d;p=thirdparty%2Fsnapper.git - avoid deprecated readdir_r --- diff --git a/snapper/FileUtils.cc b/snapper/FileUtils.cc index 364dd590..7c8f2358 100644 --- a/snapper/FileUtils.cc +++ b/snapper/FileUtils.cc @@ -1,5 +1,6 @@ /* * Copyright (c) [2011-2014] Novell, Inc. + * Copyright (c) 2018 SUSE LLC * * All Rights Reserved. * @@ -198,6 +199,24 @@ namespace snapper vector ret; +#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 24))) + + // Since glibc 2.24 readdir is thread safe under certain + // condidtions, which apply here, and readdir_r is deprecated + // (see readdir(3)). + + struct dirent* ep = nullptr; + + rewinddir(dp); + while ((ep = readdir(dp)) != nullptr) + { + if (strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0 && + pred(ep->d_type, ep->d_name)) + ret.push_back(ep->d_name); + } + +#else + long sz = fpathconf(dirfd, _PC_NAME_MAX); if (sz == -1) sz = NAME_MAX; @@ -215,6 +234,8 @@ namespace snapper free(ep); +#endif + closedir(dp); return ret;