1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 03:55:04 +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")
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)

View File

@ -19,17 +19,16 @@
#include <stdio.h>
#include <stdlib.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 <sys/stat.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include <libxml/xmlmemory.h>
#include <libxml/hash.h>
#include <libxml/uri.h>
@ -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);

View File

@ -16,18 +16,9 @@
/* Define to 1 if you have the <dl.h> header file. */
#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. */
#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 <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H 1
@ -78,18 +66,6 @@
/* Define to 1 if you have the <sys/socket.h> header file. */
#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. */
#cmakedefine HAVE_ZLIB_H 1

View File

@ -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)

4
dict.c
View File

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

View File

@ -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

View File

@ -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'],
]

View File

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

View File

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

28
xmlIO.c
View File

@ -13,15 +13,18 @@
#include <stdlib.h>
#include <errno.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_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
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef LIBXML_ZLIB_ENABLED
#include <zlib.h>
#endif
@ -29,13 +32,6 @@
#include <lzma.h>
#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/xmlmemory.h>
#include <libxml/uri.h>
@ -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;
}

View File

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

16
xzlib.c
View File

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