Skip to content

Commit

Permalink
loader: Fix getenv probing
Browse files Browse the repository at this point in the history
__GNUC__ depends on the compiler, not libc so the check is broken.
It's also better to check for features, not libc versions.

Fixes KhronosGroup#1538.
  • Loading branch information
Jussi Kukkonen committed Mar 9, 2017
1 parent f8aad33 commit 350116b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Expand Up @@ -303,6 +303,10 @@ if(NOT WIN32)
endif()

if(UNIX)
include(CheckFunctionExists)
CHECK_FUNCTION_EXISTS(secure_getenv HAVE_SECURE_GETENV)
CHECK_FUNCTION_EXISTS(__secure_getenv HAVE___SECURE_GETENV)

install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

Expand Down
17 changes: 7 additions & 10 deletions loader/loader.c
Expand Up @@ -199,20 +199,17 @@ static inline char *loader_getenv(const char *name, const struct loader_instance
// the inst pointer to get rid of compiler warnings.
(void)inst;

#if defined(__GNUC__)

// Before GLIBC 2.17, the function was __secure_getenv not secure_getenv
#if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 17))
return __secure_getenv(name);
#else
#ifdef HAVE_SECURE_GETENV
return secure_getenv(name);
#endif

// Other compilers don't support secure_getenv
#else
#ifdef HAVE___SECURE_GETENV
// Old Glibc only has __secure_getenv()
return __secure_getenv(name);
#else
// libc does not have any secure_getenv(), e.g. musl
return getenv(name);
#endif

#endif
}

static inline void loader_free_getenv(char *val, const struct loader_instance *inst) {
Expand Down

0 comments on commit 350116b

Please sign in to comment.