From d023737e6069e216c2365f7a62dbd16704181de0 Mon Sep 17 00:00:00 2001 From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137> Date: Sun, 19 Aug 2018 17:39:21 +0000 Subject: [PATCH] getopt/*, regex/*: Add _GETOPT/REGEX*_STANDALONE configurations. Makefile.am, os_win32/vc14/smart*.vcxproj*: Set *_STANDALONE. Add new files. git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk@4759 4ea69e1a-61f1-4043-bf83-b5c94c648137 --- smartmontools/ChangeLog | 4 ++- smartmontools/Makefile.am | 14 ++++++--- smartmontools/getopt/getopt.c | 16 +++++++++- smartmontools/getopt/getopt.h | 29 +++++++++++++++++++ smartmontools/getopt/getopt1.c | 2 +- smartmontools/os_win32/vc14/smartctl.vcxproj | 11 ++++--- .../os_win32/vc14/smartctl.vcxproj.filters | 9 ++++++ smartmontools/os_win32/vc14/smartd.vcxproj | 11 ++++--- .../os_win32/vc14/smartd.vcxproj.filters | 9 ++++++ smartmontools/regex/regcomp.c | 4 ++- smartmontools/regex/regex.c | 2 +- smartmontools/regex/regex.h | 2 +- smartmontools/regex/regex_internal.h | 8 ++++- 13 files changed, 102 insertions(+), 19 deletions(-) diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog index 6a5136f1e..6c3ff8f49 100644 --- a/smartmontools/ChangeLog +++ b/smartmontools/ChangeLog @@ -3,7 +3,9 @@ $Id$ 2018-08-19 Christian Franke <franke@computer.org> getopt/*, regex/*: Replace with current version from glibc 2.28 - (2018-08-01). + (2018-08-01). Add _GETOPT/REGEX*_STANDALONE configurations. + Makefile.am, os_win32/vc14/smart*.vcxproj*: Set *_STANDALONE. + Add new files. examplescripts/README: Update mailing list address. os_solaris_ata.s: Remove old mailing list address. diff --git a/smartmontools/Makefile.am b/smartmontools/Makefile.am index d5c09d885..d51dbb1f3 100644 --- a/smartmontools/Makefile.am +++ b/smartmontools/Makefile.am @@ -32,10 +32,10 @@ if OS_WIN32_MINGW AM_CPPFLAGS += -I$(srcdir)/os_win32 endif if NEED_GETOPT_LONG -AM_CPPFLAGS += -I$(srcdir)/getopt -DHAVE_GETOPT_LONG -D__GNU_LIBRARY__ +AM_CPPFLAGS += -I$(srcdir)/getopt -D_GETOPT_STANDALONE -DHAVE_GETOPT_LONG endif if NEED_REGEX -AM_CPPFLAGS += -I$(srcdir)/regex +AM_CPPFLAGS += -I$(srcdir)/regex -D_REGEX_STANDALONE endif sbin_PROGRAMS = \ @@ -209,12 +209,18 @@ if NEED_GETOPT_LONG smartctl_SOURCES += \ getopt/getopt.c \ getopt/getopt.h \ - getopt/getopt1.c + getopt/getopt1.c \ + getopt/getopt_int.h \ + getopt/bits/getopt_core.h \ + getopt/bits/getopt_ext.h smartd_SOURCES += \ getopt/getopt.c \ getopt/getopt.h \ - getopt/getopt1.c + getopt/getopt1.c \ + getopt/getopt_int.h \ + getopt/bits/getopt_core.h \ + getopt/bits/getopt_ext.h endif diff --git a/smartmontools/getopt/getopt.c b/smartmontools/getopt/getopt.c index 4b832208f..8e798a108 100644 --- a/smartmontools/getopt/getopt.c +++ b/smartmontools/getopt/getopt.c @@ -17,7 +17,7 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ -#ifndef _LIBC +#if !defined(_LIBC) && !defined(_GETOPT_STANDALONE) # include <config.h> #endif @@ -26,7 +26,9 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#ifndef _GETOPT_STANDALONE #include <unistd.h> +#endif #ifdef _LIBC /* When used as part of glibc, error printing must be done differently @@ -41,8 +43,12 @@ # define flockfile(fp) _IO_flockfile (fp) # define funlockfile(fp) _IO_funlockfile (fp) #else +#ifndef _GETOPT_STANDALONE # include "gettext.h" # define _(msgid) gettext (msgid) +#else +# define _(msgid) (msgid) +#endif /* When used standalone, flockfile and funlockfile might not be available. */ # ifndef _POSIX_THREAD_SAFE_FUNCTIONS @@ -374,6 +380,14 @@ process_long_option (int argc, char **argv, const char *optstring, return pfound->val; } +#ifndef _GL_UNUSED +# ifdef __GNUC__ +# define _GL_UNUSED __attribute__((__unused__)) +# else +# define _GL_UNUSED +# endif +#endif + /* Initialize internal data upon the first call to getopt. */ static const char * diff --git a/smartmontools/getopt/getopt.h b/smartmontools/getopt/getopt.h index afd7f6bf4..eb600ac8e 100644 --- a/smartmontools/getopt/getopt.h +++ b/smartmontools/getopt/getopt.h @@ -21,7 +21,36 @@ #ifndef _GETOPT_H #define _GETOPT_H 1 +#ifndef _GETOPT_STANDALONE #include <features.h> +#endif + +// From <sys/cdefs.h>: +#ifndef __BEGIN_DECLS +# ifdef __cplusplus +# define __BEGIN_DECLS extern "C" { +# define __END_DECLS } +# else +# define __BEGIN_DECLS +# define __END_DECLS +# endif +#endif +#ifndef __THROW +# ifdef __cplusplus +# define __THROW throw() +# elif defined(__GNUC__) +# define __THROW __attribute__ ((__nothrow__)) +# else +# define __THROW +# endif +#endif +#ifndef __nonnull +# ifdef __GNUC__ +# define __nonnull(x) __attribute__ ((__nonnull__ x)) +# else +# define __nonnull(x) +# endif +#endif /* The type of the 'argv' argument to getopt_long and getopt_long_only is properly 'char **', since both functions may write to the array diff --git a/smartmontools/getopt/getopt1.c b/smartmontools/getopt/getopt1.c index f3f274f4f..be17a5cf1 100644 --- a/smartmontools/getopt/getopt1.c +++ b/smartmontools/getopt/getopt1.c @@ -17,7 +17,7 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ -#ifndef _LIBC +#if !defined(_LIBC) && !defined(_GETOPT_STANDALONE) # include <config.h> #endif diff --git a/smartmontools/os_win32/vc14/smartctl.vcxproj b/smartmontools/os_win32/vc14/smartctl.vcxproj index 1f66993c8..33a532478 100644 --- a/smartmontools/os_win32/vc14/smartctl.vcxproj +++ b/smartmontools/os_win32/vc14/smartctl.vcxproj @@ -82,7 +82,7 @@ <ClCompile> <Optimization>Disabled</Optimization> <AdditionalIncludeDirectories>.;..\..\getopt;..\..\regex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>_DEBUG;HAVE_CONFIG_H;_USE_32BIT_TIME_T;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_DEBUG;_GETOPT_STANDALONE;_REGEX_STANDALONE;HAVE_CONFIG_H;_USE_32BIT_TIME_T;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <MinimalRebuild>true</MinimalRebuild> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> @@ -102,7 +102,7 @@ <ClCompile> <Optimization>Disabled</Optimization> <AdditionalIncludeDirectories>.;..\..\getopt;..\..\regex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>_DEBUG;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_DEBUG;_GETOPT_STANDALONE;_REGEX_STANDALONE;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <PrecompiledHeader> @@ -119,7 +119,7 @@ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> <AdditionalIncludeDirectories>.;..\..\getopt;..\..\regex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>NDEBUG;HAVE_CONFIG_H;_USE_32BIT_TIME_T;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>NDEBUG;_GETOPT_STANDALONE;_REGEX_STANDALONE;HAVE_CONFIG_H;_USE_32BIT_TIME_T;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <PrecompiledHeader> </PrecompiledHeader> @@ -138,7 +138,7 @@ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> <AdditionalIncludeDirectories>.;..\..\getopt;..\..\regex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>NDEBUG;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>NDEBUG;_GETOPT_STANDALONE;_REGEX_STANDALONE;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <PrecompiledHeader> </PrecompiledHeader> @@ -284,6 +284,9 @@ <ClInclude Include="..\..\ataidentify.h" /> <ClInclude Include="..\..\dev_areca.h" /> <ClInclude Include="..\..\dev_intelliprop.h" /> + <ClInclude Include="..\..\getopt\bits\getopt_core.h" /> + <ClInclude Include="..\..\getopt\bits\getopt_ext.h" /> + <ClInclude Include="..\..\getopt\getopt_int.h" /> <ClInclude Include="..\..\json.h" /> <ClInclude Include="..\..\nvmecmds.h" /> <ClInclude Include="..\..\nvmeprint.h" /> diff --git a/smartmontools/os_win32/vc14/smartctl.vcxproj.filters b/smartmontools/os_win32/vc14/smartctl.vcxproj.filters index 0bd56e034..72e6f9fad 100644 --- a/smartmontools/os_win32/vc14/smartctl.vcxproj.filters +++ b/smartmontools/os_win32/vc14/smartctl.vcxproj.filters @@ -106,6 +106,15 @@ <ClInclude Include="..\..\nvmeprint.h" /> <ClInclude Include="..\..\dev_intelliprop.h" /> <ClInclude Include="..\..\json.h" /> + <ClInclude Include="..\..\getopt\getopt_int.h"> + <Filter>getopt</Filter> + </ClInclude> + <ClInclude Include="..\..\getopt\bits\getopt_core.h"> + <Filter>getopt</Filter> + </ClInclude> + <ClInclude Include="..\..\getopt\bits\getopt_ext.h"> + <Filter>getopt</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\installer.nsi"> diff --git a/smartmontools/os_win32/vc14/smartd.vcxproj b/smartmontools/os_win32/vc14/smartd.vcxproj index e2e26c17d..ca4cf688a 100644 --- a/smartmontools/os_win32/vc14/smartd.vcxproj +++ b/smartmontools/os_win32/vc14/smartd.vcxproj @@ -82,7 +82,7 @@ <ClCompile> <Optimization>Disabled</Optimization> <AdditionalIncludeDirectories>.;..;..\..\getopt;..\..\regex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>_DEBUG;HAVE_CONFIG_H;_USE_32BIT_TIME_T;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_DEBUG;_GETOPT_STANDALONE;_REGEX_STANDALONE;HAVE_CONFIG_H;_USE_32BIT_TIME_T;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <MinimalRebuild>true</MinimalRebuild> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> @@ -102,7 +102,7 @@ <ClCompile> <Optimization>Disabled</Optimization> <AdditionalIncludeDirectories>.;..;..\..\getopt;..\..\regex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>_DEBUG;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_DEBUG;_GETOPT_STANDALONE;_REGEX_STANDALONE;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <PrecompiledHeader> @@ -119,7 +119,7 @@ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> <AdditionalIncludeDirectories>.;..;..\..\getopt;..\..\regex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>NDEBUG;HAVE_CONFIG_H;_USE_32BIT_TIME_T;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>NDEBUG;_GETOPT_STANDALONE;_REGEX_STANDALONE;HAVE_CONFIG_H;_USE_32BIT_TIME_T;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <PrecompiledHeader> </PrecompiledHeader> @@ -138,7 +138,7 @@ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> <AdditionalIncludeDirectories>.;..;..\..\getopt;..\..\regex;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>NDEBUG;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>NDEBUG;_GETOPT_STANDALONE;_REGEX_STANDALONE;HAVE_CONFIG_H;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <PrecompiledHeader> </PrecompiledHeader> @@ -298,6 +298,9 @@ </ClInclude> <ClInclude Include="..\..\dev_areca.h" /> <ClInclude Include="..\..\dev_intelliprop.h" /> + <ClInclude Include="..\..\getopt\bits\getopt_core.h" /> + <ClInclude Include="..\..\getopt\bits\getopt_ext.h" /> + <ClInclude Include="..\..\getopt\getopt_int.h" /> <ClInclude Include="..\..\nvmecmds.h" /> <ClInclude Include="..\..\nvmeprint.h"> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> diff --git a/smartmontools/os_win32/vc14/smartd.vcxproj.filters b/smartmontools/os_win32/vc14/smartd.vcxproj.filters index 7c7982577..84e604f2a 100644 --- a/smartmontools/os_win32/vc14/smartd.vcxproj.filters +++ b/smartmontools/os_win32/vc14/smartd.vcxproj.filters @@ -107,6 +107,15 @@ <ClInclude Include="..\..\nvmecmds.h" /> <ClInclude Include="..\..\nvmeprint.h" /> <ClInclude Include="..\..\dev_intelliprop.h" /> + <ClInclude Include="..\..\getopt\getopt_int.h"> + <Filter>getopt</Filter> + </ClInclude> + <ClInclude Include="..\..\getopt\bits\getopt_core.h"> + <Filter>getopt</Filter> + </ClInclude> + <ClInclude Include="..\..\getopt\bits\getopt_ext.h"> + <Filter>getopt</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\installer.nsi"> diff --git a/smartmontools/regex/regcomp.c b/smartmontools/regex/regcomp.c index 545d18846..16419494b 100644 --- a/smartmontools/regex/regcomp.c +++ b/smartmontools/regex/regcomp.c @@ -840,7 +840,7 @@ static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len) { __re_size_t table_size; -#ifndef _LIBC +#if !defined(_LIBC) && !defined(_REGEX_STANDALONE) const char *codeset_name; #endif #ifdef RE_ENABLE_I18N @@ -886,12 +886,14 @@ init_dfa (re_dfa_t *dfa, size_t pat_len) dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII) != 0); #else +# if !defined(_REGEX_STANDALONE) codeset_name = nl_langinfo (CODESET); if ((codeset_name[0] == 'U' || codeset_name[0] == 'u') && (codeset_name[1] == 'T' || codeset_name[1] == 't') && (codeset_name[2] == 'F' || codeset_name[2] == 'f') && strcmp (codeset_name + 3 + (codeset_name[3] == '-'), "8") == 0) dfa->is_utf8 = 1; +# endif /* We check exhaustively in the loop below if this charset is a superset of ASCII. */ diff --git a/smartmontools/regex/regex.c b/smartmontools/regex/regex.c index d6591e867..2d55bea03 100644 --- a/smartmontools/regex/regex.c +++ b/smartmontools/regex/regex.c @@ -17,7 +17,7 @@ License along with the GNU C Library; if not, see <https://www.gnu.org/licenses/>. */ -#ifndef _LIBC +#if !defined(_LIBC) && !defined(_REGEX_STANDALONE) # include <config.h> # if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ diff --git a/smartmontools/regex/regex.h b/smartmontools/regex/regex.h index 32933bc6d..c713f543b 100644 --- a/smartmontools/regex/regex.h +++ b/smartmontools/regex/regex.h @@ -29,7 +29,7 @@ extern "C" { /* Define __USE_GNU to declare GNU extensions that violate the POSIX name space rules. */ -#ifdef _GNU_SOURCE +#if defined(_GNU_SOURCE) || defined(_REGEX_STANDALONE) # define __USE_GNU 1 #endif diff --git a/smartmontools/regex/regex_internal.h b/smartmontools/regex/regex_internal.h index 3b836ed20..809d7938d 100644 --- a/smartmontools/regex/regex_internal.h +++ b/smartmontools/regex/regex_internal.h @@ -26,7 +26,9 @@ #include <stdlib.h> #include <string.h> +#ifndef _REGEX_STANDALONE #include <langinfo.h> +#endif #include <locale.h> #include <wchar.h> #include <wctype.h> @@ -35,7 +37,7 @@ /* Properties of integers. Although Gnulib has intprops.h, glibc does without for now. */ -#ifndef _LIBC +#if !defined(_LIBC) && !defined(_REGEX_STANDALONE) # include "intprops.h" #else /* True if the real type T is signed. */ @@ -132,7 +134,11 @@ # define RE_ENABLE_I18N #endif +#ifdef __GNUC__ #define BE(expr, val) __builtin_expect (expr, val) +#else +#define BE(expr, val) (expr) +#endif /* Number of ASCII characters. */ #define ASCII_CHARS 0x80 -- GitLab