[commit: packages/unix] bgamari-patch-1, master, readdirstream-maybe-patch: Don't use readdir_r if deprecated (2951cd0)

git at git.haskell.org git at git.haskell.org
Wed Jul 19 22:04:18 UTC 2017


Repository : ssh://git@git.haskell.org/unix

On branches: bgamari-patch-1,master,readdirstream-maybe-patch
Link       : http://ghc.haskell.org/trac/ghc/changeset/2951cd01a725c52afc6bf6a83c068cfb40504fdf/unix

>---------------------------------------------------------------

commit 2951cd01a725c52afc6bf6a83c068cfb40504fdf
Author: Erik de Castro Lopo <erikd at mega-nerd.com>
Date:   Tue Sep 6 19:34:40 2016 +1000

    Don't use readdir_r if deprecated
    
    GNU glibc 2.23 and later deprecate `readdir_r` in favour of plain old
    `readdir` which in some upcoming POSIX standard is going to required to be
    re-entrant.
    
    Eventually we want to drop `readder_r` all together, but want to be
    compatible with older unixen which may not have a re-entrant `readdir`.
    
    Solution is to make systems with *known* re-entrant `readir` use that and
    use `readdir_r` whereever we have it and don't *know* that `readdir` is
    re-entrant.
    
    Closes: https://github.com/haskell/unix/issues/70


>---------------------------------------------------------------

2951cd01a725c52afc6bf6a83c068cfb40504fdf
 cbits/HsUnix.c | 19 ++++++++++++++++++-
 changelog.md   |  4 ++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/cbits/HsUnix.c b/cbits/HsUnix.c
index bdd1e80..08cccd5 100644
--- a/cbits/HsUnix.c
+++ b/cbits/HsUnix.c
@@ -37,12 +37,29 @@ int __hsunix_push_module(int fd, const char *module)
 }
 
 /*
+ * GNU glibc 2.23 and later deprecate `readdir_r` in favour of plain old
+ * `readdir` which in some upcoming POSIX standard is going to required to be
+ * re-entrant.
+ * Eventually we want to drop `readder_r` all together, but want to be
+ * compatible with older unixen which may not have a re-entrant `readdir`.
+ * Solution is to make systems with *known* re-entrant `readir` use that and use
+ * `readdir_r` whereever we have it and don't *know* that `readdir` is
+ * re-entrant.
+ */
+
+#if defined (__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 23)
+#define USE_READDIR_R 0
+#else
+#define USE_READDIR_R 1
+#endif
+
+/*
  * read an entry from the directory stream; opt for the
  * re-entrant friendly way of doing this, if available.
  */
 int __hscore_readdir( DIR *dirPtr, struct dirent **pDirEnt )
 {
-#if HAVE_READDIR_R
+#if HAVE_READDIR_R && USE_READDIR_R
   struct dirent* p;
   int res;
   static unsigned int nm_max = (unsigned int)-1;
diff --git a/changelog.md b/changelog.md
index eb429cb..4bbeeb3 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,9 @@
 # Changelog for [`unix` package](http://hackage.haskell.org/package/unix)
 
+## 2.7.2.1  *Sep 2016*
+
+  * Don't use `readdir_r` if its deprecated.
+
 ## 2.7.2.0  *Apr 2016*
 
   * Bundled with GHC 8.0.1



More information about the ghc-commits mailing list