Fix the test for fsetxattr and strerror_r tests in CMake to work without compiling

This commit is contained in:
maxed 2018-03-31 13:17:45 +03:00 committed by Sergei Nikulov
parent aa18b573c8
commit 7e93637acd
2 changed files with 17 additions and 17 deletions

View File

@ -507,29 +507,29 @@ main ()
#ifdef HAVE_GLIBC_STRERROR_R #ifdef HAVE_GLIBC_STRERROR_R
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
void check(char c) {}
int int
main () { main () {
char buffer[1024]; /* big enough to play with */ char buffer[1024];
char *string = // This will not compile if strerror_r does not return a char*
strerror_r(EACCES, buffer, sizeof(buffer)); check(strerror_r(EACCES, buffer, sizeof(buffer))[0]);
/* this should've returned a string */
if(!string || !string[0])
return 99;
return 0; return 0;
} }
#endif #endif
#ifdef HAVE_POSIX_STRERROR_R #ifdef HAVE_POSIX_STRERROR_R
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
// float, because a pointer can't be implicitly cast to float
void check(float f) {}
int int
main () { main () {
char buffer[1024]; /* big enough to play with */ char buffer[1024];
int error = // This will not compile if strerror_r does not return an int
strerror_r(EACCES, buffer, sizeof(buffer)); check(strerror_r(EACCES, buffer, sizeof(buffer)));
/* This should've returned zero, and written an error string in the
buffer.*/
if(!buffer[0] || error)
return 99;
return 0; return 0;
} }
#endif #endif

View File

@ -902,7 +902,7 @@ endif()
check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR) check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
if(HAVE_FSETXATTR) if(HAVE_FSETXATTR)
foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6) foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
curl_internal_test_run(${CURL_TEST}) curl_internal_test(${CURL_TEST})
endforeach(CURL_TEST) endforeach(CURL_TEST)
endif(HAVE_FSETXATTR) endif(HAVE_FSETXATTR)
@ -982,7 +982,7 @@ foreach(CURL_TEST
HAVE_GLIBC_STRERROR_R HAVE_GLIBC_STRERROR_R
HAVE_POSIX_STRERROR_R HAVE_POSIX_STRERROR_R
) )
curl_internal_test_run(${CURL_TEST}) curl_internal_test(${CURL_TEST})
endforeach(CURL_TEST) endforeach(CURL_TEST)
# Check for reentrant # Check for reentrant