From 508225fe3f22d2bf4f5a26003251712e6355c1ab Mon Sep 17 00:00:00 2001 From: The Tumultuous Unicorn Of Darkness Date: Sat, 27 Jul 2024 17:39:48 +0200 Subject: [PATCH] Fix build on OpenBSD There are declaration conflicts between ctype.h and libcpuid_internal.h. Let's provide a workaround for it. --- libcpuid/Doxyfile.in | 1 + libcpuid/Makefile.am | 1 + libcpuid/libcpuid_ctype.h | 81 +++++++++++++++++++++++++++++++++++ libcpuid/libcpuid_util.c | 2 +- libcpuid/libcpuid_vc71.vcproj | 3 ++ libcpuid/recog_amd.c | 2 +- libcpuid/recog_arm.c | 2 +- libcpuid/recog_centaur.c | 2 +- libcpuid/recog_intel.c | 2 +- 9 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 libcpuid/libcpuid_ctype.h diff --git a/libcpuid/Doxyfile.in b/libcpuid/Doxyfile.in index 9bc44c4..8a6bebf 100644 --- a/libcpuid/Doxyfile.in +++ b/libcpuid/Doxyfile.in @@ -990,6 +990,7 @@ RECURSIVE = NO # run. EXCLUDE = @top_srcdir@/libcpuid/libcpuid_internal.h \ + @top_srcdir@/libcpuid/libcpuid_ctype.h \ @top_srcdir@/libcpuid/libcpuid_util.h # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or diff --git a/libcpuid/Makefile.am b/libcpuid/Makefile.am index 3a9a0d1..fc789c3 100644 --- a/libcpuid/Makefile.am +++ b/libcpuid/Makefile.am @@ -35,6 +35,7 @@ noinst_HEADERS = \ asm-bits.h \ centaur_code_t.h \ intel_code_t.h \ + libcpuid_ctype.h \ libcpuid_internal.h \ libcpuid_util.h \ recog_amd.h \ diff --git a/libcpuid/libcpuid_ctype.h b/libcpuid/libcpuid_ctype.h new file mode 100644 index 0000000..b4ac7a4 --- /dev/null +++ b/libcpuid/libcpuid_ctype.h @@ -0,0 +1,81 @@ +/* + * Copyright 2024 Veselin Georgiev, + * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __LIBCPUID_CTYPE_H__ +#define __LIBCPUID_CTYPE_H__ +/* + * This file contains ctype.h function declarations for OS where this header cannot be included + */ + +#if defined(__OpenBSD__) +/* On OpenBSD, _common_bits_t/_intel_bits_t/_amd_bits_t from libcpuid_internal.h conflict with ctype.h */ +int isalnum(int); +int isalpha(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); +int tolower(int); +int toupper(int); + +# if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \ + || __XPG_VISIBLE > 600 +int isblank(int); +# endif + +# if __BSD_VISIBLE || __XPG_VISIBLE +int isascii(int); +int toascii(int); +int _tolower(int); +int _toupper(int); +# endif /* __BSD_VISIBLE || __XPG_VISIBLE */ + +# if __POSIX_VISIBLE >= 200809 +int isalnum_l(int, locale_t); +int isalpha_l(int, locale_t); +int isblank_l(int, locale_t); +int iscntrl_l(int, locale_t); +int isdigit_l(int, locale_t); +int isgraph_l(int, locale_t); +int islower_l(int, locale_t); +int isprint_l(int, locale_t); +int ispunct_l(int, locale_t); +int isspace_l(int, locale_t); +int isupper_l(int, locale_t); +int isxdigit_l(int, locale_t); +int tolower_l(int, locale_t); +int toupper_l(int, locale_t); +# endif +#else +# include +#endif + +#endif /* __LIBCPUID_CTYPE_H__ */ diff --git a/libcpuid/libcpuid_util.c b/libcpuid/libcpuid_util.c index 83bf1bd..c0dd0a5 100644 --- a/libcpuid/libcpuid_util.c +++ b/libcpuid/libcpuid_util.c @@ -28,11 +28,11 @@ #include #include #include -#include #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "libcpuid.h" +#include "libcpuid_ctype.h" #include "libcpuid_util.h" #include "libcpuid_internal.h" diff --git a/libcpuid/libcpuid_vc71.vcproj b/libcpuid/libcpuid_vc71.vcproj index 47084e5..c2fb0b3 100644 --- a/libcpuid/libcpuid_vc71.vcproj +++ b/libcpuid/libcpuid_vc71.vcproj @@ -202,6 +202,9 @@ + + diff --git a/libcpuid/recog_amd.c b/libcpuid/recog_amd.c index 661555d..45579bd 100644 --- a/libcpuid/recog_amd.c +++ b/libcpuid/recog_amd.c @@ -26,8 +26,8 @@ #include #include -#include #include "libcpuid.h" +#include "libcpuid_ctype.h" #include "libcpuid_util.h" #include "libcpuid_internal.h" #include "recog_amd.h" diff --git a/libcpuid/recog_arm.c b/libcpuid/recog_arm.c index 06bd4b8..deb1e48 100644 --- a/libcpuid/recog_arm.c +++ b/libcpuid/recog_arm.c @@ -27,9 +27,9 @@ #include #include #include -#include #include #include "libcpuid.h" +#include "libcpuid_ctype.h" #include "libcpuid_util.h" #include "libcpuid_internal.h" #include "recog_arm.h" diff --git a/libcpuid/recog_centaur.c b/libcpuid/recog_centaur.c index 3643f71..423c3b5 100644 --- a/libcpuid/recog_centaur.c +++ b/libcpuid/recog_centaur.c @@ -26,8 +26,8 @@ #include #include -#include #include "libcpuid.h" +#include "libcpuid_ctype.h" #include "libcpuid_util.h" #include "libcpuid_internal.h" #include "recog_centaur.h" diff --git a/libcpuid/recog_intel.c b/libcpuid/recog_intel.c index 5dd5230..c400435 100644 --- a/libcpuid/recog_intel.c +++ b/libcpuid/recog_intel.c @@ -24,8 +24,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include #include "libcpuid.h" +#include "libcpuid_ctype.h" #include "libcpuid_util.h" #include "libcpuid_internal.h" #include "recog_intel.h"