diff --git a/src/native/libs/System.Native/pal_io.c b/src/native/libs/System.Native/pal_io.c index 7062553570eea..4051656d35ac0 100644 --- a/src/native/libs/System.Native/pal_io.c +++ b/src/native/libs/System.Native/pal_io.c @@ -54,6 +54,10 @@ #endif #endif +#ifdef TARGET_SUNOS +#include +#endif + #ifdef _AIX #include // Somehow, AIX mangles the definition for this behind a C++ def @@ -436,10 +440,17 @@ static const size_t dirent_alignment = 8; int32_t SystemNative_GetReadDirRBufferSize(void) { #if HAVE_READDIR_R + size_t result = sizeof(struct dirent); +#ifdef TARGET_SUNOS + // The d_name array is declared with only a single byte in it. + // We have to add pathconf("dir", _PC_NAME_MAX) more bytes. + // MAXNAMELEN is the largest possible value returned from pathconf. + result += MAXNAMELEN; +#endif // dirent should be under 2k in size - assert(sizeof(struct dirent) < 2048); + assert(result < 2048); // add some extra space so we can align the buffer to dirent. - return sizeof(struct dirent) + dirent_alignment - 1; + return (int32_t)(result + dirent_alignment - 1); #else return 0; #endif