1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

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.
This commit is contained in:
Nick Wellnhofer 2024-06-22 02:11:24 +02:00
parent f23fc4faed
commit 84a4f84c1c
12 changed files with 75 additions and 165 deletions

View File

@ -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") set(LIBXML2_XMLCONF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Working directory for XML Conformance Test Suite")
if(LIBXML2_WITH_PYTHON) 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) 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 ${Python_SITEARCH} CACHE PATH "Python bindings install directory")
set(LIBXML2_PYTHON_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/python" 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_include_files(dlfcn.h HAVE_DLFCN_H)
check_library_exists(dl dlopen "" HAVE_DLOPEN) check_library_exists(dl dlopen "" HAVE_DLOPEN)
check_include_files(dl.h HAVE_DL_H) 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(getentropy HAVE_GETENTROPY)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
check_library_exists(history append_history "" HAVE_LIBHISTORY) check_library_exists(history append_history "" HAVE_LIBHISTORY)
check_library_exists(readline readline "" HAVE_LIBREADLINE) check_library_exists(readline readline "" HAVE_LIBREADLINE)
check_function_exists(mmap HAVE_MMAP) 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(netinet/in.h HAVE_NETINET_IN_H)
check_include_files(poll.h HAVE_POLL_H) check_include_files(poll.h HAVE_POLL_H)
check_library_exists(dld shl_load "" HAVE_SHLLOAD) 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(stdint.h HAVE_STDINT_H)
check_include_files(sys/mman.h HAVE_SYS_MMAN_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/random.h HAVE_SYS_RANDOM_H)
check_include_files(sys/select.h HAVE_SYS_SELECT_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/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() endif()
if(LIBXML2_WITH_TLS) if(LIBXML2_WITH_TLS)

View File

@ -19,17 +19,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#elif defined (_WIN32)
#include <io.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif #endif
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/hash.h> #include <libxml/hash.h>
#include <libxml/uri.h> #include <libxml/uri.h>
@ -937,62 +936,33 @@ xmlParseCatalogFile(const char *filename) {
static xmlChar * static xmlChar *
xmlLoadFileContent(const char *filename) xmlLoadFileContent(const char *filename)
{ {
#ifdef HAVE_STAT
int fd; int fd;
#else
FILE *fd;
#endif
int len; int len;
long size; long size;
#ifdef HAVE_STAT
struct stat info; struct stat info;
#endif
xmlChar *content; xmlChar *content;
if (filename == NULL) if (filename == NULL)
return (NULL); return (NULL);
#ifdef HAVE_STAT
if (stat(filename, &info) < 0) if (stat(filename, &info) < 0)
return (NULL); return (NULL);
#endif
#ifdef HAVE_STAT
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd < 0) if (fd < 0)
#else
fd = fopen(filename, "rb");
if (fd == NULL)
#endif
{ {
return (NULL); return (NULL);
} }
#ifdef HAVE_STAT
size = info.st_size; 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); content = (xmlChar*)xmlMallocAtomic(size + 10);
if (content == NULL) { if (content == NULL) {
xmlCatalogErrMemory(); xmlCatalogErrMemory();
#ifdef HAVE_STAT
close(fd); close(fd);
#else
fclose(fd);
#endif
return (NULL); return (NULL);
} }
#ifdef HAVE_STAT
len = read(fd, content, size); len = read(fd, content, size);
close(fd); close(fd);
#else
len = fread(content, 1, size, fd);
fclose(fd);
#endif
if (len < 0) { if (len < 0) {
xmlFree(content); xmlFree(content);
return (NULL); return (NULL);

View File

@ -16,18 +16,9 @@
/* Define to 1 if you have the <dl.h> header file. */ /* Define to 1 if you have the <dl.h> header file. */
#cmakedefine HAVE_DL_H 1 #cmakedefine HAVE_DL_H 1
/* Define to 1 if you have the <fcntl.h> 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. */ /* Define to 1 if you have the `getentropy' function. */
#cmakedefine HAVE_GETENTROPY 1 #cmakedefine HAVE_GETENTROPY 1
/* Define to 1 if you have the `gettimeofday' function. */
#cmakedefine HAVE_GETTIMEOFDAY 1
/* Define if history library is there (-lhistory) */ /* Define if history library is there (-lhistory) */
#cmakedefine HAVE_LIBHISTORY 1 #cmakedefine HAVE_LIBHISTORY 1
@ -60,9 +51,6 @@
/* Have shl_load based dso */ /* Have shl_load based dso */
#cmakedefine HAVE_SHLLOAD 1 #cmakedefine HAVE_SHLLOAD 1
/* Define to 1 if you have the `stat' function. */
#cmakedefine HAVE_STAT 1
/* Define to 1 if you have the <stdint.h> header file. */ /* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H 1 #cmakedefine HAVE_STDINT_H 1
@ -78,18 +66,6 @@
/* Define to 1 if you have the <sys/socket.h> header file. */ /* Define to 1 if you have the <sys/socket.h> header file. */
#cmakedefine HAVE_SYS_SOCKET_H 1 #cmakedefine HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/timeb.h> header file. */
#cmakedefine HAVE_SYS_TIMEB_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1
/* Define to 1 if you have the <zlib.h> header file. */ /* Define to 1 if you have the <zlib.h> header file. */
#cmakedefine HAVE_ZLIB_H 1 #cmakedefine HAVE_ZLIB_H 1

View File

@ -285,16 +285,13 @@ dnl
dnl Checks for header files. dnl Checks for header files.
dnl dnl
AC_CHECK_HEADERS([stdint.h]) AC_CHECK_HEADERS([stdint.h])
AC_CHECK_HEADERS([fcntl.h unistd.h sys/stat.h]) AC_CHECK_HEADERS([sys/mman.h sys/random.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([dl.h dlfcn.h]) AC_CHECK_HEADERS([dl.h dlfcn.h])
AC_CHECK_HEADERS([glob.h]) AC_CHECK_HEADERS([glob.h])
AM_CONDITIONAL(WITH_GLOB, test "$ac_cv_header_glob_h" = "yes") AM_CONDITIONAL(WITH_GLOB, test "$ac_cv_header_glob_h" = "yes")
dnl Checks for library functions. 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() */ AH_VERBATIM([HAVE_MUNMAP_AFTER],[/* mmap() is no good without munmap() */
#if defined(HAVE_MMAP) && !defined(HAVE_MUNMAP) #if defined(HAVE_MMAP) && !defined(HAVE_MUNMAP)

4
dict.c
View File

@ -929,9 +929,7 @@ xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name) {
#include <windows.h> #include <windows.h>
#include <bcrypt.h> #include <bcrypt.h>
#elif defined(HAVE_GETENTROPY) #elif defined(HAVE_GETENTROPY)
#ifdef HAVE_UNISTD_H #include <unistd.h>
#include <unistd.h>
#endif
#ifdef HAVE_SYS_RANDOM_H #ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h> #include <sys/random.h>
#endif #endif

View File

@ -1,10 +1,6 @@
#ifndef __LIBXML_WIN32_CONFIG__ #ifndef __LIBXML_WIN32_CONFIG__
#define __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) #if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER >= 1600)
#define HAVE_STDINT_H #define HAVE_STDINT_H
#endif #endif

View File

@ -234,21 +234,19 @@ config_h.set_quoted('LOCALEDIR', dir_locale)
# header files # header files
xml_check_headers = [ xml_check_headers = [
'stdint.h', 'stdint.h',
'fcntl.h',
'unistd.h',
'sys/stat.h',
'sys/mman.h', 'sys/mman.h',
'sys/random.h',
'dl.h',
'dlfcn.h',
'glob.h',
# http
'sys/socket.h', 'sys/socket.h',
'netinet/in.h', 'netinet/in.h',
'arpa/inet.h', 'arpa/inet.h',
'netdb.h', 'netdb.h',
'sys/select.h', 'sys/select.h',
'poll.h', 'poll.h',
'sys/time.h',
'sys/timeb.h',
'dl.h',
'dlfcn.h',
'glob.h',
] ]
foreach header : xml_check_headers foreach header : xml_check_headers
@ -260,9 +258,7 @@ endforeach
# library functions # library functions
xml_check_functions = [ xml_check_functions = [
# fct | header # fct | header
['gettimeofday', 'sys/time.h'], ['getentropy', 'sys/random.h'],
['ftime', 'sys/timeb.h'],
['stat', 'sys/stat.h'],
['mmap', 'sys/mman.h'], ['mmap', 'sys/mman.h'],
['munmap', 'sys/mman.h'], ['munmap', 'sys/mman.h'],
] ]

View File

@ -20,11 +20,19 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#ifdef HAVE_UNISTD_H #include <fcntl.h>
#include <unistd.h>
#elif defined (_WIN32) #ifdef _WIN32
#include <io.h> #include <io.h>
#endif #include <wsockcompat.h>
#define XML_SOCKLEN_T int
#else /* _WIN32 */
#include <unistd.h>
#include <sys/time.h>
#ifdef HAVE_SYS_SOCKET_H #ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif
@ -40,12 +48,6 @@
#define SUPPORT_IP6 #define SUPPORT_IP6
#endif #endif
#endif #endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifndef HAVE_POLL_H #ifndef HAVE_POLL_H
#ifdef HAVE_SYS_SELECT_H #ifdef HAVE_SYS_SELECT_H
#include <sys/select.h> #include <sys/select.h>
@ -53,20 +55,20 @@
#else #else
#include <poll.h> #include <poll.h>
#endif #endif
#ifdef LIBXML_ZLIB_ENABLED
#include <zlib.h>
#endif
#ifdef VMS #ifdef VMS
#include <stropts> #include <stropts>
#define XML_SOCKLEN_T unsigned int #define XML_SOCKLEN_T unsigned int
#elif defined(_WIN32)
#include <wsockcompat.h>
#define XML_SOCKLEN_T int
#else #else
#define XML_SOCKLEN_T socklen_t #define XML_SOCKLEN_T socklen_t
#endif #endif
#endif /* _WIN32 */
#ifdef LIBXML_ZLIB_ENABLED
#include <zlib.h>
#endif
#include <libxml/xmlerror.h> #include <libxml/xmlerror.h>
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/parser.h> /* for xmlStr(n)casecmp() */ #include <libxml/parser.h> /* for xmlStr(n)casecmp() */

View File

@ -16,15 +16,17 @@
#include "libxml.h" #include "libxml.h"
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#elif defined (_WIN32)
#include <io.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/parserInternals.h> #include <libxml/parserInternals.h>

28
xmlIO.c
View File

@ -13,15 +13,18 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <io.h>
#include <direct.h>
#else
#include <unistd.h>
#endif #endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef LIBXML_ZLIB_ENABLED #ifdef LIBXML_ZLIB_ENABLED
#include <zlib.h> #include <zlib.h>
#endif #endif
@ -29,13 +32,6 @@
#include <lzma.h> #include <lzma.h>
#endif #endif
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <io.h>
#include <direct.h>
#endif
#include <libxml/xmlIO.h> #include <libxml/xmlIO.h>
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/uri.h> #include <libxml/uri.h>
@ -363,19 +359,16 @@ xmlNormalizeWindowsPath(const xmlChar *path)
int int
xmlCheckFilename(const char *path) xmlCheckFilename(const char *path)
{ {
#ifdef HAVE_STAT
#if defined(_WIN32) #if defined(_WIN32)
struct _stat stat_buffer; struct _stat stat_buffer;
#else #else
struct stat stat_buffer; struct stat stat_buffer;
#endif #endif
int res; int res;
#endif
if (path == NULL) if (path == NULL)
return(0); return(0);
#ifdef HAVE_STAT
#if defined(_WIN32) #if defined(_WIN32)
{ {
wchar_t *wpath; wchar_t *wpath;
@ -405,7 +398,6 @@ xmlCheckFilename(const char *path)
if (S_ISDIR(stat_buffer.st_mode)) if (S_ISDIR(stat_buffer.st_mode))
return 2; return 2;
#endif #endif
#endif /* HAVE_STAT */
return 1; return 1;
} }

View File

@ -17,29 +17,23 @@
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TIMEB_H
#include <sys/timeb.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <io.h>
#include <sys/timeb.h>
#else
#include <sys/time.h>
#include <unistd.h>
#endif #endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#elif defined (_WIN32)
#include <io.h>
#endif
#ifdef HAVE_SYS_MMAN_H #ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h> #include <sys/mman.h>
/* seems needed for Solaris */ /* seems needed for Solaris */
#ifndef MAP_FAILED #ifndef MAP_FAILED
#define MAP_FAILED ((void *) -1) #define MAP_FAILED ((void *) -1)
#endif #endif
#endif #endif
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>

16
xzlib.c
View File

@ -14,17 +14,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif #endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#elif defined (_WIN32)
#include <io.h>
#endif
#ifdef LIBXML_ZLIB_ENABLED #ifdef LIBXML_ZLIB_ENABLED
#include <zlib.h> #include <zlib.h>
#endif #endif