From ff19a05146e100456b30accb774001ac12a76f6b Mon Sep 17 00:00:00 2001 From: Aaron Brodersen 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(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