Skip to content

Commit d73ba58

Browse files
authored
Merge pull request #72 from erikd/topic/readdir-deprecated
Don't use readdir_r if deprecated
2 parents cd6eae1 + 2951cd0 commit d73ba58

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cbits/HsUnix.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,30 @@ int __hsunix_push_module(int fd, const char *module)
3636
#endif
3737
}
3838

39+
/*
40+
* GNU glibc 2.23 and later deprecate `readdir_r` in favour of plain old
41+
* `readdir` which in some upcoming POSIX standard is going to required to be
42+
* re-entrant.
43+
* Eventually we want to drop `readder_r` all together, but want to be
44+
* compatible with older unixen which may not have a re-entrant `readdir`.
45+
* Solution is to make systems with *known* re-entrant `readir` use that and use
46+
* `readdir_r` whereever we have it and don't *know* that `readdir` is
47+
* re-entrant.
48+
*/
49+
50+
#if defined (__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 23)
51+
#define USE_READDIR_R 0
52+
#else
53+
#define USE_READDIR_R 1
54+
#endif
55+
3956
/*
4057
* read an entry from the directory stream; opt for the
4158
* re-entrant friendly way of doing this, if available.
4259
*/
4360
int __hscore_readdir( DIR *dirPtr, struct dirent **pDirEnt )
4461
{
45-
#if HAVE_READDIR_R
62+
#if HAVE_READDIR_R && USE_READDIR_R
4663
struct dirent* p;
4764
int res;
4865
static unsigned int nm_max = (unsigned int)-1;

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog for [`unix` package](http://hackage.haskell.org/package/unix)
22

3+
## 2.7.2.1 *Sep 2016*
4+
5+
* Don't use `readdir_r` if its deprecated.
6+
37
## 2.7.2.0 *Apr 2016*
48

59
* Bundled with GHC 8.0.1

0 commit comments

Comments
 (0)