summarylogtreecommitdiffstats
path: root/readdir-corefx.patch
blob: 3d883607e1c5259d142d180de3cd7551e70da289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
From ff19a05146e100456b30accb774001ac12a76f6b Mon Sep 17 00:00:00 2001
From: Aaron Brodersen <aaron@abrodersen.com>
Date: Mon, 15 Aug 2016 10:32:33 -0500
Subject: [PATCH] Remove deprecated readdir_r invocation

Credit to sixpindin for the patch. This patch resolves this Github
issue: https://github.com/dotnet/corefx/issues/10712
---
 src/Native/System.Native/pal_io.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/Native/System.Native/pal_io.cpp b/src/Native/System.Native/pal_io.cpp
index 7da1bff..47d87d4 100644
--- a/src/Native/System.Native/pal_io.cpp
+++ b/src/Native/System.Native/pal_io.cpp
@@ -339,27 +339,27 @@ extern "C" int32_t SystemNative_ReadDirR(DIR* dir, void* buffer, int32_t bufferS
         return ERANGE;
     }
 
-    dirent* result = nullptr;
     dirent* entry = static_cast<dirent*>(buffer);
-    int error = readdir_r(dir, entry, &result);
 
-    // positive error number returned -> failure
-    if (error != 0)
+    errno = 0;
+    entry = readdir(dir);
+
+    // When an error is encountered, a null pointer shall be returned and errno shall be set to indicate the error.
+    if (entry == nullptr && errno != 0)
     {
-        assert(error > 0);
+        assert(errno > 0);
         *outputEntry = {}; // managed out param must be initialized
-        return error;
+        return errno;
     }
 
-    // 0 returned with null result -> end-of-stream
-    if (result == nullptr)
+    // When the end of the directory is encountered, a null pointer shall be returned and errno is not changed.
+    if (entry == nullptr)
     {
         *outputEntry = {}; // managed out param must be initialized
         return -1;         // shim convention for end-of-stream
     }
 
-    // 0 returned with non-null result (guaranteed to be set to entry arg) -> success
-    assert(result == entry);
+    // Upon successful completion, readdir() shall return a pointer to an object of type struct dirent.
     ConvertDirent(*entry, outputEntry);
     return 0;
 }
-- 
2.9.2