]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- avoid deprecated readdir_r
authorArvin Schnell <aschnell@suse.de>
Thu, 22 Nov 2018 08:49:03 +0000 (09:49 +0100)
committerArvin Schnell <aschnell@suse.de>
Thu, 22 Nov 2018 08:49:03 +0000 (09:49 +0100)
snapper/FileUtils.cc

index 364dd590d49518f461a7a14e3b2a0434c05f6e01..7c8f23587841e5109fd39f2f1b837adfcef4c482 100644 (file)
@@ -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<string> 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;