diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog index 6a5136f1ef961317dc026a84d52501c9c6285a81..6c3ff8f4913b83f9ad7c4ffae875ea712077718e 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 d5c09d88574c1d5f61437e57c8442465d0166aac..d51dbb1f3bc9d3a9205cce9e26d20a1d009892de 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 4b832208f8fb0c7cb6c0da9c11811ef378a50b50..8e798a108c38fa911bdcd0c99aafec854f06c041 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 afd7f6bf44ca2396d990878a97e8a7bcc5007459..eb600ac8e4416e87df6ee335a059e3dbef9ea92b 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 f3f274f4f32bbca04995eb9e1721c05015ed93bd..be17a5cf1a016fc143bbc9524d12bb085ed0759b 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 1f66993c8a1e5b7b7ffef74cd6580b3565f6afaf..33a532478bb27bdf34f9841ec6b96e3580477c00 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 0bd56e03416039d253ae985c0d8799115107843b..72e6f9fada82d24ccb52069f9d89ee622a4617e9 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 e2e26c17d690c18b4171bf3f8009039b6b9b5594..ca4cf688ab0198c5e9a93320fb5e86a8d6cc24a3 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 7c7982577352c3f287271d5cb56d793f6269a113..84e604f2ac1d32b69ba690eec1a6fe9eccf8601a 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 545d188468c376e7d82d3827a922f0fea87a4c0d..16419494b4bbd71ac2bbf36582a717c267599ee5 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 d6591e8670f73b2b1ab319fc721b7aff239dcfc4..2d55bea032c4623243b48bb396c66089ec6c7718 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 32933bc6d5b9d2c7580adce98b95f5612f7d4d36..c713f543bd105edefd9cddc203dd6fa983e371d0 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 3b836ed2067a4bff6ddd489cf545af5383be0c4b..809d7938d7f71eedfb6f1e7596be0206267a0fd1 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