From 84a4f84c1c4d9f374f228e85f418a282004dd5b7 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sat, 22 Jun 2024 02:11:24 +0200 Subject: [PATCH] build: Don't check for required headers and functions Unless we are on Windows, the following POSIX headers are required. They're part of the earliest POSIX specs and it doesn't make sense to check for them. - fcntl.h - unistd.h - sys/stat.h - sys/time.h On Windows, io.h, fcntl.h and sys/stat.h are always available. --- CMakeLists.txt | 11 ----------- catalog.c | 46 ++++++++----------------------------------- config.h.cmake.in | 24 ---------------------- configure.ac | 7 ++----- dict.c | 4 +--- include/win32config.h | 4 ---- meson.build | 18 +++++++---------- nanohttp.c | 34 +++++++++++++++++--------------- runtest.c | 14 +++++++------ xmlIO.c | 28 ++++++++++---------------- xmllint.c | 34 +++++++++++++------------------- xzlib.c | 16 +++++++-------- 12 files changed, 75 insertions(+), 165 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 581588eb..b5c35a38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,8 +61,6 @@ option(LIBXML2_WITH_ZLIB "Use libz" OFF) set(LIBXML2_XMLCONF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Working directory for XML Conformance Test Suite") if(LIBXML2_WITH_PYTHON) - check_include_files(unistd.h HAVE_UNISTD_H) - check_symbol_exists(F_GETFL fcntl.h HAVE_F_GETFL) find_package(Python COMPONENTS Interpreter Development REQUIRED) #set(LIBXML2_PYTHON_INSTALL_DIR ${Python_SITEARCH} CACHE PATH "Python bindings install directory") set(LIBXML2_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/python" @@ -130,11 +128,7 @@ if (NOT MSVC) check_include_files(dlfcn.h HAVE_DLFCN_H) check_library_exists(dl dlopen "" HAVE_DLOPEN) check_include_files(dl.h HAVE_DL_H) - check_include_files(fcntl.h HAVE_FCNTL_H) - check_function_exists(fpclass HAVE_FPCLASS) - check_function_exists(ftime HAVE_FTIME) check_function_exists(getentropy HAVE_GETENTROPY) - check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) check_library_exists(history append_history "" HAVE_LIBHISTORY) check_library_exists(readline readline "" HAVE_LIBREADLINE) check_function_exists(mmap HAVE_MMAP) @@ -143,16 +137,11 @@ if (NOT MSVC) check_include_files(netinet/in.h HAVE_NETINET_IN_H) check_include_files(poll.h HAVE_POLL_H) check_library_exists(dld shl_load "" HAVE_SHLLOAD) - check_function_exists(stat HAVE_STAT) check_include_files(stdint.h HAVE_STDINT_H) check_include_files(sys/mman.h HAVE_SYS_MMAN_H) check_include_files(sys/random.h HAVE_SYS_RANDOM_H) check_include_files(sys/select.h HAVE_SYS_SELECT_H) check_include_files(sys/socket.h HAVE_SYS_SOCKET_H) - check_include_files(sys/stat.h HAVE_SYS_STAT_H) - check_include_files(sys/timeb.h HAVE_SYS_TIMEB_H) - check_include_files(sys/time.h HAVE_SYS_TIME_H) - check_include_files(unistd.h HAVE_UNISTD_H) endif() if(LIBXML2_WITH_TLS) diff --git a/catalog.c b/catalog.c index 1e704647..55ea301f 100644 --- a/catalog.c +++ b/catalog.c @@ -19,17 +19,16 @@ #include #include #include -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#elif defined (_WIN32) -#include -#endif -#ifdef HAVE_FCNTL_H + #include +#include + +#ifdef _WIN32 + #include +#else + #include #endif + #include #include #include @@ -937,62 +936,33 @@ xmlParseCatalogFile(const char *filename) { static xmlChar * xmlLoadFileContent(const char *filename) { -#ifdef HAVE_STAT int fd; -#else - FILE *fd; -#endif int len; long size; -#ifdef HAVE_STAT struct stat info; -#endif xmlChar *content; if (filename == NULL) return (NULL); -#ifdef HAVE_STAT if (stat(filename, &info) < 0) return (NULL); -#endif -#ifdef HAVE_STAT fd = open(filename, O_RDONLY); if (fd < 0) -#else - fd = fopen(filename, "rb"); - if (fd == NULL) -#endif { return (NULL); } -#ifdef HAVE_STAT size = info.st_size; -#else - if (fseek(fd, 0, SEEK_END) || (size = ftell(fd)) == EOF || fseek(fd, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */ - fclose(fd); - return (NULL); - } -#endif content = (xmlChar*)xmlMallocAtomic(size + 10); if (content == NULL) { xmlCatalogErrMemory(); -#ifdef HAVE_STAT close(fd); -#else - fclose(fd); -#endif return (NULL); } -#ifdef HAVE_STAT len = read(fd, content, size); close(fd); -#else - len = fread(content, 1, size, fd); - fclose(fd); -#endif if (len < 0) { xmlFree(content); return (NULL); diff --git a/config.h.cmake.in b/config.h.cmake.in index acc838c8..f31fc3b0 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -16,18 +16,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_DL_H 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_FCNTL_H 1 - -/* Define to 1 if you have the `ftime' function. */ -#cmakedefine HAVE_FTIME 1 - /* Define to 1 if you have the `getentropy' function. */ #cmakedefine HAVE_GETENTROPY 1 -/* Define to 1 if you have the `gettimeofday' function. */ -#cmakedefine HAVE_GETTIMEOFDAY 1 - /* Define if history library is there (-lhistory) */ #cmakedefine HAVE_LIBHISTORY 1 @@ -60,9 +51,6 @@ /* Have shl_load based dso */ #cmakedefine HAVE_SHLLOAD 1 -/* Define to 1 if you have the `stat' function. */ -#cmakedefine HAVE_STAT 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_STDINT_H 1 @@ -78,18 +66,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_SOCKET_H 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TIMEB_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_UNISTD_H 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_ZLIB_H 1 diff --git a/configure.ac b/configure.ac index 8a089de8..de70e705 100644 --- a/configure.ac +++ b/configure.ac @@ -285,16 +285,13 @@ dnl dnl Checks for header files. dnl AC_CHECK_HEADERS([stdint.h]) -AC_CHECK_HEADERS([fcntl.h unistd.h sys/stat.h]) -AC_CHECK_HEADERS([sys/mman.h]) -AC_CHECK_HEADERS([sys/time.h sys/timeb.h]) -AC_CHECK_HEADERS([sys/random.h]) +AC_CHECK_HEADERS([sys/mman.h sys/random.h]) AC_CHECK_HEADERS([dl.h dlfcn.h]) AC_CHECK_HEADERS([glob.h]) AM_CONDITIONAL(WITH_GLOB, test "$ac_cv_header_glob_h" = "yes") dnl Checks for library functions. -AC_CHECK_FUNCS([getentropy gettimeofday ftime stat mmap munmap]) +AC_CHECK_FUNCS([getentropy mmap munmap]) AH_VERBATIM([HAVE_MUNMAP_AFTER],[/* mmap() is no good without munmap() */ #if defined(HAVE_MMAP) && !defined(HAVE_MUNMAP) diff --git a/dict.c b/dict.c index 49e1c6bf..a0dc8567 100644 --- a/dict.c +++ b/dict.c @@ -929,9 +929,7 @@ xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name) { #include #include #elif defined(HAVE_GETENTROPY) - #ifdef HAVE_UNISTD_H - #include - #endif + #include #ifdef HAVE_SYS_RANDOM_H #include #endif diff --git a/include/win32config.h b/include/win32config.h index a25e0385..edd87633 100644 --- a/include/win32config.h +++ b/include/win32config.h @@ -1,10 +1,6 @@ #ifndef __LIBXML_WIN32_CONFIG__ #define __LIBXML_WIN32_CONFIG__ -#define HAVE_SYS_STAT_H -#define HAVE_STAT -#define HAVE_FCNTL_H - #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER >= 1600) #define HAVE_STDINT_H #endif diff --git a/meson.build b/meson.build index d638de97..3cab6916 100644 --- a/meson.build +++ b/meson.build @@ -234,21 +234,19 @@ config_h.set_quoted('LOCALEDIR', dir_locale) # header files xml_check_headers = [ 'stdint.h', - 'fcntl.h', - 'unistd.h', - 'sys/stat.h', 'sys/mman.h', + 'sys/random.h', + 'dl.h', + 'dlfcn.h', + 'glob.h', + + # http 'sys/socket.h', 'netinet/in.h', 'arpa/inet.h', 'netdb.h', 'sys/select.h', 'poll.h', - 'sys/time.h', - 'sys/timeb.h', - 'dl.h', - 'dlfcn.h', - 'glob.h', ] foreach header : xml_check_headers @@ -260,9 +258,7 @@ endforeach # library functions xml_check_functions = [ # fct | header - ['gettimeofday', 'sys/time.h'], - ['ftime', 'sys/timeb.h'], - ['stat', 'sys/stat.h'], + ['getentropy', 'sys/random.h'], ['mmap', 'sys/mman.h'], ['munmap', 'sys/mman.h'], ] diff --git a/nanohttp.c b/nanohttp.c index 2bd3727e..21aabafc 100644 --- a/nanohttp.c +++ b/nanohttp.c @@ -20,11 +20,19 @@ #include #include -#ifdef HAVE_UNISTD_H -#include -#elif defined (_WIN32) +#include + +#ifdef _WIN32 + #include -#endif +#include +#define XML_SOCKLEN_T int + +#else /* _WIN32 */ + +#include +#include + #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -40,12 +48,6 @@ #define SUPPORT_IP6 #endif #endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #ifndef HAVE_POLL_H #ifdef HAVE_SYS_SELECT_H #include @@ -53,20 +55,20 @@ #else #include #endif -#ifdef LIBXML_ZLIB_ENABLED -#include -#endif #ifdef VMS #include #define XML_SOCKLEN_T unsigned int -#elif defined(_WIN32) - #include - #define XML_SOCKLEN_T int #else #define XML_SOCKLEN_T socklen_t #endif +#endif /* _WIN32 */ + +#ifdef LIBXML_ZLIB_ENABLED +#include +#endif + #include #include #include /* for xmlStr(n)casecmp() */ diff --git a/runtest.c b/runtest.c index cfbbd9bb..33e50434 100644 --- a/runtest.c +++ b/runtest.c @@ -16,15 +16,17 @@ #include "libxml.h" #include -#ifdef HAVE_UNISTD_H -#include -#elif defined (_WIN32) -#include -#endif #include #include -#include + #include +#include + +#ifdef _WIN32 + #include +#else + #include +#endif #include #include diff --git a/xmlIO.c b/xmlIO.c index ac2cf0d2..96815cbc 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -13,15 +13,18 @@ #include #include -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_FCNTL_H #include +#include + +#if defined(_WIN32) + #define WIN32_LEAN_AND_MEAN + #include + #include + #include +#else + #include #endif -#ifdef HAVE_UNISTD_H -#include -#endif + #ifdef LIBXML_ZLIB_ENABLED #include #endif @@ -29,13 +32,6 @@ #include #endif -#if defined(_WIN32) -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -#endif - #include #include #include @@ -363,19 +359,16 @@ xmlNormalizeWindowsPath(const xmlChar *path) int xmlCheckFilename(const char *path) { -#ifdef HAVE_STAT #if defined(_WIN32) struct _stat stat_buffer; #else struct stat stat_buffer; #endif int res; -#endif if (path == NULL) return(0); -#ifdef HAVE_STAT #if defined(_WIN32) { wchar_t *wpath; @@ -405,7 +398,6 @@ xmlCheckFilename(const char *path) if (S_ISDIR(stat_buffer.st_mode)) return 2; #endif -#endif /* HAVE_STAT */ return 1; } diff --git a/xmllint.c b/xmllint.c index bba83b23..65ca4236 100644 --- a/xmllint.c +++ b/xmllint.c @@ -17,29 +17,23 @@ #include #include -#ifdef HAVE_SYS_TIME_H -#include -#endif -#ifdef HAVE_SYS_TIMEB_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_FCNTL_H #include +#include + +#ifdef _WIN32 + #include + #include +#else + #include + #include #endif -#ifdef HAVE_UNISTD_H -#include -#elif defined (_WIN32) -#include -#endif + #ifdef HAVE_SYS_MMAN_H -#include -/* seems needed for Solaris */ -#ifndef MAP_FAILED -#define MAP_FAILED ((void *) -1) -#endif + #include + /* seems needed for Solaris */ + #ifndef MAP_FAILED + #define MAP_FAILED ((void *) -1) + #endif #endif #include diff --git a/xzlib.c b/xzlib.c index 0d6e6384..f3b05393 100644 --- a/xzlib.c +++ b/xzlib.c @@ -14,17 +14,15 @@ #include #include -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_FCNTL_H #include +#include + +#ifdef _WIN32 + #include +#else + #include #endif -#ifdef HAVE_UNISTD_H -#include -#elif defined (_WIN32) -#include -#endif + #ifdef LIBXML_ZLIB_ENABLED #include #endif