Skip to content

Commit

Permalink
Define dirent d_type for Solaris based OS (#34263)
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 authored Apr 4, 2020
1 parent 5e6b441 commit 9f0c540
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
10 changes: 7 additions & 3 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,15 @@ endif(CLR_CMAKE_HOST_UNIX)
if(CLR_CMAKE_HOST_LINUX)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_link_options(-Wl,--build-id=sha1 -Wl,-z,relro,-z,now)
endif(CLR_CMAKE_HOST_LINUX)
if(CLR_CMAKE_HOST_FREEBSD)
elseif(CLR_CMAKE_HOST_FREEBSD)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_link_options(LINKER:--build-id=sha1)
endif(CLR_CMAKE_HOST_FREEBSD)
elseif(CLR_CMAKE_HOST_SUNOS)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/local/lib)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
endif()

#------------------------------------
# Definitions (for platform)
Expand Down
4 changes: 1 addition & 3 deletions src/installer/corehost/cli/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ function(set_common_libs TargetType)
target_link_libraries (${DOTNET_PROJECT_NAME} "pthread")
endif()

if(CLR_CMAKE_TARGET_LINUX)
target_link_libraries (${DOTNET_PROJECT_NAME} "dl")
endif()
target_link_libraries (${DOTNET_PROJECT_NAME} ${CMAKE_DL_LIBS})
endif()

if (NOT ${TargetType} STREQUAL "lib-static")
Expand Down
3 changes: 3 additions & 0 deletions src/installer/corehost/cli/hostmisc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ project(hostmisc)

set(DOTNET_PROJECT_NAME "hostmisc")

include(configure.cmake)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

# CMake does not recommend using globbing since it messes with the freshness checks
set(SOURCES
trace.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/installer/corehost/cli/hostmisc/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _PAL_CONFIG_H_INCLUDED
#define _PAL_CONFIG_H_INCLUDED 1

#cmakedefine01 HAVE_DIRENT_D_TYPE

#endif
5 changes: 5 additions & 0 deletions src/installer/corehost/cli/hostmisc/configure.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include(CheckStructHasMember)

check_struct_has_member("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
1 change: 1 addition & 0 deletions src/installer/corehost/cli/hostmisc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define xout std::cout
#define DIR_SEPARATOR '/'
#define PATH_SEPARATOR ':'
#undef _X
#define _X(s) s

#define S_OK 0x00000000
Expand Down
16 changes: 15 additions & 1 deletion src/installer/corehost/cli/hostmisc/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <fnmatch.h>
#include <ctime>
#include <pwd.h>
#include "config.h"

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

#if !HAVE_DIRENT_D_TYPE
#define DT_UNKNOWN 0
#define DT_DIR 4
#define DT_REG 8
#define DT_LNK 10
#endif

pal::string_t pal::to_string(int value) { return std::to_string(value); }

pal::string_t pal::to_lower(const pal::string_t& in)
Expand Down Expand Up @@ -821,8 +829,14 @@ static void readdir(const pal::string_t& path, const pal::string_t& pattern, boo
continue;
}

#if HAVE_DIRENT_D_TYPE
int dirEntryType = entry->d_type;
#else
int dirEntryType = DT_UNKNOWN;
#endif

// We are interested in files only
switch (entry->d_type)
switch (dirEntryType)
{
case DT_DIR:
break;
Expand Down

0 comments on commit 9f0c540

Please sign in to comment.