Skip to content

Commit 9f0c540

Browse files
authored
Define dirent d_type for Solaris based OS (#34263)
1 parent 5e6b441 commit 9f0c540

File tree

7 files changed

+38
-7
lines changed

7 files changed

+38
-7
lines changed

eng/native/configurecompiler.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,15 @@ endif(CLR_CMAKE_HOST_UNIX)
179179
if(CLR_CMAKE_HOST_LINUX)
180180
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
181181
add_link_options(-Wl,--build-id=sha1 -Wl,-z,relro,-z,now)
182-
endif(CLR_CMAKE_HOST_LINUX)
183-
if(CLR_CMAKE_HOST_FREEBSD)
182+
elseif(CLR_CMAKE_HOST_FREEBSD)
184183
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
185184
add_link_options(LINKER:--build-id=sha1)
186-
endif(CLR_CMAKE_HOST_FREEBSD)
185+
elseif(CLR_CMAKE_HOST_SUNOS)
186+
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include)
187+
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/local/lib)
188+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
189+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
190+
endif()
187191

188192
#------------------------------------
189193
# Definitions (for platform)

src/installer/corehost/cli/common.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ function(set_common_libs TargetType)
4040
target_link_libraries (${DOTNET_PROJECT_NAME} "pthread")
4141
endif()
4242

43-
if(CLR_CMAKE_TARGET_LINUX)
44-
target_link_libraries (${DOTNET_PROJECT_NAME} "dl")
45-
endif()
43+
target_link_libraries (${DOTNET_PROJECT_NAME} ${CMAKE_DL_LIBS})
4644
endif()
4745

4846
if (NOT ${TargetType} STREQUAL "lib-static")

src/installer/corehost/cli/hostmisc/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ project(hostmisc)
66

77
set(DOTNET_PROJECT_NAME "hostmisc")
88

9+
include(configure.cmake)
10+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
11+
912
# CMake does not recommend using globbing since it messes with the freshness checks
1013
set(SOURCES
1114
trace.cpp
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef _PAL_CONFIG_H_INCLUDED
2+
#define _PAL_CONFIG_H_INCLUDED 1
3+
4+
#cmakedefine01 HAVE_DIRENT_D_TYPE
5+
6+
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include(CheckStructHasMember)
2+
3+
check_struct_has_member("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE)
4+
5+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

src/installer/corehost/cli/hostmisc/pal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define xout std::cout
4747
#define DIR_SEPARATOR '/'
4848
#define PATH_SEPARATOR ':'
49+
#undef _X
4950
#define _X(s) s
5051

5152
#define S_OK 0x00000000

src/installer/corehost/cli/hostmisc/pal.unix.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <fnmatch.h>
1515
#include <ctime>
1616
#include <pwd.h>
17+
#include "config.h"
1718

1819
#if defined(TARGET_OSX)
1920
#include <mach-o/dyld.h>
@@ -27,6 +28,13 @@
2728
#define symlinkEntrypointExecutable "/proc/curproc/exe"
2829
#endif
2930

31+
#if !HAVE_DIRENT_D_TYPE
32+
#define DT_UNKNOWN 0
33+
#define DT_DIR 4
34+
#define DT_REG 8
35+
#define DT_LNK 10
36+
#endif
37+
3038
pal::string_t pal::to_string(int value) { return std::to_string(value); }
3139

3240
pal::string_t pal::to_lower(const pal::string_t& in)
@@ -821,8 +829,14 @@ static void readdir(const pal::string_t& path, const pal::string_t& pattern, boo
821829
continue;
822830
}
823831

832+
#if HAVE_DIRENT_D_TYPE
833+
int dirEntryType = entry->d_type;
834+
#else
835+
int dirEntryType = DT_UNKNOWN;
836+
#endif
837+
824838
// We are interested in files only
825-
switch (entry->d_type)
839+
switch (dirEntryType)
826840
{
827841
case DT_DIR:
828842
break;

0 commit comments

Comments
 (0)