diff options
| author | Ton Voon <ton.voon@opsera.com> | 2010-06-17 10:16:43 +0100 |
|---|---|---|
| committer | tonvoon <ton.voon@opsera.com> | 2010-06-23 13:30:34 +0000 |
| commit | 18f6835edaf7d640a2c9e476cb1babdbdadbfd9b (patch) | |
| tree | ae11f40e48dc34658445c99012726f32bfb45c56 | |
| parent | f61412478ceb7c821793c8356b936f64066508bf (diff) | |
| download | monitoring-plugins-18f6835edaf7d640a2c9e476cb1babdbdadbfd9b.tar.gz | |
Added state retention APIs. Implemented for check_snmp with --rate option.
See http://nagiosplugin.org/c-api-private for more details on the API.
Also updated check_snmp -l option to change the perfdata label.
63 files changed, 2320 insertions, 1020 deletions
| @@ -5,7 +5,10 @@ This file documents the major additions and syntax changes between releases. | |||
| 5 | New check_ntp_peer -m and -n options to check the number of usable time sources ("truechimers") | 5 | New check_ntp_peer -m and -n options to check the number of usable time sources ("truechimers") |
| 6 | New check_disk_smb -a option which allows for specifying the IP address of the remote server | 6 | New check_disk_smb -a option which allows for specifying the IP address of the remote server |
| 7 | New check_radius -N option which allows for specifying the value of the NAS-IP-Address attribute | 7 | New check_radius -N option which allows for specifying the value of the NAS-IP-Address attribute |
| 8 | Updated Nagios::Plugin perl module | 8 | New check_snmp --rate option to store differences between invocations. Saves state in PREFIX/var/{plugin} |
| 9 | check_snmp -l label option now also changes the perfdata label. See WARNINGS | ||
| 10 | Updated Nagios::Plugin perl module | ||
| 11 | Updated gnulib to June 2010 | ||
| 9 | FIXES | 12 | FIXES |
| 10 | Fix check_ircd binding to wrong interface (#668778) | 13 | Fix check_ircd binding to wrong interface (#668778) |
| 11 | Add proxy-authorization option to check_http (Marcel Kuiper - #1323230, Bryan Irvine - #2863925) | 14 | Add proxy-authorization option to check_http (Marcel Kuiper - #1323230, Bryan Irvine - #2863925) |
| @@ -28,6 +31,7 @@ This file documents the major additions and syntax changes between releases. | |||
| 28 | Updated developer documentation to say that performance labels should not have an equals sign or | 31 | Updated developer documentation to say that performance labels should not have an equals sign or |
| 29 | single quote in the label | 32 | single quote in the label |
| 30 | check_http 1.4.14 introduced SSL SNI support - you now have to enable it explicitly with "--sni" | 33 | check_http 1.4.14 introduced SSL SNI support - you now have to enable it explicitly with "--sni" |
| 34 | check_snmp -l label option is also used for the performance label. This could change history from previous uses | ||
| 31 | 35 | ||
| 32 | 1.4.14 16th September 2009 | 36 | 1.4.14 16th September 2009 |
| 33 | check_http has options to specify the HTTP method (#2155152) | 37 | check_http has options to specify the HTTP method (#2155152) |
diff --git a/build-aux/c++defs.h b/build-aux/c++defs.h index 7d710898..0c2fad7a 100644 --- a/build-aux/c++defs.h +++ b/build-aux/c++defs.h | |||
| @@ -221,10 +221,20 @@ | |||
| 221 | _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE) | 221 | _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE) |
| 222 | # define _GL_CXXALIASWARN_1(func,namespace) \ | 222 | # define _GL_CXXALIASWARN_1(func,namespace) \ |
| 223 | _GL_CXXALIASWARN_2 (func, namespace) | 223 | _GL_CXXALIASWARN_2 (func, namespace) |
| 224 | # define _GL_CXXALIASWARN_2(func,namespace) \ | 224 | /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, |
| 225 | _GL_WARN_ON_USE (func, \ | 225 | we enable the warning only when not optimizing. */ |
| 226 | "The symbol ::" #func " refers to the system function. " \ | 226 | # if !__OPTIMIZE__ |
| 227 | "Use " #namespace "::" #func " instead.") | 227 | # define _GL_CXXALIASWARN_2(func,namespace) \ |
| 228 | _GL_WARN_ON_USE (func, \ | ||
| 229 | "The symbol ::" #func " refers to the system function. " \ | ||
| 230 | "Use " #namespace "::" #func " instead.") | ||
| 231 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | ||
| 232 | # define _GL_CXXALIASWARN_2(func,namespace) \ | ||
| 233 | extern __typeof__ (func) func | ||
| 234 | # else | ||
| 235 | # define _GL_CXXALIASWARN_2(func,namespace) \ | ||
| 236 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 237 | # endif | ||
| 228 | #else | 238 | #else |
| 229 | # define _GL_CXXALIASWARN(func) \ | 239 | # define _GL_CXXALIASWARN(func) \ |
| 230 | _GL_EXTERN_C int _gl_cxxalias_dummy | 240 | _GL_EXTERN_C int _gl_cxxalias_dummy |
| @@ -239,10 +249,20 @@ | |||
| 239 | GNULIB_NAMESPACE) | 249 | GNULIB_NAMESPACE) |
| 240 | # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \ | 250 | # define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \ |
| 241 | _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) | 251 | _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace) |
| 242 | # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ | 252 | /* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>, |
| 243 | _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \ | 253 | we enable the warning only when not optimizing. */ |
| 244 | "The symbol ::" #func " refers to the system function. " \ | 254 | # if !__OPTIMIZE__ |
| 245 | "Use " #namespace "::" #func " instead.") | 255 | # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ |
| 256 | _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \ | ||
| 257 | "The symbol ::" #func " refers to the system function. " \ | ||
| 258 | "Use " #namespace "::" #func " instead.") | ||
| 259 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | ||
| 260 | # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ | ||
| 261 | extern __typeof__ (func) func | ||
| 262 | # else | ||
| 263 | # define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \ | ||
| 264 | _GL_EXTERN_C int _gl_cxxalias_dummy | ||
| 265 | # endif | ||
| 246 | #else | 266 | #else |
| 247 | # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ | 267 | # define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \ |
| 248 | _GL_EXTERN_C int _gl_cxxalias_dummy | 268 | _GL_EXTERN_C int _gl_cxxalias_dummy |
diff --git a/build-aux/warn-on-use.h b/build-aux/warn-on-use.h index 1cd5062d..171e5991 100644 --- a/build-aux/warn-on-use.h +++ b/build-aux/warn-on-use.h | |||
| @@ -67,7 +67,10 @@ | |||
| 67 | /* A compiler attribute is available in gcc versions 4.3.0 and later. */ | 67 | /* A compiler attribute is available in gcc versions 4.3.0 and later. */ |
| 68 | # define _GL_WARN_ON_USE(function, message) \ | 68 | # define _GL_WARN_ON_USE(function, message) \ |
| 69 | extern __typeof__ (function) function __attribute__ ((__warning__ (message))) | 69 | extern __typeof__ (function) function __attribute__ ((__warning__ (message))) |
| 70 | 70 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | |
| 71 | /* Verify the existence of the function. */ | ||
| 72 | # define _GL_WARN_ON_USE(function, message) \ | ||
| 73 | extern __typeof__ (function) function | ||
| 71 | # else /* Unsupported. */ | 74 | # else /* Unsupported. */ |
| 72 | # define _GL_WARN_ON_USE(function, message) \ | 75 | # define _GL_WARN_ON_USE(function, message) \ |
| 73 | _GL_WARN_EXTERN_C int _gl_warn_on_use | 76 | _GL_WARN_EXTERN_C int _gl_warn_on_use |
| @@ -85,6 +88,10 @@ _GL_WARN_EXTERN_C int _gl_warn_on_use | |||
| 85 | # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ | 88 | # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ |
| 86 | extern rettype function parameters_and_attributes \ | 89 | extern rettype function parameters_and_attributes \ |
| 87 | __attribute__ ((__warning__ (msg))) | 90 | __attribute__ ((__warning__ (msg))) |
| 91 | # elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING | ||
| 92 | /* Verify the existence of the function. */ | ||
| 93 | # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ | ||
| 94 | extern rettype function parameters_and_attributes | ||
| 88 | # else /* Unsupported. */ | 95 | # else /* Unsupported. */ |
| 89 | # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ | 96 | # define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \ |
| 90 | _GL_WARN_EXTERN_C int _gl_warn_on_use | 97 | _GL_WARN_EXTERN_C int _gl_warn_on_use |
diff --git a/gl/Makefile.am b/gl/Makefile.am index e2dc38b7..7954b034 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | # the same distribution terms as the rest of that program. | 9 | # the same distribution terms as the rest of that program. |
| 10 | # | 10 | # |
| 11 | # Generated by gnulib-tool. | 11 | # Generated by gnulib-tool. |
| 12 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-libtool --macro-prefix=gl base64 dirname floorf fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex timegm vasprintf vsnprintf | 12 | # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-libtool --macro-prefix=gl --no-vc-files base64 crypto/sha1 dirname floorf fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex timegm vasprintf vsnprintf |
| 13 | 13 | ||
| 14 | AUTOMAKE_OPTIONS = 1.5 gnits | 14 | AUTOMAKE_OPTIONS = 1.5 gnits |
| 15 | 15 | ||
| @@ -44,17 +44,6 @@ EXTRA_DIST += alignof.h | |||
| 44 | 44 | ||
| 45 | ## end gnulib module alignof | 45 | ## end gnulib module alignof |
| 46 | 46 | ||
| 47 | ## begin gnulib module alloca | ||
| 48 | |||
| 49 | |||
| 50 | EXTRA_DIST += alloca.c | ||
| 51 | |||
| 52 | EXTRA_libgnu_a_SOURCES += alloca.c | ||
| 53 | |||
| 54 | libgnu_a_LIBADD += @ALLOCA@ | ||
| 55 | libgnu_a_DEPENDENCIES += @ALLOCA@ | ||
| 56 | ## end gnulib module alloca | ||
| 57 | |||
| 58 | ## begin gnulib module alloca-opt | 47 | ## begin gnulib module alloca-opt |
| 59 | 48 | ||
| 60 | BUILT_SOURCES += $(ALLOCA_H) | 49 | BUILT_SOURCES += $(ALLOCA_H) |
| @@ -253,6 +242,15 @@ CLEANFILES += configmake.h configmake.h-t | |||
| 253 | 242 | ||
| 254 | ## end gnulib module configmake | 243 | ## end gnulib module configmake |
| 255 | 244 | ||
| 245 | ## begin gnulib module crypto/sha1 | ||
| 246 | |||
| 247 | |||
| 248 | EXTRA_DIST += sha1.c sha1.h | ||
| 249 | |||
| 250 | EXTRA_libgnu_a_SOURCES += sha1.c | ||
| 251 | |||
| 252 | ## end gnulib module crypto/sha1 | ||
| 253 | |||
| 256 | ## begin gnulib module dirname | 254 | ## begin gnulib module dirname |
| 257 | 255 | ||
| 258 | 256 | ||
| @@ -833,11 +831,11 @@ EXTRA_libgnu_a_SOURCES += mountlist.c | |||
| 833 | 831 | ||
| 834 | ## begin gnulib module netdb | 832 | ## begin gnulib module netdb |
| 835 | 833 | ||
| 836 | BUILT_SOURCES += $(NETDB_H) | 834 | BUILT_SOURCES += netdb.h |
| 837 | 835 | ||
| 838 | # We need the following in order to create <netdb.h> when the system | 836 | # We need the following in order to create <netdb.h> when the system |
| 839 | # doesn't have one that works with the given compiler. | 837 | # doesn't have one that works with the given compiler. |
| 840 | netdb.h: netdb.in.h $(ARG_NONNULL_H) | 838 | netdb.h: netdb.in.h $(ARG_NONNULL_H) $(WARN_ON_USE_H) |
| 841 | $(AM_V_GEN)rm -f $@-t $@ && \ | 839 | $(AM_V_GEN)rm -f $@-t $@ && \ |
| 842 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ | 840 | { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ |
| 843 | sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ | 841 | sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ |
| @@ -851,6 +849,7 @@ netdb.h: netdb.in.h $(ARG_NONNULL_H) | |||
| 851 | -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \ | 849 | -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \ |
| 852 | -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \ | 850 | -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \ |
| 853 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ | 851 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ |
| 852 | -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ | ||
| 854 | < $(srcdir)/netdb.in.h; \ | 853 | < $(srcdir)/netdb.in.h; \ |
| 855 | } > $@-t && \ | 854 | } > $@-t && \ |
| 856 | mv $@-t $@ | 855 | mv $@-t $@ |
| @@ -1140,6 +1139,7 @@ stdio.h: stdio.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | |||
| 1140 | -e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \ | 1139 | -e 's|@''REPLACE_VPRINTF''@|$(REPLACE_VPRINTF)|g' \ |
| 1141 | -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \ | 1140 | -e 's|@''REPLACE_VSNPRINTF''@|$(REPLACE_VSNPRINTF)|g' \ |
| 1142 | -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \ | 1141 | -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \ |
| 1142 | -e 's|@''ASM_SYMBOL_PREFIX''@|$(ASM_SYMBOL_PREFIX)|g' \ | ||
| 1143 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ | 1143 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ |
| 1144 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ | 1144 | -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ |
| 1145 | -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ | 1145 | -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ |
| @@ -1333,6 +1333,7 @@ string.h: string.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | |||
| 1333 | -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ | 1333 | -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ |
| 1334 | -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \ | 1334 | -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \ |
| 1335 | -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ | 1335 | -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ |
| 1336 | -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \ | ||
| 1336 | -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ | 1337 | -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ |
| 1337 | -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ | 1338 | -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ |
| 1338 | -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ | 1339 | -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ |
| @@ -1506,6 +1507,7 @@ time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | |||
| 1506 | -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ | 1507 | -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ |
| 1507 | -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ | 1508 | -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ |
| 1508 | -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ | 1509 | -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ |
| 1510 | -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ | ||
| 1509 | -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ | 1511 | -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ |
| 1510 | -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ | 1512 | -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ |
| 1511 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ | 1513 | -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ |
| @@ -1577,6 +1579,7 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | |||
| 1577 | -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \ | 1579 | -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \ |
| 1578 | -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \ | 1580 | -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \ |
| 1579 | -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \ | 1581 | -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \ |
| 1582 | -e 's|@''GNULIB_PWRITE''@|$(GNULIB_PWRITE)|g' \ | ||
| 1580 | -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \ | 1583 | -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \ |
| 1581 | -e 's|@''GNULIB_READLINKAT''@|$(GNULIB_READLINKAT)|g' \ | 1584 | -e 's|@''GNULIB_READLINKAT''@|$(GNULIB_READLINKAT)|g' \ |
| 1582 | -e 's|@''GNULIB_RMDIR''@|$(GNULIB_RMDIR)|g' \ | 1585 | -e 's|@''GNULIB_RMDIR''@|$(GNULIB_RMDIR)|g' \ |
| @@ -1611,6 +1614,7 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | |||
| 1611 | -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \ | 1614 | -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \ |
| 1612 | -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \ | 1615 | -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \ |
| 1613 | -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \ | 1616 | -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \ |
| 1617 | -e 's|@''HAVE_PWRITE''@|$(HAVE_PWRITE)|g' \ | ||
| 1614 | -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ | 1618 | -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ |
| 1615 | -e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \ | 1619 | -e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \ |
| 1616 | -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ | 1620 | -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ |
| @@ -1638,10 +1642,12 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) | |||
| 1638 | -e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \ | 1642 | -e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \ |
| 1639 | -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ | 1643 | -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ |
| 1640 | -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \ | 1644 | -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \ |
| 1645 | -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \ | ||
| 1641 | -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \ | 1646 | -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \ |
| 1642 | -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \ | 1647 | -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \ |
| 1643 | -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \ | 1648 | -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \ |
| 1644 | -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \ | 1649 | -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \ |
| 1650 | -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \ | ||
| 1645 | -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \ | 1651 | -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \ |
| 1646 | -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \ | 1652 | -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \ |
| 1647 | -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \ | 1653 | -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \ |
diff --git a/gl/alloca.c b/gl/alloca.c deleted file mode 100644 index 75afdb96..00000000 --- a/gl/alloca.c +++ /dev/null | |||
| @@ -1,489 +0,0 @@ | |||
| 1 | /* alloca.c -- allocate automatically reclaimed memory | ||
| 2 | (Mostly) portable public-domain implementation -- D A Gwyn | ||
| 3 | |||
| 4 | This implementation of the PWB library alloca function, | ||
| 5 | which is used to allocate space off the run-time stack so | ||
| 6 | that it is automatically reclaimed upon procedure exit, | ||
| 7 | was inspired by discussions with J. Q. Johnson of Cornell. | ||
| 8 | J.Otto Tennant <jot@cray.com> contributed the Cray support. | ||
| 9 | |||
| 10 | There are some preprocessor constants that can | ||
| 11 | be defined when compiling for your specific system, for | ||
| 12 | improved efficiency; however, the defaults should be okay. | ||
| 13 | |||
| 14 | The general concept of this implementation is to keep | ||
| 15 | track of all alloca-allocated blocks, and reclaim any | ||
| 16 | that are found to be deeper in the stack than the current | ||
| 17 | invocation. This heuristic does not reclaim storage as | ||
| 18 | soon as it becomes invalid, but it will do so eventually. | ||
| 19 | |||
| 20 | As a special case, alloca(0) reclaims storage without | ||
| 21 | allocating any. It is a good idea to use alloca(0) in | ||
| 22 | your main control loop, etc. to force garbage collection. */ | ||
| 23 | |||
| 24 | #include <config.h> | ||
| 25 | |||
| 26 | #include <alloca.h> | ||
| 27 | |||
| 28 | #include <string.h> | ||
| 29 | #include <stdlib.h> | ||
| 30 | |||
| 31 | #ifdef emacs | ||
| 32 | # include "lisp.h" | ||
| 33 | # include "blockinput.h" | ||
| 34 | # ifdef EMACS_FREE | ||
| 35 | # undef free | ||
| 36 | # define free EMACS_FREE | ||
| 37 | # endif | ||
| 38 | #else | ||
| 39 | # define memory_full() abort () | ||
| 40 | #endif | ||
| 41 | |||
| 42 | /* If compiling with GCC 2, this file's not needed. */ | ||
| 43 | #if !defined (__GNUC__) || __GNUC__ < 2 | ||
| 44 | |||
| 45 | /* If someone has defined alloca as a macro, | ||
| 46 | there must be some other way alloca is supposed to work. */ | ||
| 47 | # ifndef alloca | ||
| 48 | |||
| 49 | # ifdef emacs | ||
| 50 | # ifdef static | ||
| 51 | /* actually, only want this if static is defined as "" | ||
| 52 | -- this is for usg, in which emacs must undefine static | ||
| 53 | in order to make unexec workable | ||
| 54 | */ | ||
| 55 | # ifndef STACK_DIRECTION | ||
| 56 | you | ||
| 57 | lose | ||
| 58 | -- must know STACK_DIRECTION at compile-time | ||
| 59 | /* Using #error here is not wise since this file should work for | ||
| 60 | old and obscure compilers. */ | ||
| 61 | # endif /* STACK_DIRECTION undefined */ | ||
| 62 | # endif /* static */ | ||
| 63 | # endif /* emacs */ | ||
| 64 | |||
| 65 | /* If your stack is a linked list of frames, you have to | ||
| 66 | provide an "address metric" ADDRESS_FUNCTION macro. */ | ||
| 67 | |||
| 68 | # if defined (CRAY) && defined (CRAY_STACKSEG_END) | ||
| 69 | long i00afunc (); | ||
| 70 | # define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) | ||
| 71 | # else | ||
| 72 | # define ADDRESS_FUNCTION(arg) &(arg) | ||
| 73 | # endif | ||
| 74 | |||
| 75 | /* Define STACK_DIRECTION if you know the direction of stack | ||
| 76 | growth for your system; otherwise it will be automatically | ||
| 77 | deduced at run-time. | ||
| 78 | |||
| 79 | STACK_DIRECTION > 0 => grows toward higher addresses | ||
| 80 | STACK_DIRECTION < 0 => grows toward lower addresses | ||
| 81 | STACK_DIRECTION = 0 => direction of growth unknown */ | ||
| 82 | |||
| 83 | # ifndef STACK_DIRECTION | ||
| 84 | # define STACK_DIRECTION 0 /* Direction unknown. */ | ||
| 85 | # endif | ||
| 86 | |||
| 87 | # if STACK_DIRECTION != 0 | ||
| 88 | |||
| 89 | # define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ | ||
| 90 | |||
| 91 | # else /* STACK_DIRECTION == 0; need run-time code. */ | ||
| 92 | |||
| 93 | static int stack_dir; /* 1 or -1 once known. */ | ||
| 94 | # define STACK_DIR stack_dir | ||
| 95 | |||
| 96 | static void | ||
| 97 | find_stack_direction (void) | ||
| 98 | { | ||
| 99 | static char *addr = NULL; /* Address of first `dummy', once known. */ | ||
| 100 | auto char dummy; /* To get stack address. */ | ||
| 101 | |||
| 102 | if (addr == NULL) | ||
| 103 | { /* Initial entry. */ | ||
| 104 | addr = ADDRESS_FUNCTION (dummy); | ||
| 105 | |||
| 106 | find_stack_direction (); /* Recurse once. */ | ||
| 107 | } | ||
| 108 | else | ||
| 109 | { | ||
| 110 | /* Second entry. */ | ||
| 111 | if (ADDRESS_FUNCTION (dummy) > addr) | ||
| 112 | stack_dir = 1; /* Stack grew upward. */ | ||
| 113 | else | ||
| 114 | stack_dir = -1; /* Stack grew downward. */ | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | # endif /* STACK_DIRECTION == 0 */ | ||
| 119 | |||
| 120 | /* An "alloca header" is used to: | ||
| 121 | (a) chain together all alloca'ed blocks; | ||
| 122 | (b) keep track of stack depth. | ||
| 123 | |||
| 124 | It is very important that sizeof(header) agree with malloc | ||
| 125 | alignment chunk size. The following default should work okay. */ | ||
| 126 | |||
| 127 | # ifndef ALIGN_SIZE | ||
| 128 | # define ALIGN_SIZE sizeof(double) | ||
| 129 | # endif | ||
| 130 | |||
| 131 | typedef union hdr | ||
| 132 | { | ||
| 133 | char align[ALIGN_SIZE]; /* To force sizeof(header). */ | ||
| 134 | struct | ||
| 135 | { | ||
| 136 | union hdr *next; /* For chaining headers. */ | ||
| 137 | char *deep; /* For stack depth measure. */ | ||
| 138 | } h; | ||
| 139 | } header; | ||
| 140 | |||
| 141 | static header *last_alloca_header = NULL; /* -> last alloca header. */ | ||
| 142 | |||
| 143 | /* Return a pointer to at least SIZE bytes of storage, | ||
| 144 | which will be automatically reclaimed upon exit from | ||
| 145 | the procedure that called alloca. Originally, this space | ||
| 146 | was supposed to be taken from the current stack frame of the | ||
| 147 | caller, but that method cannot be made to work for some | ||
| 148 | implementations of C, for example under Gould's UTX/32. */ | ||
| 149 | |||
| 150 | void * | ||
| 151 | alloca (size_t size) | ||
| 152 | { | ||
| 153 | auto char probe; /* Probes stack depth: */ | ||
| 154 | register char *depth = ADDRESS_FUNCTION (probe); | ||
| 155 | |||
| 156 | # if STACK_DIRECTION == 0 | ||
| 157 | if (STACK_DIR == 0) /* Unknown growth direction. */ | ||
| 158 | find_stack_direction (); | ||
| 159 | # endif | ||
| 160 | |||
| 161 | /* Reclaim garbage, defined as all alloca'd storage that | ||
| 162 | was allocated from deeper in the stack than currently. */ | ||
| 163 | |||
| 164 | { | ||
| 165 | register header *hp; /* Traverses linked list. */ | ||
| 166 | |||
| 167 | # ifdef emacs | ||
| 168 | BLOCK_INPUT; | ||
| 169 | # endif | ||
| 170 | |||
| 171 | for (hp = last_alloca_header; hp != NULL;) | ||
| 172 | if ((STACK_DIR > 0 && hp->h.deep > depth) | ||
| 173 | || (STACK_DIR < 0 && hp->h.deep < depth)) | ||
| 174 | { | ||
| 175 | register header *np = hp->h.next; | ||
| 176 | |||
| 177 | free (hp); /* Collect garbage. */ | ||
| 178 | |||
| 179 | hp = np; /* -> next header. */ | ||
| 180 | } | ||
| 181 | else | ||
| 182 | break; /* Rest are not deeper. */ | ||
| 183 | |||
| 184 | last_alloca_header = hp; /* -> last valid storage. */ | ||
| 185 | |||
| 186 | # ifdef emacs | ||
| 187 | UNBLOCK_INPUT; | ||
| 188 | # endif | ||
| 189 | } | ||
| 190 | |||
| 191 | if (size == 0) | ||
| 192 | return NULL; /* No allocation required. */ | ||
| 193 | |||
| 194 | /* Allocate combined header + user data storage. */ | ||
| 195 | |||
| 196 | { | ||
| 197 | /* Address of header. */ | ||
| 198 | register header *new; | ||
| 199 | |||
| 200 | size_t combined_size = sizeof (header) + size; | ||
| 201 | if (combined_size < sizeof (header)) | ||
| 202 | memory_full (); | ||
| 203 | |||
| 204 | new = malloc (combined_size); | ||
| 205 | |||
| 206 | if (! new) | ||
| 207 | memory_full (); | ||
| 208 | |||
| 209 | new->h.next = last_alloca_header; | ||
| 210 | new->h.deep = depth; | ||
| 211 | |||
| 212 | last_alloca_header = new; | ||
| 213 | |||
| 214 | /* User storage begins just after header. */ | ||
| 215 | |||
| 216 | return (void *) (new + 1); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | # if defined (CRAY) && defined (CRAY_STACKSEG_END) | ||
| 221 | |||
| 222 | # ifdef DEBUG_I00AFUNC | ||
| 223 | # include <stdio.h> | ||
| 224 | # endif | ||
| 225 | |||
| 226 | # ifndef CRAY_STACK | ||
| 227 | # define CRAY_STACK | ||
| 228 | # ifndef CRAY2 | ||
| 229 | /* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ | ||
| 230 | struct stack_control_header | ||
| 231 | { | ||
| 232 | long shgrow:32; /* Number of times stack has grown. */ | ||
| 233 | long shaseg:32; /* Size of increments to stack. */ | ||
| 234 | long shhwm:32; /* High water mark of stack. */ | ||
| 235 | long shsize:32; /* Current size of stack (all segments). */ | ||
| 236 | }; | ||
| 237 | |||
| 238 | /* The stack segment linkage control information occurs at | ||
| 239 | the high-address end of a stack segment. (The stack | ||
| 240 | grows from low addresses to high addresses.) The initial | ||
| 241 | part of the stack segment linkage control information is | ||
| 242 | 0200 (octal) words. This provides for register storage | ||
| 243 | for the routine which overflows the stack. */ | ||
| 244 | |||
| 245 | struct stack_segment_linkage | ||
| 246 | { | ||
| 247 | long ss[0200]; /* 0200 overflow words. */ | ||
| 248 | long sssize:32; /* Number of words in this segment. */ | ||
| 249 | long ssbase:32; /* Offset to stack base. */ | ||
| 250 | long:32; | ||
| 251 | long sspseg:32; /* Offset to linkage control of previous | ||
| 252 | segment of stack. */ | ||
| 253 | long:32; | ||
| 254 | long sstcpt:32; /* Pointer to task common address block. */ | ||
| 255 | long sscsnm; /* Private control structure number for | ||
| 256 | microtasking. */ | ||
| 257 | long ssusr1; /* Reserved for user. */ | ||
| 258 | long ssusr2; /* Reserved for user. */ | ||
| 259 | long sstpid; /* Process ID for pid based multi-tasking. */ | ||
| 260 | long ssgvup; /* Pointer to multitasking thread giveup. */ | ||
| 261 | long sscray[7]; /* Reserved for Cray Research. */ | ||
| 262 | long ssa0; | ||
| 263 | long ssa1; | ||
| 264 | long ssa2; | ||
| 265 | long ssa3; | ||
| 266 | long ssa4; | ||
| 267 | long ssa5; | ||
| 268 | long ssa6; | ||
| 269 | long ssa7; | ||
| 270 | long sss0; | ||
| 271 | long sss1; | ||
| 272 | long sss2; | ||
| 273 | long sss3; | ||
| 274 | long sss4; | ||
| 275 | long sss5; | ||
| 276 | long sss6; | ||
| 277 | long sss7; | ||
| 278 | }; | ||
| 279 | |||
| 280 | # else /* CRAY2 */ | ||
| 281 | /* The following structure defines the vector of words | ||
| 282 | returned by the STKSTAT library routine. */ | ||
| 283 | struct stk_stat | ||
| 284 | { | ||
| 285 | long now; /* Current total stack size. */ | ||
| 286 | long maxc; /* Amount of contiguous space which would | ||
| 287 | be required to satisfy the maximum | ||
| 288 | stack demand to date. */ | ||
| 289 | long high_water; /* Stack high-water mark. */ | ||
| 290 | long overflows; /* Number of stack overflow ($STKOFEN) calls. */ | ||
| 291 | long hits; /* Number of internal buffer hits. */ | ||
| 292 | long extends; /* Number of block extensions. */ | ||
| 293 | long stko_mallocs; /* Block allocations by $STKOFEN. */ | ||
| 294 | long underflows; /* Number of stack underflow calls ($STKRETN). */ | ||
| 295 | long stko_free; /* Number of deallocations by $STKRETN. */ | ||
| 296 | long stkm_free; /* Number of deallocations by $STKMRET. */ | ||
| 297 | long segments; /* Current number of stack segments. */ | ||
| 298 | long maxs; /* Maximum number of stack segments so far. */ | ||
| 299 | long pad_size; /* Stack pad size. */ | ||
| 300 | long current_address; /* Current stack segment address. */ | ||
| 301 | long current_size; /* Current stack segment size. This | ||
| 302 | number is actually corrupted by STKSTAT to | ||
| 303 | include the fifteen word trailer area. */ | ||
| 304 | long initial_address; /* Address of initial segment. */ | ||
| 305 | long initial_size; /* Size of initial segment. */ | ||
| 306 | }; | ||
| 307 | |||
| 308 | /* The following structure describes the data structure which trails | ||
| 309 | any stack segment. I think that the description in 'asdef' is | ||
| 310 | out of date. I only describe the parts that I am sure about. */ | ||
| 311 | |||
| 312 | struct stk_trailer | ||
| 313 | { | ||
| 314 | long this_address; /* Address of this block. */ | ||
| 315 | long this_size; /* Size of this block (does not include | ||
| 316 | this trailer). */ | ||
| 317 | long unknown2; | ||
| 318 | long unknown3; | ||
| 319 | long link; /* Address of trailer block of previous | ||
| 320 | segment. */ | ||
| 321 | long unknown5; | ||
| 322 | long unknown6; | ||
| 323 | long unknown7; | ||
| 324 | long unknown8; | ||
| 325 | long unknown9; | ||
| 326 | long unknown10; | ||
| 327 | long unknown11; | ||
| 328 | long unknown12; | ||
| 329 | long unknown13; | ||
| 330 | long unknown14; | ||
| 331 | }; | ||
| 332 | |||
| 333 | # endif /* CRAY2 */ | ||
| 334 | # endif /* not CRAY_STACK */ | ||
| 335 | |||
| 336 | # ifdef CRAY2 | ||
| 337 | /* Determine a "stack measure" for an arbitrary ADDRESS. | ||
| 338 | I doubt that "lint" will like this much. */ | ||
| 339 | |||
| 340 | static long | ||
| 341 | i00afunc (long *address) | ||
| 342 | { | ||
| 343 | struct stk_stat status; | ||
| 344 | struct stk_trailer *trailer; | ||
| 345 | long *block, size; | ||
| 346 | long result = 0; | ||
| 347 | |||
| 348 | /* We want to iterate through all of the segments. The first | ||
| 349 | step is to get the stack status structure. We could do this | ||
| 350 | more quickly and more directly, perhaps, by referencing the | ||
| 351 | $LM00 common block, but I know that this works. */ | ||
| 352 | |||
| 353 | STKSTAT (&status); | ||
| 354 | |||
| 355 | /* Set up the iteration. */ | ||
| 356 | |||
| 357 | trailer = (struct stk_trailer *) (status.current_address | ||
| 358 | + status.current_size | ||
| 359 | - 15); | ||
| 360 | |||
| 361 | /* There must be at least one stack segment. Therefore it is | ||
| 362 | a fatal error if "trailer" is null. */ | ||
| 363 | |||
| 364 | if (trailer == 0) | ||
| 365 | abort (); | ||
| 366 | |||
| 367 | /* Discard segments that do not contain our argument address. */ | ||
| 368 | |||
| 369 | while (trailer != 0) | ||
| 370 | { | ||
| 371 | block = (long *) trailer->this_address; | ||
| 372 | size = trailer->this_size; | ||
| 373 | if (block == 0 || size == 0) | ||
| 374 | abort (); | ||
| 375 | trailer = (struct stk_trailer *) trailer->link; | ||
| 376 | if ((block <= address) && (address < (block + size))) | ||
| 377 | break; | ||
| 378 | } | ||
| 379 | |||
| 380 | /* Set the result to the offset in this segment and add the sizes | ||
| 381 | of all predecessor segments. */ | ||
| 382 | |||
| 383 | result = address - block; | ||
| 384 | |||
| 385 | if (trailer == 0) | ||
| 386 | { | ||
| 387 | return result; | ||
| 388 | } | ||
| 389 | |||
| 390 | do | ||
| 391 | { | ||
| 392 | if (trailer->this_size <= 0) | ||
| 393 | abort (); | ||
| 394 | result += trailer->this_size; | ||
| 395 | trailer = (struct stk_trailer *) trailer->link; | ||
| 396 | } | ||
| 397 | while (trailer != 0); | ||
| 398 | |||
| 399 | /* We are done. Note that if you present a bogus address (one | ||
| 400 | not in any segment), you will get a different number back, formed | ||
| 401 | from subtracting the address of the first block. This is probably | ||
| 402 | not what you want. */ | ||
| 403 | |||
| 404 | return (result); | ||
| 405 | } | ||
| 406 | |||
| 407 | # else /* not CRAY2 */ | ||
| 408 | /* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. | ||
| 409 | Determine the number of the cell within the stack, | ||
| 410 | given the address of the cell. The purpose of this | ||
| 411 | routine is to linearize, in some sense, stack addresses | ||
| 412 | for alloca. */ | ||
| 413 | |||
| 414 | static long | ||
| 415 | i00afunc (long address) | ||
| 416 | { | ||
| 417 | long stkl = 0; | ||
| 418 | |||
| 419 | long size, pseg, this_segment, stack; | ||
| 420 | long result = 0; | ||
| 421 | |||
| 422 | struct stack_segment_linkage *ssptr; | ||
| 423 | |||
| 424 | /* Register B67 contains the address of the end of the | ||
| 425 | current stack segment. If you (as a subprogram) store | ||
| 426 | your registers on the stack and find that you are past | ||
| 427 | the contents of B67, you have overflowed the segment. | ||
| 428 | |||
| 429 | B67 also points to the stack segment linkage control | ||
| 430 | area, which is what we are really interested in. */ | ||
| 431 | |||
| 432 | stkl = CRAY_STACKSEG_END (); | ||
| 433 | ssptr = (struct stack_segment_linkage *) stkl; | ||
| 434 | |||
| 435 | /* If one subtracts 'size' from the end of the segment, | ||
| 436 | one has the address of the first word of the segment. | ||
| 437 | |||
| 438 | If this is not the first segment, 'pseg' will be | ||
| 439 | nonzero. */ | ||
| 440 | |||
| 441 | pseg = ssptr->sspseg; | ||
| 442 | size = ssptr->sssize; | ||
| 443 | |||
| 444 | this_segment = stkl - size; | ||
| 445 | |||
| 446 | /* It is possible that calling this routine itself caused | ||
| 447 | a stack overflow. Discard stack segments which do not | ||
| 448 | contain the target address. */ | ||
| 449 | |||
| 450 | while (!(this_segment <= address && address <= stkl)) | ||
| 451 | { | ||
| 452 | # ifdef DEBUG_I00AFUNC | ||
| 453 | fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); | ||
| 454 | # endif | ||
| 455 | if (pseg == 0) | ||
| 456 | break; | ||
| 457 | stkl = stkl - pseg; | ||
| 458 | ssptr = (struct stack_segment_linkage *) stkl; | ||
| 459 | size = ssptr->sssize; | ||
| 460 | pseg = ssptr->sspseg; | ||
| 461 | this_segment = stkl - size; | ||
| 462 | } | ||
| 463 | |||
| 464 | result = address - this_segment; | ||
| 465 | |||
| 466 | /* If you subtract pseg from the current end of the stack, | ||
| 467 | you get the address of the previous stack segment's end. | ||
| 468 | This seems a little convoluted to me, but I'll bet you save | ||
| 469 | a cycle somewhere. */ | ||
| 470 | |||
| 471 | while (pseg != 0) | ||
| 472 | { | ||
| 473 | # ifdef DEBUG_I00AFUNC | ||
| 474 | fprintf (stderr, "%011o %011o\n", pseg, size); | ||
| 475 | # endif | ||
| 476 | stkl = stkl - pseg; | ||
| 477 | ssptr = (struct stack_segment_linkage *) stkl; | ||
| 478 | size = ssptr->sssize; | ||
| 479 | pseg = ssptr->sspseg; | ||
| 480 | result += size; | ||
| 481 | } | ||
| 482 | return (result); | ||
| 483 | } | ||
| 484 | |||
| 485 | # endif /* not CRAY2 */ | ||
| 486 | # endif /* CRAY */ | ||
| 487 | |||
| 488 | # endif /* no alloca */ | ||
| 489 | #endif /* not GCC version 3 */ | ||
diff --git a/gl/config.charset b/gl/config.charset index 2959df89..aa7d00db 100644 --- a/gl/config.charset +++ b/gl/config.charset | |||
| @@ -30,21 +30,21 @@ | |||
| 30 | # The current list of GNU canonical charset names is as follows. | 30 | # The current list of GNU canonical charset names is as follows. |
| 31 | # | 31 | # |
| 32 | # name MIME? used by which systems | 32 | # name MIME? used by which systems |
| 33 | # ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin | 33 | # ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin cygwin |
| 34 | # ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin | 34 | # ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin |
| 35 | # ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin | 35 | # ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin |
| 36 | # ISO-8859-3 Y glibc solaris | 36 | # ISO-8859-3 Y glibc solaris cygwin |
| 37 | # ISO-8859-4 Y osf solaris freebsd netbsd openbsd darwin | 37 | # ISO-8859-4 Y osf solaris freebsd netbsd openbsd darwin |
| 38 | # ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin | 38 | # ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin |
| 39 | # ISO-8859-6 Y glibc aix hpux solaris | 39 | # ISO-8859-6 Y glibc aix hpux solaris cygwin |
| 40 | # ISO-8859-7 Y glibc aix hpux irix osf solaris netbsd openbsd darwin | 40 | # ISO-8859-7 Y glibc aix hpux irix osf solaris netbsd openbsd darwin cygwin |
| 41 | # ISO-8859-8 Y glibc aix hpux osf solaris | 41 | # ISO-8859-8 Y glibc aix hpux osf solaris cygwin |
| 42 | # ISO-8859-9 Y glibc aix hpux irix osf solaris darwin | 42 | # ISO-8859-9 Y glibc aix hpux irix osf solaris darwin cygwin |
| 43 | # ISO-8859-13 glibc netbsd openbsd darwin | 43 | # ISO-8859-13 glibc netbsd openbsd darwin cygwin |
| 44 | # ISO-8859-14 glibc | 44 | # ISO-8859-14 glibc cygwin |
| 45 | # ISO-8859-15 glibc aix osf solaris freebsd netbsd openbsd darwin | 45 | # ISO-8859-15 glibc aix osf solaris freebsd netbsd openbsd darwin cygwin |
| 46 | # KOI8-R Y glibc solaris freebsd netbsd openbsd darwin | 46 | # KOI8-R Y glibc solaris freebsd netbsd openbsd darwin |
| 47 | # KOI8-U Y glibc freebsd netbsd openbsd darwin | 47 | # KOI8-U Y glibc freebsd netbsd openbsd darwin cygwin |
| 48 | # KOI8-T glibc | 48 | # KOI8-T glibc |
| 49 | # CP437 dos | 49 | # CP437 dos |
| 50 | # CP775 dos | 50 | # CP775 dos |
| @@ -61,7 +61,7 @@ | |||
| 61 | # CP869 dos | 61 | # CP869 dos |
| 62 | # CP874 woe32 dos | 62 | # CP874 woe32 dos |
| 63 | # CP922 aix | 63 | # CP922 aix |
| 64 | # CP932 aix woe32 dos | 64 | # CP932 aix cygwin woe32 dos |
| 65 | # CP943 aix | 65 | # CP943 aix |
| 66 | # CP949 osf darwin woe32 dos | 66 | # CP949 osf darwin woe32 dos |
| 67 | # CP950 woe32 dos | 67 | # CP950 woe32 dos |
| @@ -71,7 +71,7 @@ | |||
| 71 | # CP1129 aix | 71 | # CP1129 aix |
| 72 | # CP1131 darwin | 72 | # CP1131 darwin |
| 73 | # CP1250 woe32 | 73 | # CP1250 woe32 |
| 74 | # CP1251 glibc solaris netbsd openbsd darwin woe32 | 74 | # CP1251 glibc solaris netbsd openbsd darwin cygwin woe32 |
| 75 | # CP1252 aix woe32 | 75 | # CP1252 aix woe32 |
| 76 | # CP1253 woe32 | 76 | # CP1253 woe32 |
| 77 | # CP1254 woe32 | 77 | # CP1254 woe32 |
| @@ -80,19 +80,19 @@ | |||
| 80 | # CP1257 woe32 | 80 | # CP1257 woe32 |
| 81 | # GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin | 81 | # GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin |
| 82 | # EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin | 82 | # EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin |
| 83 | # EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin | 83 | # EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin |
| 84 | # EUC-TW glibc aix hpux irix osf solaris netbsd | 84 | # EUC-TW glibc aix hpux irix osf solaris netbsd |
| 85 | # BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin | 85 | # BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin |
| 86 | # BIG5-HKSCS glibc solaris darwin | 86 | # BIG5-HKSCS glibc solaris darwin |
| 87 | # GBK glibc aix osf solaris darwin woe32 dos | 87 | # GBK glibc aix osf solaris darwin cygwin woe32 dos |
| 88 | # GB18030 glibc solaris netbsd darwin | 88 | # GB18030 glibc solaris netbsd darwin |
| 89 | # SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin | 89 | # SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin |
| 90 | # JOHAB glibc solaris woe32 | 90 | # JOHAB glibc solaris woe32 |
| 91 | # TIS-620 glibc aix hpux osf solaris | 91 | # TIS-620 glibc aix hpux osf solaris cygwin |
| 92 | # VISCII Y glibc | 92 | # VISCII Y glibc |
| 93 | # TCVN5712-1 glibc | 93 | # TCVN5712-1 glibc |
| 94 | # ARMSCII-8 glibc darwin | 94 | # ARMSCII-8 glibc darwin |
| 95 | # GEORGIAN-PS glibc | 95 | # GEORGIAN-PS glibc cygwin |
| 96 | # PT154 glibc | 96 | # PT154 glibc |
| 97 | # HP-ROMAN8 hpux | 97 | # HP-ROMAN8 hpux |
| 98 | # HP-ARABIC8 hpux | 98 | # HP-ARABIC8 hpux |
| @@ -102,7 +102,7 @@ | |||
| 102 | # HP-KANA8 hpux | 102 | # HP-KANA8 hpux |
| 103 | # DEC-KANJI osf | 103 | # DEC-KANJI osf |
| 104 | # DEC-HANYU osf | 104 | # DEC-HANYU osf |
| 105 | # UTF-8 Y glibc aix hpux osf solaris netbsd darwin | 105 | # UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin |
| 106 | # | 106 | # |
| 107 | # Note: Names which are not marked as being a MIME name should not be used in | 107 | # Note: Names which are not marked as being a MIME name should not be used in |
| 108 | # Internet protocols for information interchange (mail, news, etc.). | 108 | # Internet protocols for information interchange (mail, news, etc.). |
| @@ -88,6 +88,15 @@ extern void __error_at_line (int status, int errnum, const char *file_name, | |||
| 88 | # include <fcntl.h> | 88 | # include <fcntl.h> |
| 89 | # include <unistd.h> | 89 | # include <unistd.h> |
| 90 | 90 | ||
| 91 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 92 | /* Get declarations of the Win32 API functions. */ | ||
| 93 | # define WIN32_LEAN_AND_MEAN | ||
| 94 | # include <windows.h> | ||
| 95 | # endif | ||
| 96 | |||
| 97 | /* The gnulib override of fcntl is not needed in this file. */ | ||
| 98 | # undef fcntl | ||
| 99 | |||
| 91 | # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P | 100 | # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P |
| 92 | # ifndef HAVE_DECL_STRERROR_R | 101 | # ifndef HAVE_DECL_STRERROR_R |
| 93 | "this configure-time declaration test was not run" | 102 | "this configure-time declaration test was not run" |
| @@ -104,10 +113,29 @@ extern char *program_name; | |||
| 104 | # endif /* HAVE_STRERROR_R || defined strerror_r */ | 113 | # endif /* HAVE_STRERROR_R || defined strerror_r */ |
| 105 | #endif /* not _LIBC */ | 114 | #endif /* not _LIBC */ |
| 106 | 115 | ||
| 116 | #if !_LIBC | ||
| 117 | /* Return non-zero if FD is open. */ | ||
| 118 | static inline int | ||
| 119 | is_open (int fd) | ||
| 120 | { | ||
| 121 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | ||
| 122 | /* On Win32: The initial state of unassigned standard file descriptors is | ||
| 123 | that they are open but point to an INVALID_HANDLE_VALUE. There is no | ||
| 124 | fcntl, and the gnulib replacement fcntl does not support F_GETFL. */ | ||
| 125 | return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; | ||
| 126 | # else | ||
| 127 | # ifndef F_GETFL | ||
| 128 | # error Please port fcntl to your platform | ||
| 129 | # endif | ||
| 130 | return 0 <= fcntl (fd, F_GETFL); | ||
| 131 | # endif | ||
| 132 | } | ||
| 133 | #endif | ||
| 134 | |||
| 107 | static inline void | 135 | static inline void |
| 108 | flush_stdout (void) | 136 | flush_stdout (void) |
| 109 | { | 137 | { |
| 110 | #if !_LIBC && defined F_GETFL | 138 | #if !_LIBC |
| 111 | int stdout_fd; | 139 | int stdout_fd; |
| 112 | 140 | ||
| 113 | # if GNULIB_FREOPEN_SAFER | 141 | # if GNULIB_FREOPEN_SAFER |
| @@ -124,7 +152,7 @@ flush_stdout (void) | |||
| 124 | /* POSIX states that fflush (stdout) after fclose is unspecified; it | 152 | /* POSIX states that fflush (stdout) after fclose is unspecified; it |
| 125 | is safe in glibc, but not on all other platforms. fflush (NULL) | 153 | is safe in glibc, but not on all other platforms. fflush (NULL) |
| 126 | is always defined, but too draconian. */ | 154 | is always defined, but too draconian. */ |
| 127 | if (0 <= stdout_fd && 0 <= fcntl (stdout_fd, F_GETFL)) | 155 | if (0 <= stdout_fd && is_open (stdout_fd)) |
| 128 | #endif | 156 | #endif |
| 129 | fflush (stdout); | 157 | fflush (stdout); |
| 130 | } | 158 | } |
diff --git a/gl/getopt.c b/gl/getopt.c index aaabc8d1..3791f129 100644 --- a/gl/getopt.c +++ b/gl/getopt.c | |||
| @@ -348,8 +348,6 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 348 | int long_only, struct _getopt_data *d, int posixly_correct) | 348 | int long_only, struct _getopt_data *d, int posixly_correct) |
| 349 | { | 349 | { |
| 350 | int print_errors = d->opterr; | 350 | int print_errors = d->opterr; |
| 351 | if (optstring[0] == ':') | ||
| 352 | print_errors = 0; | ||
| 353 | 351 | ||
| 354 | if (argc < 1) | 352 | if (argc < 1) |
| 355 | return -1; | 353 | return -1; |
| @@ -364,6 +362,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 364 | posixly_correct); | 362 | posixly_correct); |
| 365 | d->__initialized = 1; | 363 | d->__initialized = 1; |
| 366 | } | 364 | } |
| 365 | else if (optstring[0] == '-' || optstring[0] == '+') | ||
| 366 | optstring++; | ||
| 367 | if (optstring[0] == ':') | ||
| 368 | print_errors = 0; | ||
| 367 | 369 | ||
| 368 | /* Test whether ARGV[optind] points to a non-option argument. | 370 | /* Test whether ARGV[optind] points to a non-option argument. |
| 369 | Either it does not have option syntax, or there is an environment flag | 371 | Either it does not have option syntax, or there is an environment flag |
| @@ -633,8 +635,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 633 | char *buf; | 635 | char *buf; |
| 634 | 636 | ||
| 635 | if (__asprintf (&buf, _("\ | 637 | if (__asprintf (&buf, _("\ |
| 636 | %s: option '%s' requires an argument\n"), | 638 | %s: option '--%s' requires an argument\n"), |
| 637 | argv[0], argv[d->optind - 1]) >= 0) | 639 | argv[0], pfound->name) >= 0) |
| 638 | { | 640 | { |
| 639 | _IO_flockfile (stderr); | 641 | _IO_flockfile (stderr); |
| 640 | 642 | ||
| @@ -651,8 +653,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 651 | } | 653 | } |
| 652 | #else | 654 | #else |
| 653 | fprintf (stderr, | 655 | fprintf (stderr, |
| 654 | _("%s: option '%s' requires an argument\n"), | 656 | _("%s: option '--%s' requires an argument\n"), |
| 655 | argv[0], argv[d->optind - 1]); | 657 | argv[0], pfound->name); |
| 656 | #endif | 658 | #endif |
| 657 | } | 659 | } |
| 658 | d->__nextchar += strlen (d->__nextchar); | 660 | d->__nextchar += strlen (d->__nextchar); |
| @@ -736,13 +738,13 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 736 | 738 | ||
| 737 | { | 739 | { |
| 738 | char c = *d->__nextchar++; | 740 | char c = *d->__nextchar++; |
| 739 | char *temp = strchr (optstring, c); | 741 | const char *temp = strchr (optstring, c); |
| 740 | 742 | ||
| 741 | /* Increment `optind' when we start to process its last character. */ | 743 | /* Increment `optind' when we start to process its last character. */ |
| 742 | if (*d->__nextchar == '\0') | 744 | if (*d->__nextchar == '\0') |
| 743 | ++d->optind; | 745 | ++d->optind; |
| 744 | 746 | ||
| 745 | if (temp == NULL || c == ':') | 747 | if (temp == NULL || c == ':' || c == ';') |
| 746 | { | 748 | { |
| 747 | if (print_errors) | 749 | if (print_errors) |
| 748 | { | 750 | { |
| @@ -864,7 +866,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 864 | pfound = p; | 866 | pfound = p; |
| 865 | indfound = option_index; | 867 | indfound = option_index; |
| 866 | } | 868 | } |
| 867 | else | 869 | else if (long_only |
| 870 | || pfound->has_arg != p->has_arg | ||
| 871 | || pfound->flag != p->flag | ||
| 872 | || pfound->val != p->val) | ||
| 868 | /* Second or later nonexact match found. */ | 873 | /* Second or later nonexact match found. */ |
| 869 | ambig = 1; | 874 | ambig = 1; |
| 870 | } | 875 | } |
| @@ -876,7 +881,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 876 | char *buf; | 881 | char *buf; |
| 877 | 882 | ||
| 878 | if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"), | 883 | if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"), |
| 879 | argv[0], argv[d->optind]) >= 0) | 884 | argv[0], d->optarg) >= 0) |
| 880 | { | 885 | { |
| 881 | _IO_flockfile (stderr); | 886 | _IO_flockfile (stderr); |
| 882 | 887 | ||
| @@ -892,7 +897,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 892 | } | 897 | } |
| 893 | #else | 898 | #else |
| 894 | fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"), | 899 | fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"), |
| 895 | argv[0], argv[d->optind]); | 900 | argv[0], d->optarg); |
| 896 | #endif | 901 | #endif |
| 897 | } | 902 | } |
| 898 | d->__nextchar += strlen (d->__nextchar); | 903 | d->__nextchar += strlen (d->__nextchar); |
| @@ -955,8 +960,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 955 | char *buf; | 960 | char *buf; |
| 956 | 961 | ||
| 957 | if (__asprintf (&buf, _("\ | 962 | if (__asprintf (&buf, _("\ |
| 958 | %s: option '%s' requires an argument\n"), | 963 | %s: option '-W %s' requires an argument\n"), |
| 959 | argv[0], argv[d->optind - 1]) >= 0) | 964 | argv[0], pfound->name) >= 0) |
| 960 | { | 965 | { |
| 961 | _IO_flockfile (stderr); | 966 | _IO_flockfile (stderr); |
| 962 | 967 | ||
| @@ -972,15 +977,17 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 972 | free (buf); | 977 | free (buf); |
| 973 | } | 978 | } |
| 974 | #else | 979 | #else |
| 975 | fprintf (stderr, | 980 | fprintf (stderr, _("\ |
| 976 | _("%s: option '%s' requires an argument\n"), | 981 | %s: option '-W %s' requires an argument\n"), |
| 977 | argv[0], argv[d->optind - 1]); | 982 | argv[0], pfound->name); |
| 978 | #endif | 983 | #endif |
| 979 | } | 984 | } |
| 980 | d->__nextchar += strlen (d->__nextchar); | 985 | d->__nextchar += strlen (d->__nextchar); |
| 981 | return optstring[0] == ':' ? ':' : '?'; | 986 | return optstring[0] == ':' ? ':' : '?'; |
| 982 | } | 987 | } |
| 983 | } | 988 | } |
| 989 | else | ||
| 990 | d->optarg = NULL; | ||
| 984 | d->__nextchar += strlen (d->__nextchar); | 991 | d->__nextchar += strlen (d->__nextchar); |
| 985 | if (longind != NULL) | 992 | if (longind != NULL) |
| 986 | *longind = option_index; | 993 | *longind = option_index; |
diff --git a/gl/getopt_int.h b/gl/getopt_int.h index 169def5b..980b7507 100644 --- a/gl/getopt_int.h +++ b/gl/getopt_int.h | |||
| @@ -30,6 +30,40 @@ extern int _getopt_internal (int ___argc, char **___argv, | |||
| 30 | /* Reentrant versions which can handle parsing multiple argument | 30 | /* Reentrant versions which can handle parsing multiple argument |
| 31 | vectors at the same time. */ | 31 | vectors at the same time. */ |
| 32 | 32 | ||
| 33 | /* Describe how to deal with options that follow non-option ARGV-elements. | ||
| 34 | |||
| 35 | If the caller did not specify anything, | ||
| 36 | the default is REQUIRE_ORDER if the environment variable | ||
| 37 | POSIXLY_CORRECT is defined, PERMUTE otherwise. | ||
| 38 | |||
| 39 | REQUIRE_ORDER means don't recognize them as options; | ||
| 40 | stop option processing when the first non-option is seen. | ||
| 41 | This is what Unix does. | ||
| 42 | This mode of operation is selected by either setting the environment | ||
| 43 | variable POSIXLY_CORRECT, or using `+' as the first character | ||
| 44 | of the list of option characters, or by calling getopt. | ||
| 45 | |||
| 46 | PERMUTE is the default. We permute the contents of ARGV as we | ||
| 47 | scan, so that eventually all the non-options are at the end. | ||
| 48 | This allows options to be given in any order, even with programs | ||
| 49 | that were not written to expect this. | ||
| 50 | |||
| 51 | RETURN_IN_ORDER is an option available to programs that were | ||
| 52 | written to expect options and other ARGV-elements in any order | ||
| 53 | and that care about the ordering of the two. We describe each | ||
| 54 | non-option ARGV-element as if it were the argument of an option | ||
| 55 | with character code 1. Using `-' as the first character of the | ||
| 56 | list of option characters selects this mode of operation. | ||
| 57 | |||
| 58 | The special argument `--' forces an end of option-scanning regardless | ||
| 59 | of the value of `ordering'. In the case of RETURN_IN_ORDER, only | ||
| 60 | `--' can cause `getopt' to return -1 with `optind' != ARGC. */ | ||
| 61 | |||
| 62 | enum __ord | ||
| 63 | { | ||
| 64 | REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER | ||
| 65 | }; | ||
| 66 | |||
| 33 | /* Data type for reentrant functions. */ | 67 | /* Data type for reentrant functions. */ |
| 34 | struct _getopt_data | 68 | struct _getopt_data |
| 35 | { | 69 | { |
| @@ -54,39 +88,8 @@ struct _getopt_data | |||
| 54 | by advancing to the next ARGV-element. */ | 88 | by advancing to the next ARGV-element. */ |
| 55 | char *__nextchar; | 89 | char *__nextchar; |
| 56 | 90 | ||
| 57 | /* Describe how to deal with options that follow non-option ARGV-elements. | 91 | /* See __ord above. */ |
| 58 | 92 | enum __ord __ordering; | |
| 59 | If the caller did not specify anything, | ||
| 60 | the default is REQUIRE_ORDER if the environment variable | ||
| 61 | POSIXLY_CORRECT is defined, PERMUTE otherwise. | ||
| 62 | |||
| 63 | REQUIRE_ORDER means don't recognize them as options; | ||
| 64 | stop option processing when the first non-option is seen. | ||
| 65 | This is what Unix does. | ||
| 66 | This mode of operation is selected by either setting the environment | ||
| 67 | variable POSIXLY_CORRECT, or using `+' as the first character | ||
| 68 | of the list of option characters, or by calling getopt. | ||
| 69 | |||
| 70 | PERMUTE is the default. We permute the contents of ARGV as we | ||
| 71 | scan, so that eventually all the non-options are at the end. | ||
| 72 | This allows options to be given in any order, even with programs | ||
| 73 | that were not written to expect this. | ||
| 74 | |||
| 75 | RETURN_IN_ORDER is an option available to programs that were | ||
| 76 | written to expect options and other ARGV-elements in any order | ||
| 77 | and that care about the ordering of the two. We describe each | ||
| 78 | non-option ARGV-element as if it were the argument of an option | ||
| 79 | with character code 1. Using `-' as the first character of the | ||
| 80 | list of option characters selects this mode of operation. | ||
| 81 | |||
| 82 | The special argument `--' forces an end of option-scanning regardless | ||
| 83 | of the value of `ordering'. In the case of RETURN_IN_ORDER, only | ||
| 84 | `--' can cause `getopt' to return -1 with `optind' != ARGC. */ | ||
| 85 | |||
| 86 | enum | ||
| 87 | { | ||
| 88 | REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER | ||
| 89 | } __ordering; | ||
| 90 | 93 | ||
| 91 | /* If the POSIXLY_CORRECT environment variable is set | 94 | /* If the POSIXLY_CORRECT environment variable is set |
| 92 | or getopt was called. */ | 95 | or getopt was called. */ |
diff --git a/gl/localcharset.c b/gl/localcharset.c index a04dc446..fa2207fe 100644 --- a/gl/localcharset.c +++ b/gl/localcharset.c | |||
| @@ -369,10 +369,9 @@ locale_charset (void) | |||
| 369 | codeset = nl_langinfo (CODESET); | 369 | codeset = nl_langinfo (CODESET); |
| 370 | 370 | ||
| 371 | # ifdef __CYGWIN__ | 371 | # ifdef __CYGWIN__ |
| 372 | /* Cygwin 1.5.x does not have locales. nl_langinfo (CODESET) always | 372 | /* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always |
| 373 | returns "US-ASCII". As long as this is not fixed, return the suffix | 373 | returns "US-ASCII". Return the suffix of the locale name from the |
| 374 | of the locale name from the environment variables (if present) or | 374 | environment variables (if present) or the codepage as a number. */ |
| 375 | the codepage as a number. */ | ||
| 376 | if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) | 375 | if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) |
| 377 | { | 376 | { |
| 378 | const char *locale; | 377 | const char *locale; |
diff --git a/gl/m4/asm-underscore.m4 b/gl/m4/asm-underscore.m4 new file mode 100644 index 00000000..1736cc43 --- /dev/null +++ b/gl/m4/asm-underscore.m4 | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | # asm-underscore.m4 serial 1 | ||
| 2 | dnl Copyright (C) 2010 Free Software Foundation, Inc. | ||
| 3 | dnl This file is free software; the Free Software Foundation | ||
| 4 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 5 | dnl with or without modifications, as long as this notice is preserved. | ||
| 6 | |||
| 7 | dnl From Bruno Haible. Based on as-underscore.m4 in GNU clisp. | ||
| 8 | |||
| 9 | # gl_ASM_SYMBOL_PREFIX | ||
| 10 | # Tests for the prefix of C symbols at the assembly language level and the | ||
| 11 | # linker level. This prefix is either an underscore or empty. Defines the | ||
| 12 | # C macro USER_LABEL_PREFIX to this prefix, and sets ASM_SYMBOL_PREFIX to | ||
| 13 | # a stringified variant of this prefix. | ||
| 14 | |||
| 15 | AC_DEFUN([gl_ASM_SYMBOL_PREFIX], | ||
| 16 | [ | ||
| 17 | dnl We don't use GCC's __USER_LABEL_PREFIX__ here, because | ||
| 18 | dnl 1. It works only for GCC. | ||
| 19 | dnl 2. It is incorrectly defined on some platforms, in some GCC versions. | ||
| 20 | AC_CACHE_CHECK( | ||
| 21 | [whether C symbols are prefixed with underscore at the linker level], | ||
| 22 | [gl_cv_prog_as_underscore], | ||
| 23 | [cat > conftest.c <<EOF | ||
| 24 | #ifdef __cplusplus | ||
| 25 | extern "C" int foo (void); | ||
| 26 | #endif | ||
| 27 | int foo(void) { return 0; } | ||
| 28 | EOF | ||
| 29 | # Look for the assembly language name in the .s file. | ||
| 30 | AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -S conftest.c) >/dev/null 2>&1 | ||
| 31 | if grep _foo conftest.s >/dev/null ; then | ||
| 32 | gl_cv_prog_as_underscore=yes | ||
| 33 | else | ||
| 34 | gl_cv_prog_as_underscore=no | ||
| 35 | fi | ||
| 36 | rm -f conftest* | ||
| 37 | ]) | ||
| 38 | if test $gl_cv_prog_as_underscore = yes; then | ||
| 39 | USER_LABEL_PREFIX=_ | ||
| 40 | else | ||
| 41 | USER_LABEL_PREFIX= | ||
| 42 | fi | ||
| 43 | AC_DEFINE_UNQUOTED([USER_LABEL_PREFIX], [$USER_LABEL_PREFIX], | ||
| 44 | [Define to the prefix of C symbols at the assembler and linker level, | ||
| 45 | either an underscore or empty.]) | ||
| 46 | ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"' | ||
| 47 | AC_SUBST([ASM_SYMBOL_PREFIX]) | ||
| 48 | ]) | ||
diff --git a/gl/m4/getopt.m4 b/gl/m4/getopt.m4 index a19805ea..5b211e56 100644 --- a/gl/m4/getopt.m4 +++ b/gl/m4/getopt.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # getopt.m4 serial 24 | 1 | # getopt.m4 serial 28 |
| 2 | dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -79,8 +79,13 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS], | |||
| 79 | dnl Existence of the variable, in and of itself, is not a reason to replace | 79 | dnl Existence of the variable, in and of itself, is not a reason to replace |
| 80 | dnl getopt, but knowledge of the variable is needed to determine how to | 80 | dnl getopt, but knowledge of the variable is needed to determine how to |
| 81 | dnl reset and whether a reset reparses the environment. | 81 | dnl reset and whether a reset reparses the environment. |
| 82 | if test -z "$gl_replace_getopt" && test $gl_getopt_required = GNU; then | 82 | dnl Solaris supports neither optreset nor optind=0, but keeps no state that |
| 83 | AC_CHECK_DECLS([optreset], [], [], | 83 | dnl needs a reset beyond setting optind=1; detect Solaris by getopt_clip. |
| 84 | if test -z "$gl_replace_getopt"; then | ||
| 85 | AC_CHECK_DECLS([optreset], [], | ||
| 86 | [AC_CHECK_DECLS([getopt_clip], [], [], | ||
| 87 | [[#include <getopt.h>]]) | ||
| 88 | ], | ||
| 84 | [[#include <getopt.h>]]) | 89 | [[#include <getopt.h>]]) |
| 85 | fi | 90 | fi |
| 86 | 91 | ||
| @@ -89,6 +94,10 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS], | |||
| 89 | dnl is left over from earlier calls, and neither setting optind = 0 nor | 94 | dnl is left over from earlier calls, and neither setting optind = 0 nor |
| 90 | dnl setting optreset = 1 get rid of this internal state. | 95 | dnl setting optreset = 1 get rid of this internal state. |
| 91 | dnl POSIX is silent on optind vs. optreset, so we allow either behavior. | 96 | dnl POSIX is silent on optind vs. optreset, so we allow either behavior. |
| 97 | dnl POSIX 2008 does not specify leading '+' behavior, but see | ||
| 98 | dnl http://austingroupbugs.net/view.php?id=191 for a recommendation on | ||
| 99 | dnl the next version of POSIX. For now, we only guarantee leading '+' | ||
| 100 | dnl behavior with getopt-gnu. | ||
| 92 | if test -z "$gl_replace_getopt"; then | 101 | if test -z "$gl_replace_getopt"; then |
| 93 | AC_CACHE_CHECK([whether getopt is POSIX compatible], | 102 | AC_CACHE_CHECK([whether getopt is POSIX compatible], |
| 94 | [gl_cv_func_getopt_posix], | 103 | [gl_cv_func_getopt_posix], |
| @@ -99,7 +108,7 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS], | |||
| 99 | #include <stdlib.h> | 108 | #include <stdlib.h> |
| 100 | #include <string.h> | 109 | #include <string.h> |
| 101 | 110 | ||
| 102 | #if !HAVE_DECL_OPTRESET | 111 | #if !HAVE_DECL_OPTRESET && !HAVE_DECL_GETOPT_CLIP |
| 103 | # define OPTIND_MIN 0 | 112 | # define OPTIND_MIN 0 |
| 104 | #else | 113 | #else |
| 105 | # define OPTIND_MIN 1 | 114 | # define OPTIND_MIN 1 |
| @@ -167,6 +176,20 @@ main () | |||
| 167 | if (!(optind == 1)) | 176 | if (!(optind == 1)) |
| 168 | return 12; | 177 | return 12; |
| 169 | } | 178 | } |
| 179 | /* Detect MacOS 10.5 bug. */ | ||
| 180 | { | ||
| 181 | char *argv[3] = { "program", "-ab", NULL }; | ||
| 182 | optind = OPTIND_MIN; | ||
| 183 | opterr = 0; | ||
| 184 | if (getopt (2, argv, "ab:") != 'a') | ||
| 185 | return 13; | ||
| 186 | if (getopt (2, argv, "ab:") != '?') | ||
| 187 | return 14; | ||
| 188 | if (optopt != 'b') | ||
| 189 | return 15; | ||
| 190 | if (optind != 2) | ||
| 191 | return 16; | ||
| 192 | } | ||
| 170 | 193 | ||
| 171 | return 0; | 194 | return 0; |
| 172 | } | 195 | } |
| @@ -174,6 +197,7 @@ main () | |||
| 174 | [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no], | 197 | [gl_cv_func_getopt_posix=yes], [gl_cv_func_getopt_posix=no], |
| 175 | [case "$host_os" in | 198 | [case "$host_os" in |
| 176 | mingw*) gl_cv_func_getopt_posix="guessing no";; | 199 | mingw*) gl_cv_func_getopt_posix="guessing no";; |
| 200 | darwin*) gl_cv_func_getopt_posix="guessing no";; | ||
| 177 | *) gl_cv_func_getopt_posix="guessing yes";; | 201 | *) gl_cv_func_getopt_posix="guessing yes";; |
| 178 | esac | 202 | esac |
| 179 | ]) | 203 | ]) |
| @@ -234,6 +258,15 @@ main () | |||
| 234 | if (getopt (3, argv, "-p") != 'p') | 258 | if (getopt (3, argv, "-p") != 'p') |
| 235 | return 7; | 259 | return 7; |
| 236 | } | 260 | } |
| 261 | /* This code fails on glibc 2.11. */ | ||
| 262 | { | ||
| 263 | char *argv[] = { "program", "-b", "-a", NULL }; | ||
| 264 | optind = opterr = 0; | ||
| 265 | if (getopt (3, argv, "+:a:b") != 'b') | ||
| 266 | return 8; | ||
| 267 | if (getopt (3, argv, "+:a:b") != ':') | ||
| 268 | return 9; | ||
| 269 | } | ||
| 237 | return 0; | 270 | return 0; |
| 238 | ]])], | 271 | ]])], |
| 239 | [gl_cv_func_getopt_gnu=yes], | 272 | [gl_cv_func_getopt_gnu=yes], |
diff --git a/gl/m4/gettext.m4 b/gl/m4/gettext.m4 index d6dc3fe2..f84e6a5d 100644 --- a/gl/m4/gettext.m4 +++ b/gl/m4/gettext.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # gettext.m4 serial 62 (gettext-0.18) | 1 | # gettext.m4 serial 63 (gettext-0.18) |
| 2 | dnl Copyright (C) 1995-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 1995-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -15,7 +15,7 @@ dnl They are *not* in the public domain. | |||
| 15 | 15 | ||
| 16 | dnl Authors: | 16 | dnl Authors: |
| 17 | dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. | 17 | dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. |
| 18 | dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006. | 18 | dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006, 2008-2010. |
| 19 | 19 | ||
| 20 | dnl Macro to add for using GNU gettext. | 20 | dnl Macro to add for using GNU gettext. |
| 21 | 21 | ||
| @@ -60,6 +60,8 @@ AC_DEFUN([AM_GNU_GETTEXT], | |||
| 60 | ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], , | 60 | ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], , |
| 61 | [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT | 61 | [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT |
| 62 | ])])])])]) | 62 | ])])])])]) |
| 63 | ifelse(ifelse([$1], [], [old])[]ifelse([$1], [no-libtool], [old]), [old], | ||
| 64 | [AC_DIAGNOSE([obsolete], [Use of AM_GNU_GETTEXT without [external] argument is deprecated.])]) | ||
| 63 | ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , | 65 | ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , |
| 64 | [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT | 66 | [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT |
| 65 | ])])])]) | 67 | ])])])]) |
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4 index 0ac6b969..97b1849b 100644 --- a/gl/m4/gnulib-cache.m4 +++ b/gl/m4/gnulib-cache.m4 | |||
| @@ -15,12 +15,13 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | # Specification in the form of a command-line invocation: | 17 | # Specification in the form of a command-line invocation: |
| 18 | # gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-libtool --macro-prefix=gl base64 dirname floorf fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex timegm vasprintf vsnprintf | 18 | # gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-libtool --macro-prefix=gl --no-vc-files base64 crypto/sha1 dirname floorf fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex timegm vasprintf vsnprintf |
| 19 | 19 | ||
| 20 | # Specification in the form of a few gnulib-tool.m4 macro invocations: | 20 | # Specification in the form of a few gnulib-tool.m4 macro invocations: |
| 21 | gl_LOCAL_DIR([]) | 21 | gl_LOCAL_DIR([]) |
| 22 | gl_MODULES([ | 22 | gl_MODULES([ |
| 23 | base64 | 23 | base64 |
| 24 | crypto/sha1 | ||
| 24 | dirname | 25 | dirname |
| 25 | floorf | 26 | floorf |
| 26 | fsusage | 27 | fsusage |
| @@ -45,3 +46,4 @@ gl_LIB([libgnu]) | |||
| 45 | gl_MAKEFILE_NAME([]) | 46 | gl_MAKEFILE_NAME([]) |
| 46 | gl_MACRO_PREFIX([gl]) | 47 | gl_MACRO_PREFIX([gl]) |
| 47 | gl_PO_DOMAIN([]) | 48 | gl_PO_DOMAIN([]) |
| 49 | gl_VC_FILES([false]) | ||
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4 index 9cc519e7..4c7ac30d 100644 --- a/gl/m4/gnulib-common.m4 +++ b/gl/m4/gnulib-common.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # gnulib-common.m4 serial 18 | 1 | # gnulib-common.m4 serial 20 |
| 2 | dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -35,6 +35,12 @@ AC_DEFUN([gl_COMMON_BODY], [ | |||
| 35 | is a misnomer outside of parameter lists. */ | 35 | is a misnomer outside of parameter lists. */ |
| 36 | #define _UNUSED_PARAMETER_ _GL_UNUSED | 36 | #define _UNUSED_PARAMETER_ _GL_UNUSED |
| 37 | ]) | 37 | ]) |
| 38 | dnl Preparation for running test programs: | ||
| 39 | dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not | ||
| 40 | dnl to /dev/tty, so they can be redirected to log files. Such diagnostics | ||
| 41 | dnl arise e.g., in the macros gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N. | ||
| 42 | LIBC_FATAL_STDERR_=1 | ||
| 43 | export LIBC_FATAL_STDERR_ | ||
| 38 | ]) | 44 | ]) |
| 39 | 45 | ||
| 40 | # gl_MODULE_INDICATOR_CONDITION | 46 | # gl_MODULE_INDICATOR_CONDITION |
| @@ -132,6 +138,7 @@ m4_ifdef([AC_PROG_MKDIR_P], [ | |||
| 132 | # so that mixed use of GNU C and GNU C++ and mixed use of Sun C and Sun C++ | 138 | # so that mixed use of GNU C and GNU C++ and mixed use of Sun C and Sun C++ |
| 133 | # works. | 139 | # works. |
| 134 | # This definition can be removed once autoconf >= 2.62 can be assumed. | 140 | # This definition can be removed once autoconf >= 2.62 can be assumed. |
| 141 | m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.62]),[-1],[ | ||
| 135 | AC_DEFUN([AC_C_RESTRICT], | 142 | AC_DEFUN([AC_C_RESTRICT], |
| 136 | [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict], | 143 | [AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict], |
| 137 | [ac_cv_c_restrict=no | 144 | [ac_cv_c_restrict=no |
| @@ -169,6 +176,7 @@ AC_DEFUN([AC_C_RESTRICT], | |||
| 169 | *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;; | 176 | *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;; |
| 170 | esac | 177 | esac |
| 171 | ]) | 178 | ]) |
| 179 | ]) | ||
| 172 | 180 | ||
| 173 | # gl_BIGENDIAN | 181 | # gl_BIGENDIAN |
| 174 | # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd. | 182 | # is like AC_C_BIGENDIAN, except that it can be AC_REQUIREd. |
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index 4a956e44..f4031cc7 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 | |||
| @@ -26,7 +26,6 @@ AC_DEFUN([gl_EARLY], | |||
| 26 | m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable | 26 | m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable |
| 27 | AC_REQUIRE([AC_PROG_RANLIB]) | 27 | AC_REQUIRE([AC_PROG_RANLIB]) |
| 28 | # Code from module alignof: | 28 | # Code from module alignof: |
| 29 | # Code from module alloca: | ||
| 30 | # Code from module alloca-opt: | 29 | # Code from module alloca-opt: |
| 31 | # Code from module arg-nonnull: | 30 | # Code from module arg-nonnull: |
| 32 | # Code from module arpa_inet: | 31 | # Code from module arpa_inet: |
| @@ -37,6 +36,7 @@ AC_DEFUN([gl_EARLY], | |||
| 37 | # Code from module cloexec: | 36 | # Code from module cloexec: |
| 38 | # Code from module close-hook: | 37 | # Code from module close-hook: |
| 39 | # Code from module configmake: | 38 | # Code from module configmake: |
| 39 | # Code from module crypto/sha1: | ||
| 40 | # Code from module dirname: | 40 | # Code from module dirname: |
| 41 | # Code from module dirname-lgpl: | 41 | # Code from module dirname-lgpl: |
| 42 | # Code from module double-slash-root: | 42 | # Code from module double-slash-root: |
| @@ -146,7 +146,6 @@ AC_DEFUN([gl_INIT], | |||
| 146 | gl_COMMON | 146 | gl_COMMON |
| 147 | gl_source_base='gl' | 147 | gl_source_base='gl' |
| 148 | # Code from module alignof: | 148 | # Code from module alignof: |
| 149 | # Code from module alloca: | ||
| 150 | # Code from module alloca-opt: | 149 | # Code from module alloca-opt: |
| 151 | gl_FUNC_ALLOCA | 150 | gl_FUNC_ALLOCA |
| 152 | # Code from module arg-nonnull: | 151 | # Code from module arg-nonnull: |
| @@ -166,6 +165,8 @@ AC_DEFUN([gl_INIT], | |||
| 166 | gl_MODULE_INDICATOR_FOR_TESTS([cloexec]) | 165 | gl_MODULE_INDICATOR_FOR_TESTS([cloexec]) |
| 167 | # Code from module close-hook: | 166 | # Code from module close-hook: |
| 168 | # Code from module configmake: | 167 | # Code from module configmake: |
| 168 | # Code from module crypto/sha1: | ||
| 169 | gl_SHA1 | ||
| 169 | # Code from module dirname: | 170 | # Code from module dirname: |
| 170 | gl_DIRNAME | 171 | gl_DIRNAME |
| 171 | gl_MODULE_INDICATOR([dirname]) | 172 | gl_MODULE_INDICATOR([dirname]) |
| @@ -222,7 +223,7 @@ AC_DEFUN([gl_INIT], | |||
| 222 | gl_FUNC_GETOPT_POSIX | 223 | gl_FUNC_GETOPT_POSIX |
| 223 | # Code from module gettext: | 224 | # Code from module gettext: |
| 224 | dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. | 225 | dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. |
| 225 | AM_GNU_GETTEXT_VERSION([0.17]) | 226 | AM_GNU_GETTEXT_VERSION([0.18.1]) |
| 226 | # Code from module gettext-h: | 227 | # Code from module gettext-h: |
| 227 | AC_SUBST([LIBINTL]) | 228 | AC_SUBST([LIBINTL]) |
| 228 | AC_SUBST([LTLIBINTL]) | 229 | AC_SUBST([LTLIBINTL]) |
| @@ -522,7 +523,6 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 522 | build-aux/config.rpath | 523 | build-aux/config.rpath |
| 523 | build-aux/warn-on-use.h | 524 | build-aux/warn-on-use.h |
| 524 | lib/alignof.h | 525 | lib/alignof.h |
| 525 | lib/alloca.c | ||
| 526 | lib/alloca.in.h | 526 | lib/alloca.in.h |
| 527 | lib/arpa_inet.in.h | 527 | lib/arpa_inet.in.h |
| 528 | lib/asnprintf.c | 528 | lib/asnprintf.c |
| @@ -613,6 +613,8 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 613 | lib/safe-read.h | 613 | lib/safe-read.h |
| 614 | lib/safe-write.c | 614 | lib/safe-write.c |
| 615 | lib/safe-write.h | 615 | lib/safe-write.h |
| 616 | lib/sha1.c | ||
| 617 | lib/sha1.h | ||
| 616 | lib/size_max.h | 618 | lib/size_max.h |
| 617 | lib/snprintf.c | 619 | lib/snprintf.c |
| 618 | lib/sockets.c | 620 | lib/sockets.c |
| @@ -660,6 +662,7 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 660 | m4/00gnulib.m4 | 662 | m4/00gnulib.m4 |
| 661 | m4/alloca.m4 | 663 | m4/alloca.m4 |
| 662 | m4/arpa_inet_h.m4 | 664 | m4/arpa_inet_h.m4 |
| 665 | m4/asm-underscore.m4 | ||
| 663 | m4/base64.m4 | 666 | m4/base64.m4 |
| 664 | m4/btowc.m4 | 667 | m4/btowc.m4 |
| 665 | m4/c-strtod.m4 | 668 | m4/c-strtod.m4 |
| @@ -740,6 +743,7 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 740 | m4/safe-read.m4 | 743 | m4/safe-read.m4 |
| 741 | m4/safe-write.m4 | 744 | m4/safe-write.m4 |
| 742 | m4/servent.m4 | 745 | m4/servent.m4 |
| 746 | m4/sha1.m4 | ||
| 743 | m4/size_max.m4 | 747 | m4/size_max.m4 |
| 744 | m4/snprintf.m4 | 748 | m4/snprintf.m4 |
| 745 | m4/sockets.m4 | 749 | m4/sockets.m4 |
diff --git a/gl/m4/iconv.m4 b/gl/m4/iconv.m4 index f46ff142..e2041b9b 100644 --- a/gl/m4/iconv.m4 +++ b/gl/m4/iconv.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # iconv.m4 serial 9 (gettext-0.18) | 1 | # iconv.m4 serial 11 (gettext-0.18.1) |
| 2 | dnl Copyright (C) 2000-2002, 2007-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2000-2002, 2007-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -170,7 +170,22 @@ int main () | |||
| 170 | AC_SUBST([LTLIBICONV]) | 170 | AC_SUBST([LTLIBICONV]) |
| 171 | ]) | 171 | ]) |
| 172 | 172 | ||
| 173 | AC_DEFUN([AM_ICONV], | 173 | dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to |
| 174 | dnl avoid warnings like | ||
| 175 | dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required". | ||
| 176 | dnl This is tricky because of the way 'aclocal' is implemented: | ||
| 177 | dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN. | ||
| 178 | dnl Otherwise aclocal's initial scan pass would miss the macro definition. | ||
| 179 | dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions. | ||
| 180 | dnl Otherwise aclocal would emit many "Use of uninitialized value $1" | ||
| 181 | dnl warnings. | ||
| 182 | m4_define([gl_iconv_AC_DEFUN], | ||
| 183 | m4_version_prereq([2.64], | ||
| 184 | [[AC_DEFUN_ONCE( | ||
| 185 | [$1], [$2])]], | ||
| 186 | [[AC_DEFUN( | ||
| 187 | [$1], [$2])]])) | ||
| 188 | gl_iconv_AC_DEFUN([AM_ICONV], | ||
| 174 | [ | 189 | [ |
| 175 | AM_ICONV_LINK | 190 | AM_ICONV_LINK |
| 176 | if test "$am_cv_func_iconv" = yes; then | 191 | if test "$am_cv_func_iconv" = yes; then |
diff --git a/gl/m4/intl.m4 b/gl/m4/intl.m4 index 5e17fea9..335b23c2 100644 --- a/gl/m4/intl.m4 +++ b/gl/m4/intl.m4 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | # intl.m4 serial 8 (gettext-0.17) | 1 | # intl.m4 serial 17 (gettext-0.18) |
| 2 | dnl Copyright (C) 1995-2007, 2009-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 1995-2009 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| 5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
| @@ -15,9 +15,9 @@ dnl They are *not* in the public domain. | |||
| 15 | 15 | ||
| 16 | dnl Authors: | 16 | dnl Authors: |
| 17 | dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. | 17 | dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. |
| 18 | dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006. | 18 | dnl Bruno Haible <haible@clisp.cons.org>, 2000-2009. |
| 19 | 19 | ||
| 20 | AC_PREREQ(2.52) | 20 | AC_PREREQ([2.52]) |
| 21 | 21 | ||
| 22 | dnl Checks for all prerequisites of the intl subdirectory, | 22 | dnl Checks for all prerequisites of the intl subdirectory, |
| 23 | dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, | 23 | dnl except for INTL_LIBTOOL_SUFFIX_PREFIX (and possibly LIBTOOL), INTLOBJS, |
| @@ -40,14 +40,24 @@ AC_DEFUN([AM_INTL_SUBDIR], | |||
| 40 | AC_REQUIRE([gt_PRINTF_POSIX]) | 40 | AC_REQUIRE([gt_PRINTF_POSIX]) |
| 41 | AC_REQUIRE([gl_GLIBC21])dnl | 41 | AC_REQUIRE([gl_GLIBC21])dnl |
| 42 | AC_REQUIRE([gl_XSIZE])dnl | 42 | AC_REQUIRE([gl_XSIZE])dnl |
| 43 | AC_REQUIRE([gl_FCNTL_O_FLAGS])dnl | ||
| 43 | AC_REQUIRE([gt_INTL_MACOSX])dnl | 44 | AC_REQUIRE([gt_INTL_MACOSX])dnl |
| 44 | 45 | ||
| 46 | dnl Support for automake's --enable-silent-rules. | ||
| 47 | case "$enable_silent_rules" in | ||
| 48 | yes) INTL_DEFAULT_VERBOSITY=0;; | ||
| 49 | no) INTL_DEFAULT_VERBOSITY=1;; | ||
| 50 | *) INTL_DEFAULT_VERBOSITY=1;; | ||
| 51 | esac | ||
| 52 | AC_SUBST([INTL_DEFAULT_VERBOSITY]) | ||
| 53 | |||
| 45 | AC_CHECK_TYPE([ptrdiff_t], , | 54 | AC_CHECK_TYPE([ptrdiff_t], , |
| 46 | [AC_DEFINE([ptrdiff_t], [long], | 55 | [AC_DEFINE([ptrdiff_t], [long], |
| 47 | [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) | 56 | [Define as the type of the result of subtracting two pointers, if the system doesn't define it.]) |
| 48 | ]) | 57 | ]) |
| 49 | AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) | 58 | AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) |
| 50 | AC_CHECK_FUNCS([asprintf fwprintf putenv setenv setlocale snprintf wcslen]) | 59 | AC_CHECK_FUNCS([asprintf fwprintf newlocale putenv setenv setlocale \ |
| 60 | snprintf strnlen wcslen wcsnlen mbrtowc wcrtomb]) | ||
| 51 | 61 | ||
| 52 | dnl Use the _snprintf function only if it is declared (because on NetBSD it | 62 | dnl Use the _snprintf function only if it is declared (because on NetBSD it |
| 53 | dnl is defined as a weak alias of snprintf; we prefer to use the latter). | 63 | dnl is defined as a weak alias of snprintf; we prefer to use the latter). |
| @@ -78,6 +88,12 @@ AC_DEFUN([AM_INTL_SUBDIR], | |||
| 78 | HAVE_SNPRINTF=0 | 88 | HAVE_SNPRINTF=0 |
| 79 | fi | 89 | fi |
| 80 | AC_SUBST([HAVE_SNPRINTF]) | 90 | AC_SUBST([HAVE_SNPRINTF]) |
| 91 | if test "$ac_cv_func_newlocale" = yes; then | ||
| 92 | HAVE_NEWLOCALE=1 | ||
| 93 | else | ||
| 94 | HAVE_NEWLOCALE=0 | ||
| 95 | fi | ||
| 96 | AC_SUBST([HAVE_NEWLOCALE]) | ||
| 81 | if test "$ac_cv_func_wprintf" = yes; then | 97 | if test "$ac_cv_func_wprintf" = yes; then |
| 82 | HAVE_WPRINTF=1 | 98 | HAVE_WPRINTF=1 |
| 83 | else | 99 | else |
| @@ -146,22 +162,31 @@ AC_DEFUN([AM_INTL_SUBDIR], | |||
| 146 | #define __libc_lock_lock_recursive gl_recursive_lock_lock | 162 | #define __libc_lock_lock_recursive gl_recursive_lock_lock |
| 147 | #define __libc_lock_unlock_recursive gl_recursive_lock_unlock | 163 | #define __libc_lock_unlock_recursive gl_recursive_lock_unlock |
| 148 | #define glthread_in_use libintl_thread_in_use | 164 | #define glthread_in_use libintl_thread_in_use |
| 149 | #define glthread_lock_init libintl_lock_init | 165 | #define glthread_lock_init_func libintl_lock_init_func |
| 150 | #define glthread_lock_lock libintl_lock_lock | 166 | #define glthread_lock_lock_func libintl_lock_lock_func |
| 151 | #define glthread_lock_unlock libintl_lock_unlock | 167 | #define glthread_lock_unlock_func libintl_lock_unlock_func |
| 152 | #define glthread_lock_destroy libintl_lock_destroy | 168 | #define glthread_lock_destroy_func libintl_lock_destroy_func |
| 153 | #define glthread_rwlock_init libintl_rwlock_init | 169 | #define glthread_rwlock_init_multithreaded libintl_rwlock_init_multithreaded |
| 154 | #define glthread_rwlock_rdlock libintl_rwlock_rdlock | 170 | #define glthread_rwlock_init_func libintl_rwlock_init_func |
| 155 | #define glthread_rwlock_wrlock libintl_rwlock_wrlock | 171 | #define glthread_rwlock_rdlock_multithreaded libintl_rwlock_rdlock_multithreaded |
| 156 | #define glthread_rwlock_unlock libintl_rwlock_unlock | 172 | #define glthread_rwlock_rdlock_func libintl_rwlock_rdlock_func |
| 157 | #define glthread_rwlock_destroy libintl_rwlock_destroy | 173 | #define glthread_rwlock_wrlock_multithreaded libintl_rwlock_wrlock_multithreaded |
| 158 | #define glthread_recursive_lock_init libintl_recursive_lock_init | 174 | #define glthread_rwlock_wrlock_func libintl_rwlock_wrlock_func |
| 159 | #define glthread_recursive_lock_lock libintl_recursive_lock_lock | 175 | #define glthread_rwlock_unlock_multithreaded libintl_rwlock_unlock_multithreaded |
| 160 | #define glthread_recursive_lock_unlock libintl_recursive_lock_unlock | 176 | #define glthread_rwlock_unlock_func libintl_rwlock_unlock_func |
| 161 | #define glthread_recursive_lock_destroy libintl_recursive_lock_destroy | 177 | #define glthread_rwlock_destroy_multithreaded libintl_rwlock_destroy_multithreaded |
| 162 | #define glthread_once libintl_once | 178 | #define glthread_rwlock_destroy_func libintl_rwlock_destroy_func |
| 163 | #define glthread_once_call libintl_once_call | 179 | #define glthread_recursive_lock_init_multithreaded libintl_recursive_lock_init_multithreaded |
| 180 | #define glthread_recursive_lock_init_func libintl_recursive_lock_init_func | ||
| 181 | #define glthread_recursive_lock_lock_multithreaded libintl_recursive_lock_lock_multithreaded | ||
| 182 | #define glthread_recursive_lock_lock_func libintl_recursive_lock_lock_func | ||
| 183 | #define glthread_recursive_lock_unlock_multithreaded libintl_recursive_lock_unlock_multithreaded | ||
| 184 | #define glthread_recursive_lock_unlock_func libintl_recursive_lock_unlock_func | ||
| 185 | #define glthread_recursive_lock_destroy_multithreaded libintl_recursive_lock_destroy_multithreaded | ||
| 186 | #define glthread_recursive_lock_destroy_func libintl_recursive_lock_destroy_func | ||
| 187 | #define glthread_once_func libintl_once_func | ||
| 164 | #define glthread_once_singlethreaded libintl_once_singlethreaded | 188 | #define glthread_once_singlethreaded libintl_once_singlethreaded |
| 189 | #define glthread_once_multithreaded libintl_once_multithreaded | ||
| 165 | ]) | 190 | ]) |
| 166 | ]) | 191 | ]) |
| 167 | 192 | ||
| @@ -198,40 +223,24 @@ AC_DEFUN([gt_INTL_SUBDIR_CORE], | |||
| 198 | AC_TRY_LINK( | 223 | AC_TRY_LINK( |
| 199 | [int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; }], | 224 | [int foo (int a) { a = __builtin_expect (a, 10); return a == 10 ? 0 : 1; }], |
| 200 | [], | 225 | [], |
| 201 | [AC_DEFINE([HAVE_BUILTIN_EXPECT], 1, | 226 | [AC_DEFINE([HAVE_BUILTIN_EXPECT], [1], |
| 202 | [Define to 1 if the compiler understands __builtin_expect.])]) | 227 | [Define to 1 if the compiler understands __builtin_expect.])]) |
| 203 | 228 | ||
| 204 | AC_CHECK_HEADERS([argz.h inttypes.h limits.h unistd.h sys/param.h]) | 229 | AC_CHECK_HEADERS([argz.h inttypes.h limits.h unistd.h sys/param.h]) |
| 205 | AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \ | 230 | AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \ |
| 206 | stpcpy strcasecmp strdup strtoul tsearch argz_count argz_stringify \ | 231 | stpcpy strcasecmp strdup strtoul tsearch uselocale argz_count \ |
| 207 | argz_next __fsetlocking]) | 232 | argz_stringify argz_next __fsetlocking]) |
| 208 | 233 | ||
| 209 | dnl Use the *_unlocked functions only if they are declared. | 234 | dnl Use the *_unlocked functions only if they are declared. |
| 210 | dnl (because some of them were defined without being declared in Solaris | 235 | dnl (because some of them were defined without being declared in Solaris |
| 211 | dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built | 236 | dnl 2.5.1 but were removed in Solaris 2.6, whereas we want binaries built |
| 212 | dnl on Solaris 2.5.1 to run on Solaris 2.6). | 237 | dnl on Solaris 2.5.1 to run on Solaris 2.6). |
| 213 | dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. | 238 | dnl Don't use AC_CHECK_DECLS because it isn't supported in autoconf-2.13. |
| 214 | gt_CHECK_DECL(feof_unlocked, [#include <stdio.h>]) | 239 | gt_CHECK_DECL([feof_unlocked], [#include <stdio.h>]) |
| 215 | gt_CHECK_DECL(fgets_unlocked, [#include <stdio.h>]) | 240 | gt_CHECK_DECL([fgets_unlocked], [#include <stdio.h>]) |
| 216 | 241 | ||
| 217 | AM_ICONV | 242 | AM_ICONV |
| 218 | 243 | ||
| 219 | dnl glibc >= 2.4 has a NL_LOCALE_NAME macro when _GNU_SOURCE is defined, | ||
| 220 | dnl and a _NL_LOCALE_NAME macro always. | ||
| 221 | AC_CACHE_CHECK([for NL_LOCALE_NAME macro], gt_cv_nl_locale_name, | ||
| 222 | [AC_TRY_LINK([#include <langinfo.h> | ||
| 223 | #include <locale.h>], | ||
| 224 | [char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES)); | ||
| 225 | return !cs; | ||
| 226 | ], | ||
| 227 | gt_cv_nl_locale_name=yes, | ||
| 228 | gt_cv_nl_locale_name=no) | ||
| 229 | ]) | ||
| 230 | if test $gt_cv_nl_locale_name = yes; then | ||
| 231 | AC_DEFINE(HAVE_NL_LOCALE_NAME, 1, | ||
| 232 | [Define if you have <langinfo.h> and it defines the NL_LOCALE_NAME macro if _GNU_SOURCE is defined.]) | ||
| 233 | fi | ||
| 234 | |||
| 235 | dnl intl/plural.c is generated from intl/plural.y. It requires bison, | 244 | dnl intl/plural.c is generated from intl/plural.y. It requires bison, |
| 236 | dnl because plural.y uses bison specific features. It requires at least | 245 | dnl because plural.y uses bison specific features. It requires at least |
| 237 | dnl bison-1.26 because earlier versions generate a plural.c that doesn't | 246 | dnl bison-1.26 because earlier versions generate a plural.c that doesn't |
| @@ -269,7 +278,7 @@ dnl gt_CHECK_DECL(FUNC, INCLUDES) | |||
| 269 | dnl Check whether a function is declared. | 278 | dnl Check whether a function is declared. |
| 270 | AC_DEFUN([gt_CHECK_DECL], | 279 | AC_DEFUN([gt_CHECK_DECL], |
| 271 | [ | 280 | [ |
| 272 | AC_CACHE_CHECK([whether $1 is declared], ac_cv_have_decl_$1, | 281 | AC_CACHE_CHECK([whether $1 is declared], [ac_cv_have_decl_$1], |
| 273 | [AC_TRY_COMPILE([$2], [ | 282 | [AC_TRY_COMPILE([$2], [ |
| 274 | #ifndef $1 | 283 | #ifndef $1 |
| 275 | char *p = (char *) $1; | 284 | char *p = (char *) $1; |
diff --git a/gl/m4/lib-link.m4 b/gl/m4/lib-link.m4 index 90e1ac91..59b367df 100644 --- a/gl/m4/lib-link.m4 +++ b/gl/m4/lib-link.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # lib-link.m4 serial 20 (gettext-0.18) | 1 | # lib-link.m4 serial 23 (gettext-0.18.2) |
| 2 | dnl Copyright (C) 2001-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2001-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -18,9 +18,9 @@ AC_DEFUN([AC_LIB_LINKFLAGS], | |||
| 18 | [ | 18 | [ |
| 19 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) | 19 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) |
| 20 | AC_REQUIRE([AC_LIB_RPATH]) | 20 | AC_REQUIRE([AC_LIB_RPATH]) |
| 21 | pushdef([Name],[translit([$1],[./-], [___])]) | 21 | pushdef([Name],[m4_translit([$1],[./+-], [____])]) |
| 22 | pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], | 22 | pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], |
| 23 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) | 23 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) |
| 24 | AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ | 24 | AC_CACHE_CHECK([how to link with lib[]$1], [ac_cv_lib[]Name[]_libs], [ |
| 25 | AC_LIB_LINKFLAGS_BODY([$1], [$2]) | 25 | AC_LIB_LINKFLAGS_BODY([$1], [$2]) |
| 26 | ac_cv_lib[]Name[]_libs="$LIB[]NAME" | 26 | ac_cv_lib[]Name[]_libs="$LIB[]NAME" |
| @@ -58,9 +58,9 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], | |||
| 58 | [ | 58 | [ |
| 59 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) | 59 | AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) |
| 60 | AC_REQUIRE([AC_LIB_RPATH]) | 60 | AC_REQUIRE([AC_LIB_RPATH]) |
| 61 | pushdef([Name],[translit([$1],[./-], [___])]) | 61 | pushdef([Name],[m4_translit([$1],[./+-], [____])]) |
| 62 | pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], | 62 | pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], |
| 63 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) | 63 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) |
| 64 | 64 | ||
| 65 | dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME | 65 | dnl Search for lib[]Name and define LIB[]NAME, LTLIB[]NAME and INC[]NAME |
| 66 | dnl accordingly. | 66 | dnl accordingly. |
| @@ -74,7 +74,17 @@ AC_DEFUN([AC_LIB_HAVE_LINKFLAGS], | |||
| 74 | 74 | ||
| 75 | AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ | 75 | AC_CACHE_CHECK([for lib[]$1], [ac_cv_lib[]Name], [ |
| 76 | ac_save_LIBS="$LIBS" | 76 | ac_save_LIBS="$LIBS" |
| 77 | LIBS="$LIBS $LIB[]NAME" | 77 | dnl If $LIB[]NAME contains some -l options, add it to the end of LIBS, |
| 78 | dnl because these -l options might require -L options that are present in | ||
| 79 | dnl LIBS. -l options benefit only from the -L options listed before it. | ||
| 80 | dnl Otherwise, add it to the front of LIBS, because it may be a static | ||
| 81 | dnl library that depends on another static library that is present in LIBS. | ||
| 82 | dnl Static libraries benefit only from the static libraries listed after | ||
| 83 | dnl it. | ||
| 84 | case " $LIB[]NAME" in | ||
| 85 | *" -l"*) LIBS="$LIBS $LIB[]NAME" ;; | ||
| 86 | *) LIBS="$LIB[]NAME $LIBS" ;; | ||
| 87 | esac | ||
| 78 | AC_TRY_LINK([$3], [$4], | 88 | AC_TRY_LINK([$3], [$4], |
| 79 | [ac_cv_lib[]Name=yes], | 89 | [ac_cv_lib[]Name=yes], |
| 80 | [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])']) | 90 | [ac_cv_lib[]Name='m4_if([$5], [], [no], [[$5]])']) |
| @@ -147,13 +157,13 @@ dnl package. This declaration must occur before an AC_LIB_LINKFLAGS or similar | |||
| 147 | dnl macro call that searches for libname. | 157 | dnl macro call that searches for libname. |
| 148 | AC_DEFUN([AC_LIB_FROMPACKAGE], | 158 | AC_DEFUN([AC_LIB_FROMPACKAGE], |
| 149 | [ | 159 | [ |
| 150 | pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], | 160 | pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], |
| 151 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) | 161 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) |
| 152 | define([acl_frompackage_]NAME, [$2]) | 162 | define([acl_frompackage_]NAME, [$2]) |
| 153 | popdef([NAME]) | 163 | popdef([NAME]) |
| 154 | pushdef([PACK],[$2]) | 164 | pushdef([PACK],[$2]) |
| 155 | pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-], | 165 | pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], |
| 156 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) | 166 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) |
| 157 | define([acl_libsinpackage_]PACKUP, | 167 | define([acl_libsinpackage_]PACKUP, |
| 158 | m4_ifdef([acl_libsinpackage_]PACKUP, [acl_libsinpackage_]PACKUP[[, ]],)[lib$1]) | 168 | m4_ifdef([acl_libsinpackage_]PACKUP, [acl_libsinpackage_]PACKUP[[, ]],)[lib$1]) |
| 159 | popdef([PACKUP]) | 169 | popdef([PACKUP]) |
| @@ -168,14 +178,14 @@ dnl in ${LIB${NAME}_PREFIX}/$acl_libdirstem. | |||
| 168 | AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | 178 | AC_DEFUN([AC_LIB_LINKFLAGS_BODY], |
| 169 | [ | 179 | [ |
| 170 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) | 180 | AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) |
| 171 | pushdef([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-], | 181 | pushdef([NAME],[m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./+-], |
| 172 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) | 182 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) |
| 173 | pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])]) | 183 | pushdef([PACK],[m4_ifdef([acl_frompackage_]NAME, [acl_frompackage_]NAME, lib[$1])]) |
| 174 | pushdef([PACKUP],[translit(PACK,[abcdefghijklmnopqrstuvwxyz./-], | 184 | pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], |
| 175 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])]) | 185 | [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) |
| 176 | pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])]) | 186 | pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])]) |
| 177 | dnl Autoconf >= 2.61 supports dots in --with options. | 187 | dnl Autoconf >= 2.61 supports dots in --with options. |
| 178 | pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[translit(PACK,[.],[_])],PACK)]) | 188 | pushdef([P_A_C_K],[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.61]),[-1],[m4_translit(PACK,[.],[_])],PACK)]) |
| 179 | dnl By default, look in $includedir and $libdir. | 189 | dnl By default, look in $includedir and $libdir. |
| 180 | use_additional=yes | 190 | use_additional=yes |
| 181 | AC_LIB_WITH_FINAL_PREFIX([ | 191 | AC_LIB_WITH_FINAL_PREFIX([ |
| @@ -232,7 +242,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY], | |||
| 232 | names_already_handled="$names_already_handled $name" | 242 | names_already_handled="$names_already_handled $name" |
| 233 | dnl See if it was already located by an earlier AC_LIB_LINKFLAGS | 243 | dnl See if it was already located by an earlier AC_LIB_LINKFLAGS |
| 234 | dnl or AC_LIB_HAVE_LINKFLAGS call. | 244 | dnl or AC_LIB_HAVE_LINKFLAGS call. |
| 235 | uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'` | 245 | uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./+-|ABCDEFGHIJKLMNOPQRSTUVWXYZ____|'` |
| 236 | eval value=\"\$HAVE_LIB$uppername\" | 246 | eval value=\"\$HAVE_LIB$uppername\" |
| 237 | if test -n "$value"; then | 247 | if test -n "$value"; then |
| 238 | if test "$value" = yes; then | 248 | if test "$value" = yes; then |
diff --git a/gl/m4/netdb_h.m4 b/gl/m4/netdb_h.m4 index 40ba8f66..c870fb61 100644 --- a/gl/m4/netdb_h.m4 +++ b/gl/m4/netdb_h.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # netdb_h.m4 serial 7 | 1 | # netdb_h.m4 serial 9 |
| 2 | dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -10,21 +10,16 @@ AC_DEFUN([gl_HEADER_NETDB], | |||
| 10 | AC_CHECK_HEADERS_ONCE([netdb.h]) | 10 | AC_CHECK_HEADERS_ONCE([netdb.h]) |
| 11 | gl_CHECK_NEXT_HEADERS([netdb.h]) | 11 | gl_CHECK_NEXT_HEADERS([netdb.h]) |
| 12 | if test $ac_cv_header_netdb_h = yes; then | 12 | if test $ac_cv_header_netdb_h = yes; then |
| 13 | AC_COMPILE_IFELSE( | ||
| 14 | [AC_LANG_PROGRAM([[ | ||
| 15 | #include <netdb.h> | ||
| 16 | struct addrinfo a; | ||
| 17 | int b = EAI_OVERFLOW; | ||
| 18 | int c = AI_NUMERICSERV; | ||
| 19 | ]])], | ||
| 20 | [NETDB_H=''], [NETDB_H='netdb.h']) | ||
| 21 | HAVE_NETDB_H=1 | 13 | HAVE_NETDB_H=1 |
| 22 | else | 14 | else |
| 23 | NETDB_H='netdb.h' | ||
| 24 | HAVE_NETDB_H=0 | 15 | HAVE_NETDB_H=0 |
| 25 | fi | 16 | fi |
| 26 | AC_SUBST([HAVE_NETDB_H]) | 17 | AC_SUBST([HAVE_NETDB_H]) |
| 27 | AC_SUBST([NETDB_H]) | 18 | |
| 19 | dnl Check for declarations of anything we want to poison if the | ||
| 20 | dnl corresponding gnulib module is not in use. | ||
| 21 | gl_WARN_ON_USE_PREPARE([[#include <netdb.h>]], | ||
| 22 | [getaddrinfo freeaddrinfo gai_strerror getnameinfo]) | ||
| 28 | ]) | 23 | ]) |
| 29 | 24 | ||
| 30 | AC_DEFUN([gl_NETDB_MODULE_INDICATOR], | 25 | AC_DEFUN([gl_NETDB_MODULE_INDICATOR], |
diff --git a/gl/m4/onceonly.m4 b/gl/m4/onceonly.m4 index 4a3cd84d..6a9c87b7 100644 --- a/gl/m4/onceonly.m4 +++ b/gl/m4/onceonly.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # onceonly.m4 serial 6 | 1 | # onceonly.m4 serial 7 |
| 2 | dnl Copyright (C) 2002-2003, 2005-2006, 2008-2010 Free Software Foundation, | 2 | dnl Copyright (C) 2002-2003, 2005-2006, 2008-2010 Free Software Foundation, |
| 3 | dnl Inc. | 3 | dnl Inc. |
| 4 | dnl This file is free software, distributed under the terms of the GNU | 4 | dnl This file is free software, distributed under the terms of the GNU |
| @@ -39,16 +39,16 @@ AC_PREREQ([2.59]) | |||
| 39 | AC_DEFUN([AC_CHECK_HEADERS_ONCE], [ | 39 | AC_DEFUN([AC_CHECK_HEADERS_ONCE], [ |
| 40 | : | 40 | : |
| 41 | m4_foreach_w([gl_HEADER_NAME], [$1], [ | 41 | m4_foreach_w([gl_HEADER_NAME], [$1], [ |
| 42 | AC_DEFUN([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, | 42 | AC_DEFUN([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME, |
| 43 | [./-], [___])), [ | 43 | [./-], [___])), [ |
| 44 | m4_divert_text([INIT_PREPARE], | 44 | m4_divert_text([INIT_PREPARE], |
| 45 | [gl_header_list="$gl_header_list gl_HEADER_NAME"]) | 45 | [gl_header_list="$gl_header_list gl_HEADER_NAME"]) |
| 46 | gl_HEADERS_EXPANSION | 46 | gl_HEADERS_EXPANSION |
| 47 | AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])), | 47 | AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])), |
| 48 | [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.]) | 48 | [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.]) |
| 49 | ]) | 49 | ]) |
| 50 | AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, | 50 | AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME, |
| 51 | [./-], [___]))) | 51 | [./-], [___]))) |
| 52 | ]) | 52 | ]) |
| 53 | ]) | 53 | ]) |
| 54 | m4_define([gl_HEADERS_EXPANSION], [ | 54 | m4_define([gl_HEADERS_EXPANSION], [ |
diff --git a/gl/m4/po.m4 b/gl/m4/po.m4 index 960efe15..47f36a41 100644 --- a/gl/m4/po.m4 +++ b/gl/m4/po.m4 | |||
| @@ -29,7 +29,7 @@ AC_DEFUN([AM_PO_SUBDIRS], | |||
| 29 | 29 | ||
| 30 | dnl Release version of the gettext macros. This is used to ensure that | 30 | dnl Release version of the gettext macros. This is used to ensure that |
| 31 | dnl the gettext macros and po/Makefile.in.in are in sync. | 31 | dnl the gettext macros and po/Makefile.in.in are in sync. |
| 32 | AC_SUBST([GETTEXT_MACRO_VERSION], [0.17]) | 32 | AC_SUBST([GETTEXT_MACRO_VERSION], [0.18]) |
| 33 | 33 | ||
| 34 | dnl Perform the following tests also if --disable-nls has been given, | 34 | dnl Perform the following tests also if --disable-nls has been given, |
| 35 | dnl because they are needed for "make dist" to work. | 35 | dnl because they are needed for "make dist" to work. |
diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4 index ebca5364..b31efe3e 100644 --- a/gl/m4/printf.m4 +++ b/gl/m4/printf.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # printf.m4 serial 33 | 1 | # printf.m4 serial 34 |
| 2 | dnl Copyright (C) 2003, 2007-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2003, 2007-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -1101,7 +1101,7 @@ dnl } | |||
| 1101 | dnl --------------------------------------------------------------------- | 1101 | dnl --------------------------------------------------------------------- |
| 1102 | dnl Result is gl_cv_func_snprintf_retval_c99. | 1102 | dnl Result is gl_cv_func_snprintf_retval_c99. |
| 1103 | 1103 | ||
| 1104 | AC_DEFUN([gl_SNPRINTF_RETVAL_C99], | 1104 | AC_DEFUN_ONCE([gl_SNPRINTF_RETVAL_C99], |
| 1105 | [ | 1105 | [ |
| 1106 | AC_REQUIRE([AC_PROG_CC]) | 1106 | AC_REQUIRE([AC_PROG_CC]) |
| 1107 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | 1107 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
diff --git a/gl/m4/sha1.m4 b/gl/m4/sha1.m4 new file mode 100644 index 00000000..0d18d857 --- /dev/null +++ b/gl/m4/sha1.m4 | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | # sha1.m4 serial 9 | ||
| 2 | dnl Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Free Software | ||
| 3 | dnl Foundation, Inc. | ||
| 4 | dnl This file is free software; the Free Software Foundation | ||
| 5 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 6 | dnl with or without modifications, as long as this notice is preserved. | ||
| 7 | |||
| 8 | AC_DEFUN([gl_SHA1], | ||
| 9 | [ | ||
| 10 | AC_LIBOBJ([sha1]) | ||
| 11 | |||
| 12 | dnl Prerequisites of lib/sha1.c. | ||
| 13 | AC_REQUIRE([gl_BIGENDIAN]) | ||
| 14 | AC_REQUIRE([AC_C_INLINE]) | ||
| 15 | : | ||
| 16 | ]) | ||
diff --git a/gl/m4/sockpfaf.m4 b/gl/m4/sockpfaf.m4 index 8a0c2360..8806705a 100644 --- a/gl/m4/sockpfaf.m4 +++ b/gl/m4/sockpfaf.m4 | |||
| @@ -47,6 +47,9 @@ AC_DEFUN([gl_SOCKET_FAMILIES], | |||
| 47 | #endif | 47 | #endif |
| 48 | #ifdef HAVE_WINSOCK2_H | 48 | #ifdef HAVE_WINSOCK2_H |
| 49 | #include <winsock2.h> | 49 | #include <winsock2.h> |
| 50 | #endif | ||
| 51 | #ifdef HAVE_WS2TCPIP_H | ||
| 52 | #include <ws2tcpip.h> | ||
| 50 | #endif]], | 53 | #endif]], |
| 51 | [[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z; | 54 | [[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z; |
| 52 | if (&x && &y && &z) return 0;]])], | 55 | if (&x && &y && &z) return 0;]])], |
diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4 index 1cc57e6e..c5e813a9 100644 --- a/gl/m4/stdint.m4 +++ b/gl/m4/stdint.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # stdint.m4 serial 34 | 1 | # stdint.m4 serial 35 |
| 2 | dnl Copyright (C) 2001-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2001-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -309,7 +309,7 @@ AC_DEFUN([gl_STDINT_BITSIZEOF], | |||
| 309 | dnl config.h.in, | 309 | dnl config.h.in, |
| 310 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | 310 | dnl - extra AC_SUBST calls, so that the right substitutions are made. |
| 311 | m4_foreach_w([gltype], [$1], | 311 | m4_foreach_w([gltype], [$1], |
| 312 | [AH_TEMPLATE([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), | 312 | [AH_TEMPLATE([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), |
| 313 | [Define to the number of bits in type ']gltype['.])]) | 313 | [Define to the number of bits in type ']gltype['.])]) |
| 314 | for gltype in $1 ; do | 314 | for gltype in $1 ; do |
| 315 | AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], | 315 | AC_CACHE_CHECK([for bit size of $gltype], [gl_cv_bitsizeof_${gltype}], |
| @@ -334,7 +334,7 @@ AC_DEFUN([gl_STDINT_BITSIZEOF], | |||
| 334 | eval BITSIZEOF_${GLTYPE}=\$result | 334 | eval BITSIZEOF_${GLTYPE}=\$result |
| 335 | done | 335 | done |
| 336 | m4_foreach_w([gltype], [$1], | 336 | m4_foreach_w([gltype], [$1], |
| 337 | [AC_SUBST([BITSIZEOF_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) | 337 | [AC_SUBST([BITSIZEOF_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) |
| 338 | ]) | 338 | ]) |
| 339 | 339 | ||
| 340 | dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) | 340 | dnl gl_CHECK_TYPES_SIGNED(TYPES, INCLUDES) |
| @@ -347,7 +347,7 @@ AC_DEFUN([gl_CHECK_TYPES_SIGNED], | |||
| 347 | dnl config.h.in, | 347 | dnl config.h.in, |
| 348 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | 348 | dnl - extra AC_SUBST calls, so that the right substitutions are made. |
| 349 | m4_foreach_w([gltype], [$1], | 349 | m4_foreach_w([gltype], [$1], |
| 350 | [AH_TEMPLATE([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), | 350 | [AH_TEMPLATE([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]), |
| 351 | [Define to 1 if ']gltype[' is a signed integer type.])]) | 351 | [Define to 1 if ']gltype[' is a signed integer type.])]) |
| 352 | for gltype in $1 ; do | 352 | for gltype in $1 ; do |
| 353 | AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], | 353 | AC_CACHE_CHECK([whether $gltype is signed], [gl_cv_type_${gltype}_signed], |
| @@ -367,7 +367,7 @@ AC_DEFUN([gl_CHECK_TYPES_SIGNED], | |||
| 367 | fi | 367 | fi |
| 368 | done | 368 | done |
| 369 | m4_foreach_w([gltype], [$1], | 369 | m4_foreach_w([gltype], [$1], |
| 370 | [AC_SUBST([HAVE_SIGNED_]translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) | 370 | [AC_SUBST([HAVE_SIGNED_]m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]))]) |
| 371 | ]) | 371 | ]) |
| 372 | 372 | ||
| 373 | dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) | 373 | dnl gl_INTEGER_TYPE_SUFFIX(TYPES, INCLUDES) |
| @@ -380,7 +380,7 @@ AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], | |||
| 380 | dnl config.h.in, | 380 | dnl config.h.in, |
| 381 | dnl - extra AC_SUBST calls, so that the right substitutions are made. | 381 | dnl - extra AC_SUBST calls, so that the right substitutions are made. |
| 382 | m4_foreach_w([gltype], [$1], | 382 | m4_foreach_w([gltype], [$1], |
| 383 | [AH_TEMPLATE(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], | 383 | [AH_TEMPLATE(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX], |
| 384 | [Define to l, ll, u, ul, ull, etc., as suitable for | 384 | [Define to l, ll, u, ul, ull, etc., as suitable for |
| 385 | constants of type ']gltype['.])]) | 385 | constants of type ']gltype['.])]) |
| 386 | for gltype in $1 ; do | 386 | for gltype in $1 ; do |
| @@ -419,7 +419,7 @@ AC_DEFUN([gl_INTEGER_TYPE_SUFFIX], | |||
| 419 | AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], [$result]) | 419 | AC_DEFINE_UNQUOTED([${GLTYPE}_SUFFIX], [$result]) |
| 420 | done | 420 | done |
| 421 | m4_foreach_w([gltype], [$1], | 421 | m4_foreach_w([gltype], [$1], |
| 422 | [AC_SUBST(translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) | 422 | [AC_SUBST(m4_translit(gltype,[abcdefghijklmnopqrstuvwxyz ],[ABCDEFGHIJKLMNOPQRSTUVWXYZ_])[_SUFFIX])]) |
| 423 | ]) | 423 | ]) |
| 424 | 424 | ||
| 425 | dnl gl_STDINT_INCLUDES | 425 | dnl gl_STDINT_INCLUDES |
diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4 index 1d1d95e5..f5650cde 100644 --- a/gl/m4/stdio_h.m4 +++ b/gl/m4/stdio_h.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # stdio_h.m4 serial 30 | 1 | # stdio_h.m4 serial 31 |
| 2 | dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -8,6 +8,7 @@ AC_DEFUN([gl_STDIO_H], | |||
| 8 | [ | 8 | [ |
| 9 | AC_REQUIRE([gl_STDIO_H_DEFAULTS]) | 9 | AC_REQUIRE([gl_STDIO_H_DEFAULTS]) |
| 10 | AC_REQUIRE([AC_C_INLINE]) | 10 | AC_REQUIRE([AC_C_INLINE]) |
| 11 | AC_REQUIRE([gl_ASM_SYMBOL_PREFIX]) | ||
| 11 | gl_CHECK_NEXT_HEADERS([stdio.h]) | 12 | gl_CHECK_NEXT_HEADERS([stdio.h]) |
| 12 | dnl No need to create extra modules for these functions. Everyone who uses | 13 | dnl No need to create extra modules for these functions. Everyone who uses |
| 13 | dnl <stdio.h> likely needs them. | 14 | dnl <stdio.h> likely needs them. |
diff --git a/gl/m4/string_h.m4 b/gl/m4/string_h.m4 index cf26123e..1977aecf 100644 --- a/gl/m4/string_h.m4 +++ b/gl/m4/string_h.m4 | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | # gives unlimited permission to copy and/or distribute it, | 5 | # gives unlimited permission to copy and/or distribute it, |
| 6 | # with or without modifications, as long as this notice is preserved. | 6 | # with or without modifications, as long as this notice is preserved. |
| 7 | 7 | ||
| 8 | # serial 16 | 8 | # serial 17 |
| 9 | 9 | ||
| 10 | # Written by Paul Eggert. | 10 | # Written by Paul Eggert. |
| 11 | 11 | ||
| @@ -105,6 +105,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], | |||
| 105 | REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) | 105 | REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) |
| 106 | REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT]) | 106 | REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT]) |
| 107 | REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP]) | 107 | REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP]) |
| 108 | REPLACE_STRNLEN=0; AC_SUBST([REPLACE_STRNLEN]) | ||
| 108 | REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) | 109 | REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) |
| 109 | REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R]) | 110 | REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R]) |
| 110 | UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R]) | 111 | UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R]) |
diff --git a/gl/m4/strnlen.m4 b/gl/m4/strnlen.m4 index cd48948f..52bb838f 100644 --- a/gl/m4/strnlen.m4 +++ b/gl/m4/strnlen.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # strnlen.m4 serial 10 | 1 | # strnlen.m4 serial 12 |
| 2 | dnl Copyright (C) 2002-2003, 2005-2007, 2009-2010 Free Software Foundation, | 2 | dnl Copyright (C) 2002-2003, 2005-2007, 2009-2010 Free Software Foundation, |
| 3 | dnl Inc. | 3 | dnl Inc. |
| 4 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
| @@ -7,23 +7,23 @@ dnl with or without modifications, as long as this notice is preserved. | |||
| 7 | 7 | ||
| 8 | AC_DEFUN([gl_FUNC_STRNLEN], | 8 | AC_DEFUN([gl_FUNC_STRNLEN], |
| 9 | [ | 9 | [ |
| 10 | AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) | ||
| 11 | |||
| 10 | dnl Persuade glibc <string.h> to declare strnlen(). | 12 | dnl Persuade glibc <string.h> to declare strnlen(). |
| 11 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) | 13 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
| 12 | 14 | ||
| 13 | AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) | ||
| 14 | AC_CHECK_DECLS_ONCE([strnlen]) | 15 | AC_CHECK_DECLS_ONCE([strnlen]) |
| 15 | if test $ac_cv_have_decl_strnlen = no; then | 16 | if test $ac_cv_have_decl_strnlen = no; then |
| 16 | HAVE_DECL_STRNLEN=0 | 17 | HAVE_DECL_STRNLEN=0 |
| 18 | else | ||
| 19 | AC_FUNC_STRNLEN | ||
| 20 | dnl Note: AC_FUNC_STRNLEN does AC_LIBOBJ([strnlen]). | ||
| 21 | if test $ac_cv_func_strnlen_working = no; then | ||
| 22 | REPLACE_STRNLEN=1 | ||
| 23 | fi | ||
| 17 | fi | 24 | fi |
| 18 | 25 | if test $HAVE_DECL_STRNLEN = 0 || test $REPLACE_STRNLEN = 1; then | |
| 19 | AC_FUNC_STRNLEN | 26 | AC_LIBOBJ([strnlen]) |
| 20 | if test $ac_cv_func_strnlen_working = no; then | ||
| 21 | # This is necessary because automake-1.6.1 doesn't understand | ||
| 22 | # that the above use of AC_FUNC_STRNLEN means we may have to use | ||
| 23 | # lib/strnlen.c. | ||
| 24 | #AC_LIBOBJ([strnlen]) | ||
| 25 | AC_DEFINE([strnlen], [rpl_strnlen], | ||
| 26 | [Define to rpl_strnlen if the replacement function should be used.]) | ||
| 27 | gl_PREREQ_STRNLEN | 27 | gl_PREREQ_STRNLEN |
| 28 | fi | 28 | fi |
| 29 | ]) | 29 | ]) |
diff --git a/gl/m4/time_h.m4 b/gl/m4/time_h.m4 index b88ba94d..a45a10a9 100644 --- a/gl/m4/time_h.m4 +++ b/gl/m4/time_h.m4 | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | # Copyright (C) 2000-2001, 2003-2007, 2009-2010 Free Software Foundation, Inc. | 3 | # Copyright (C) 2000-2001, 2003-2007, 2009-2010 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | # serial 2 | ||
| 6 | |||
| 5 | # This file is free software; the Free Software Foundation | 7 | # This file is free software; the Free Software Foundation |
| 6 | # gives unlimited permission to copy and/or distribute it, | 8 | # gives unlimited permission to copy and/or distribute it, |
| 7 | # with or without modifications, as long as this notice is preserved. | 9 | # with or without modifications, as long as this notice is preserved. |
| @@ -24,7 +26,7 @@ AC_DEFUN([gl_HEADER_TIME_H_BODY], | |||
| 24 | ]) | 26 | ]) |
| 25 | 27 | ||
| 26 | dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared | 28 | dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared |
| 27 | dnl in time.h or sys/time.h. | 29 | dnl in time.h, sys/time.h, or pthread.h. |
| 28 | 30 | ||
| 29 | AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], | 31 | AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], |
| 30 | [ | 32 | [ |
| @@ -41,6 +43,7 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], | |||
| 41 | 43 | ||
| 42 | TIME_H_DEFINES_STRUCT_TIMESPEC=0 | 44 | TIME_H_DEFINES_STRUCT_TIMESPEC=0 |
| 43 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 | 45 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 |
| 46 | PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0 | ||
| 44 | if test $gl_cv_sys_struct_timespec_in_time_h = yes; then | 47 | if test $gl_cv_sys_struct_timespec_in_time_h = yes; then |
| 45 | TIME_H_DEFINES_STRUCT_TIMESPEC=1 | 48 | TIME_H_DEFINES_STRUCT_TIMESPEC=1 |
| 46 | else | 49 | else |
| @@ -55,10 +58,24 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], | |||
| 55 | [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) | 58 | [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) |
| 56 | if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then | 59 | if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then |
| 57 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 | 60 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 |
| 61 | else | ||
| 62 | AC_CACHE_CHECK([for struct timespec in <pthread.h>], | ||
| 63 | [gl_cv_sys_struct_timespec_in_pthread_h], | ||
| 64 | [AC_COMPILE_IFELSE( | ||
| 65 | [AC_LANG_PROGRAM( | ||
| 66 | [[#include <pthread.h> | ||
| 67 | ]], | ||
| 68 | [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], | ||
| 69 | [gl_cv_sys_struct_timespec_in_pthread_h=yes], | ||
| 70 | [gl_cv_sys_struct_timespec_in_pthread_h=no])]) | ||
| 71 | if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then | ||
| 72 | PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1 | ||
| 73 | fi | ||
| 58 | fi | 74 | fi |
| 59 | fi | 75 | fi |
| 60 | AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) | 76 | AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) |
| 61 | AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) | 77 | AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) |
| 78 | AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC]) | ||
| 62 | ]) | 79 | ]) |
| 63 | 80 | ||
| 64 | AC_DEFUN([gl_TIME_MODULE_INDICATOR], | 81 | AC_DEFUN([gl_TIME_MODULE_INDICATOR], |
diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4 index 8c2eec64..48d06c74 100644 --- a/gl/m4/unistd_h.m4 +++ b/gl/m4/unistd_h.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # unistd_h.m4 serial 45 | 1 | # unistd_h.m4 serial 46 |
| 2 | dnl Copyright (C) 2006-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2006-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -38,8 +38,9 @@ AC_DEFUN([gl_UNISTD_H], | |||
| 38 | ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat | 38 | ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat |
| 39 | fsync ftruncate getcwd getdomainname getdtablesize getgroups | 39 | fsync ftruncate getcwd getdomainname getdtablesize getgroups |
| 40 | gethostname getlogin getlogin_r getpagesize getusershell setusershell | 40 | gethostname getlogin getlogin_r getpagesize getusershell setusershell |
| 41 | endusershell lchown link linkat lseek pipe2 pread readlink readlinkat | 41 | endusershell lchown link linkat lseek pipe2 pread pwrite readlink |
| 42 | rmdir sleep symlink symlinkat ttyname_r unlink unlinkat usleep]) | 42 | readlinkat rmdir sleep symlink symlinkat ttyname_r unlink unlinkat |
| 43 | usleep]) | ||
| 43 | ]) | 44 | ]) |
| 44 | 45 | ||
| 45 | AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], | 46 | AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], |
| @@ -79,6 +80,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], | |||
| 79 | GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK]) | 80 | GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK]) |
| 80 | GNULIB_PIPE2=0; AC_SUBST([GNULIB_PIPE2]) | 81 | GNULIB_PIPE2=0; AC_SUBST([GNULIB_PIPE2]) |
| 81 | GNULIB_PREAD=0; AC_SUBST([GNULIB_PREAD]) | 82 | GNULIB_PREAD=0; AC_SUBST([GNULIB_PREAD]) |
| 83 | GNULIB_PWRITE=0; AC_SUBST([GNULIB_PWRITE]) | ||
| 82 | GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK]) | 84 | GNULIB_READLINK=0; AC_SUBST([GNULIB_READLINK]) |
| 83 | GNULIB_READLINKAT=0; AC_SUBST([GNULIB_READLINKAT]) | 85 | GNULIB_READLINKAT=0; AC_SUBST([GNULIB_READLINKAT]) |
| 84 | GNULIB_RMDIR=0; AC_SUBST([GNULIB_RMDIR]) | 86 | GNULIB_RMDIR=0; AC_SUBST([GNULIB_RMDIR]) |
| @@ -113,6 +115,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], | |||
| 113 | HAVE_LINKAT=1; AC_SUBST([HAVE_LINKAT]) | 115 | HAVE_LINKAT=1; AC_SUBST([HAVE_LINKAT]) |
| 114 | HAVE_PIPE2=1; AC_SUBST([HAVE_PIPE2]) | 116 | HAVE_PIPE2=1; AC_SUBST([HAVE_PIPE2]) |
| 115 | HAVE_PREAD=1; AC_SUBST([HAVE_PREAD]) | 117 | HAVE_PREAD=1; AC_SUBST([HAVE_PREAD]) |
| 118 | HAVE_PWRITE=1; AC_SUBST([HAVE_PWRITE]) | ||
| 116 | HAVE_READLINK=1; AC_SUBST([HAVE_READLINK]) | 119 | HAVE_READLINK=1; AC_SUBST([HAVE_READLINK]) |
| 117 | HAVE_READLINKAT=1; AC_SUBST([HAVE_READLINKAT]) | 120 | HAVE_READLINKAT=1; AC_SUBST([HAVE_READLINKAT]) |
| 118 | HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) | 121 | HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) |
| @@ -140,10 +143,12 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], | |||
| 140 | REPLACE_LINKAT=0; AC_SUBST([REPLACE_LINKAT]) | 143 | REPLACE_LINKAT=0; AC_SUBST([REPLACE_LINKAT]) |
| 141 | REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK]) | 144 | REPLACE_LSEEK=0; AC_SUBST([REPLACE_LSEEK]) |
| 142 | REPLACE_PREAD=0; AC_SUBST([REPLACE_PREAD]) | 145 | REPLACE_PREAD=0; AC_SUBST([REPLACE_PREAD]) |
| 146 | REPLACE_PWRITE=0; AC_SUBST([REPLACE_PWRITE]) | ||
| 143 | REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK]) | 147 | REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK]) |
| 144 | REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR]) | 148 | REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR]) |
| 145 | REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP]) | 149 | REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP]) |
| 146 | REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK]) | 150 | REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK]) |
| 151 | REPLACE_TTYNAME_R=0; AC_SUBST([REPLACE_TTYNAME_R]) | ||
| 147 | REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK]) | 152 | REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK]) |
| 148 | REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT]) | 153 | REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT]) |
| 149 | REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP]) | 154 | REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP]) |
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4 index 50a20cca..ebe3c52c 100644 --- a/gl/m4/vasnprintf.m4 +++ b/gl/m4/vasnprintf.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # vasnprintf.m4 serial 29 | 1 | # vasnprintf.m4 serial 31 |
| 2 | dnl Copyright (C) 2002-2004, 2006-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2002-2004, 2006-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -54,6 +54,7 @@ AC_DEFUN([gl_PREREQ_PRINTF_PARSE], | |||
| 54 | # Prerequisites of lib/vasnprintf.c. | 54 | # Prerequisites of lib/vasnprintf.c. |
| 55 | AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], | 55 | AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], |
| 56 | [ | 56 | [ |
| 57 | AC_REQUIRE([AC_C_INLINE]) | ||
| 57 | AC_REQUIRE([AC_FUNC_ALLOCA]) | 58 | AC_REQUIRE([AC_FUNC_ALLOCA]) |
| 58 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | 59 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) |
| 59 | AC_REQUIRE([gt_TYPE_WCHAR_T]) | 60 | AC_REQUIRE([gt_TYPE_WCHAR_T]) |
| @@ -62,6 +63,17 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF], | |||
| 62 | dnl Use the _snprintf function only if it is declared (because on NetBSD it | 63 | dnl Use the _snprintf function only if it is declared (because on NetBSD it |
| 63 | dnl is defined as a weak alias of snprintf; we prefer to use the latter). | 64 | dnl is defined as a weak alias of snprintf; we prefer to use the latter). |
| 64 | AC_CHECK_DECLS([_snprintf], , , [#include <stdio.h>]) | 65 | AC_CHECK_DECLS([_snprintf], , , [#include <stdio.h>]) |
| 66 | dnl We can avoid a lot of code by assuming that snprintf's return value | ||
| 67 | dnl conforms to ISO C99. So check that. | ||
| 68 | AC_REQUIRE([gl_SNPRINTF_RETVAL_C99]) | ||
| 69 | case "$gl_cv_func_snprintf_retval_c99" in | ||
| 70 | *yes) | ||
| 71 | AC_DEFINE([HAVE_SNPRINTF_RETVAL_C99], [1], | ||
| 72 | [Define if the return value of the snprintf function is the number of | ||
| 73 | of bytes (excluding the terminating NUL) that would have been produced | ||
| 74 | if the buffer had been large enough.]) | ||
| 75 | ;; | ||
| 76 | esac | ||
| 65 | ]) | 77 | ]) |
| 66 | 78 | ||
| 67 | # Extra prerequisites of lib/vasnprintf.c for supporting 'long double' | 79 | # Extra prerequisites of lib/vasnprintf.c for supporting 'long double' |
diff --git a/gl/m4/visibility.m4 b/gl/m4/visibility.m4 index 6d3f9c9d..077c4765 100644 --- a/gl/m4/visibility.m4 +++ b/gl/m4/visibility.m4 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # visibility.m4 serial 2 (gettext-0.18) | 1 | # visibility.m4 serial 3 (gettext-0.18) |
| 2 | dnl Copyright (C) 2005, 2008-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2005, 2008-2010 Free Software Foundation, Inc. |
| 3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
| 4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
| @@ -26,15 +26,37 @@ AC_DEFUN([gl_VISIBILITY], | |||
| 26 | CFLAG_VISIBILITY= | 26 | CFLAG_VISIBILITY= |
| 27 | HAVE_VISIBILITY=0 | 27 | HAVE_VISIBILITY=0 |
| 28 | if test -n "$GCC"; then | 28 | if test -n "$GCC"; then |
| 29 | dnl First, check whether -Werror can be added to the command line, or | ||
| 30 | dnl whether it leads to an error because of some other option that the | ||
| 31 | dnl user has put into $CC $CFLAGS $CPPFLAGS. | ||
| 32 | AC_MSG_CHECKING([whether the -Werror option is usable]) | ||
| 33 | AC_CACHE_VAL([gl_cv_cc_vis_werror], [ | ||
| 34 | gl_save_CFLAGS="$CFLAGS" | ||
| 35 | CFLAGS="$CFLAGS -Werror" | ||
| 36 | AC_TRY_COMPILE([], [], | ||
| 37 | [gl_cv_cc_vis_werror=yes], | ||
| 38 | [gl_cv_cc_vis_werror=no]) | ||
| 39 | CFLAGS="$gl_save_CFLAGS"]) | ||
| 40 | AC_MSG_RESULT([$gl_cv_cc_vis_werror]) | ||
| 41 | dnl Now check whether visibility declarations are supported. | ||
| 29 | AC_MSG_CHECKING([for simple visibility declarations]) | 42 | AC_MSG_CHECKING([for simple visibility declarations]) |
| 30 | AC_CACHE_VAL([gl_cv_cc_visibility], [ | 43 | AC_CACHE_VAL([gl_cv_cc_visibility], [ |
| 31 | gl_save_CFLAGS="$CFLAGS" | 44 | gl_save_CFLAGS="$CFLAGS" |
| 32 | CFLAGS="$CFLAGS -fvisibility=hidden" | 45 | CFLAGS="$CFLAGS -fvisibility=hidden" |
| 46 | dnl We use the option -Werror and a function dummyfunc, because on some | ||
| 47 | dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning | ||
| 48 | dnl "visibility attribute not supported in this configuration; ignored" | ||
| 49 | dnl at the first function definition in every compilation unit, and we | ||
| 50 | dnl don't want to use the option in this case. | ||
| 51 | if test $gl_cv_cc_vis_werror = yes; then | ||
| 52 | CFLAGS="$CFLAGS -Werror" | ||
| 53 | fi | ||
| 33 | AC_TRY_COMPILE( | 54 | AC_TRY_COMPILE( |
| 34 | [extern __attribute__((__visibility__("hidden"))) int hiddenvar; | 55 | [extern __attribute__((__visibility__("hidden"))) int hiddenvar; |
| 35 | extern __attribute__((__visibility__("default"))) int exportedvar; | 56 | extern __attribute__((__visibility__("default"))) int exportedvar; |
| 36 | extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); | 57 | extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); |
| 37 | extern __attribute__((__visibility__("default"))) int exportedfunc (void);], | 58 | extern __attribute__((__visibility__("default"))) int exportedfunc (void); |
| 59 | void dummyfunc (void) {}], | ||
| 38 | [], | 60 | [], |
| 39 | [gl_cv_cc_visibility=yes], | 61 | [gl_cv_cc_visibility=yes], |
| 40 | [gl_cv_cc_visibility=no]) | 62 | [gl_cv_cc_visibility=no]) |
diff --git a/gl/netdb.in.h b/gl/netdb.in.h index 73db46a5..f800cac8 100644 --- a/gl/netdb.in.h +++ b/gl/netdb.in.h | |||
| @@ -41,6 +41,8 @@ | |||
| 41 | 41 | ||
| 42 | /* The definition of _GL_ARG_NONNULL is copied here. */ | 42 | /* The definition of _GL_ARG_NONNULL is copied here. */ |
| 43 | 43 | ||
| 44 | /* The definition of _GL_WARN_ON_USE is copied here. */ | ||
| 45 | |||
| 44 | /* Declarations for a platform that lacks <netdb.h>, or where it is | 46 | /* Declarations for a platform that lacks <netdb.h>, or where it is |
| 45 | incomplete. */ | 47 | incomplete. */ |
| 46 | 48 | ||
| @@ -186,7 +188,33 @@ extern int getnameinfo (const struct sockaddr *restrict sa, socklen_t salen, | |||
| 186 | # define NI_NUMERICSERV 2 | 188 | # define NI_NUMERICSERV 2 |
| 187 | # endif | 189 | # endif |
| 188 | 190 | ||
| 189 | #endif /* @GNULIB_GETADDRINFO@ */ | 191 | #elif defined GNULIB_POSIXCHECK |
| 192 | |||
| 193 | # undef getaddrinfo | ||
| 194 | # if HAVE_RAW_DECL_GETADDRINFO | ||
| 195 | _GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - " | ||
| 196 | "use gnulib module getaddrinfo for portability"); | ||
| 197 | # endif | ||
| 198 | |||
| 199 | # undef freeaddrinfo | ||
| 200 | # if HAVE_RAW_DECL_FREEADDRINFO | ||
| 201 | _GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - " | ||
| 202 | "use gnulib module getaddrinfo for portability"); | ||
| 203 | # endif | ||
| 204 | |||
| 205 | # undef gai_strerror | ||
| 206 | # if HAVE_RAW_DECL_GAI_STRERROR | ||
| 207 | _GL_WARN_ON_USE (gai_strerror, "gai_strerror is unportable - " | ||
| 208 | "use gnulib module getaddrinfo for portability"); | ||
| 209 | # endif | ||
| 210 | |||
| 211 | # undef getnameinfo | ||
| 212 | # if HAVE_RAW_DECL_GETNAMEINFO | ||
| 213 | _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - " | ||
| 214 | "use gnulib module getaddrinfo for portability"); | ||
| 215 | # endif | ||
| 216 | |||
| 217 | #endif | ||
| 190 | 218 | ||
| 191 | #endif /* _GL_NETDB_H */ | 219 | #endif /* _GL_NETDB_H */ |
| 192 | #endif /* _GL_NETDB_H */ | 220 | #endif /* _GL_NETDB_H */ |
diff --git a/gl/regex_internal.c b/gl/regex_internal.c index 17eafaa9..98b8d5d2 100644 --- a/gl/regex_internal.c +++ b/gl/regex_internal.c | |||
| @@ -733,15 +733,17 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) | |||
| 733 | mbstate_t cur_state; | 733 | mbstate_t cur_state; |
| 734 | wchar_t wc2; | 734 | wchar_t wc2; |
| 735 | Idx mlen = raw + pstr->len - p; | 735 | Idx mlen = raw + pstr->len - p; |
| 736 | unsigned char buf[6]; | ||
| 737 | size_t mbclen; | 736 | size_t mbclen; |
| 738 | 737 | ||
| 738 | #if 0 /* dead code: buf is set but never used */ | ||
| 739 | unsigned char buf[6]; | ||
| 739 | if (BE (pstr->trans != NULL, 0)) | 740 | if (BE (pstr->trans != NULL, 0)) |
| 740 | { | 741 | { |
| 741 | int i = mlen < 6 ? mlen : 6; | 742 | int i = mlen < 6 ? mlen : 6; |
| 742 | while (--i >= 0) | 743 | while (--i >= 0) |
| 743 | buf[i] = pstr->trans[p[i]]; | 744 | buf[i] = pstr->trans[p[i]]; |
| 744 | } | 745 | } |
| 746 | #endif | ||
| 745 | /* XXX Don't use mbrtowc, we know which conversion | 747 | /* XXX Don't use mbrtowc, we know which conversion |
| 746 | to use (UTF-8 -> UCS4). */ | 748 | to use (UTF-8 -> UCS4). */ |
| 747 | memset (&cur_state, 0, sizeof (cur_state)); | 749 | memset (&cur_state, 0, sizeof (cur_state)); |
diff --git a/gl/regex_internal.h b/gl/regex_internal.h index 2cb8c4d0..5aa5aa28 100644 --- a/gl/regex_internal.h +++ b/gl/regex_internal.h | |||
| @@ -467,6 +467,8 @@ static unsigned int re_string_context_at (const re_string_t *input, Idx idx, | |||
| 467 | # else | 467 | # else |
| 468 | /* alloca is implemented with malloc, so just use malloc. */ | 468 | /* alloca is implemented with malloc, so just use malloc. */ |
| 469 | # define __libc_use_alloca(n) 0 | 469 | # define __libc_use_alloca(n) 0 |
| 470 | # undef alloca | ||
| 471 | # define alloca(n) malloc (n) | ||
| 470 | # endif | 472 | # endif |
| 471 | #endif | 473 | #endif |
| 472 | 474 | ||
diff --git a/gl/sha1.c b/gl/sha1.c new file mode 100644 index 00000000..7251ca80 --- /dev/null +++ b/gl/sha1.c | |||
| @@ -0,0 +1,428 @@ | |||
| 1 | /* sha1.c - Functions to compute SHA1 message digest of files or | ||
| 2 | memory blocks according to the NIST specification FIPS-180-1. | ||
| 3 | |||
| 4 | Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Free | ||
| 5 | Software Foundation, Inc. | ||
| 6 | |||
| 7 | This program is free software; you can redistribute it and/or modify it | ||
| 8 | under the terms of the GNU General Public License as published by the | ||
| 9 | Free Software Foundation; either version 3, or (at your option) any | ||
| 10 | later version. | ||
| 11 | |||
| 12 | This program is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License | ||
| 18 | along with this program; if not, write to the Free Software Foundation, | ||
| 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 20 | |||
| 21 | /* Written by Scott G. Miller | ||
| 22 | Credits: | ||
| 23 | Robert Klep <robert@ilse.nl> -- Expansion function fix | ||
| 24 | */ | ||
| 25 | |||
| 26 | #include <config.h> | ||
| 27 | |||
| 28 | #include "sha1.h" | ||
| 29 | |||
| 30 | #include <stddef.h> | ||
| 31 | #include <stdlib.h> | ||
| 32 | #include <string.h> | ||
| 33 | |||
| 34 | #if USE_UNLOCKED_IO | ||
| 35 | # include "unlocked-io.h" | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifdef WORDS_BIGENDIAN | ||
| 39 | # define SWAP(n) (n) | ||
| 40 | #else | ||
| 41 | # define SWAP(n) \ | ||
| 42 | (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #define BLOCKSIZE 32768 | ||
| 46 | #if BLOCKSIZE % 64 != 0 | ||
| 47 | # error "invalid BLOCKSIZE" | ||
| 48 | #endif | ||
| 49 | |||
| 50 | /* This array contains the bytes used to pad the buffer to the next | ||
| 51 | 64-byte boundary. (RFC 1321, 3.1: Step 1) */ | ||
| 52 | static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; | ||
| 53 | |||
| 54 | |||
| 55 | /* Take a pointer to a 160 bit block of data (five 32 bit ints) and | ||
| 56 | initialize it to the start constants of the SHA1 algorithm. This | ||
| 57 | must be called before using hash in the call to sha1_hash. */ | ||
| 58 | void | ||
| 59 | sha1_init_ctx (struct sha1_ctx *ctx) | ||
| 60 | { | ||
| 61 | ctx->A = 0x67452301; | ||
| 62 | ctx->B = 0xefcdab89; | ||
| 63 | ctx->C = 0x98badcfe; | ||
| 64 | ctx->D = 0x10325476; | ||
| 65 | ctx->E = 0xc3d2e1f0; | ||
| 66 | |||
| 67 | ctx->total[0] = ctx->total[1] = 0; | ||
| 68 | ctx->buflen = 0; | ||
| 69 | } | ||
| 70 | |||
| 71 | /* Copy the 4 byte value from v into the memory location pointed to by *cp, | ||
| 72 | If your architecture allows unaligned access this is equivalent to | ||
| 73 | * (uint32_t *) cp = v */ | ||
| 74 | static inline void | ||
| 75 | set_uint32 (char *cp, uint32_t v) | ||
| 76 | { | ||
| 77 | memcpy (cp, &v, sizeof v); | ||
| 78 | } | ||
| 79 | |||
| 80 | /* Put result from CTX in first 20 bytes following RESBUF. The result | ||
| 81 | must be in little endian byte order. */ | ||
| 82 | void * | ||
| 83 | sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf) | ||
| 84 | { | ||
| 85 | char *r = resbuf; | ||
| 86 | set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A)); | ||
| 87 | set_uint32 (r + 1 * sizeof ctx->B, SWAP (ctx->B)); | ||
| 88 | set_uint32 (r + 2 * sizeof ctx->C, SWAP (ctx->C)); | ||
| 89 | set_uint32 (r + 3 * sizeof ctx->D, SWAP (ctx->D)); | ||
| 90 | set_uint32 (r + 4 * sizeof ctx->E, SWAP (ctx->E)); | ||
| 91 | |||
| 92 | return resbuf; | ||
| 93 | } | ||
| 94 | |||
| 95 | /* Process the remaining bytes in the internal buffer and the usual | ||
| 96 | prolog according to the standard and write the result to RESBUF. */ | ||
| 97 | void * | ||
| 98 | sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf) | ||
| 99 | { | ||
| 100 | /* Take yet unprocessed bytes into account. */ | ||
| 101 | uint32_t bytes = ctx->buflen; | ||
| 102 | size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4; | ||
| 103 | |||
| 104 | /* Now count remaining bytes. */ | ||
| 105 | ctx->total[0] += bytes; | ||
| 106 | if (ctx->total[0] < bytes) | ||
| 107 | ++ctx->total[1]; | ||
| 108 | |||
| 109 | /* Put the 64-bit file length in *bits* at the end of the buffer. */ | ||
| 110 | ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29)); | ||
| 111 | ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3); | ||
| 112 | |||
| 113 | memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes); | ||
| 114 | |||
| 115 | /* Process last bytes. */ | ||
| 116 | sha1_process_block (ctx->buffer, size * 4, ctx); | ||
| 117 | |||
| 118 | return sha1_read_ctx (ctx, resbuf); | ||
| 119 | } | ||
| 120 | |||
| 121 | /* Compute SHA1 message digest for bytes read from STREAM. The | ||
| 122 | resulting message digest number will be written into the 16 bytes | ||
| 123 | beginning at RESBLOCK. */ | ||
| 124 | int | ||
| 125 | sha1_stream (FILE *stream, void *resblock) | ||
| 126 | { | ||
| 127 | struct sha1_ctx ctx; | ||
| 128 | size_t sum; | ||
| 129 | |||
| 130 | char *buffer = malloc (BLOCKSIZE + 72); | ||
| 131 | if (!buffer) | ||
| 132 | return 1; | ||
| 133 | |||
| 134 | /* Initialize the computation context. */ | ||
| 135 | sha1_init_ctx (&ctx); | ||
| 136 | |||
| 137 | /* Iterate over full file contents. */ | ||
| 138 | while (1) | ||
| 139 | { | ||
| 140 | /* We read the file in blocks of BLOCKSIZE bytes. One call of the | ||
| 141 | computation function processes the whole buffer so that with the | ||
| 142 | next round of the loop another block can be read. */ | ||
| 143 | size_t n; | ||
| 144 | sum = 0; | ||
| 145 | |||
| 146 | /* Read block. Take care for partial reads. */ | ||
| 147 | while (1) | ||
| 148 | { | ||
| 149 | n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); | ||
| 150 | |||
| 151 | sum += n; | ||
| 152 | |||
| 153 | if (sum == BLOCKSIZE) | ||
| 154 | break; | ||
| 155 | |||
| 156 | if (n == 0) | ||
| 157 | { | ||
| 158 | /* Check for the error flag IFF N == 0, so that we don't | ||
| 159 | exit the loop after a partial read due to e.g., EAGAIN | ||
| 160 | or EWOULDBLOCK. */ | ||
| 161 | if (ferror (stream)) | ||
| 162 | { | ||
| 163 | free (buffer); | ||
| 164 | return 1; | ||
| 165 | } | ||
| 166 | goto process_partial_block; | ||
| 167 | } | ||
| 168 | |||
| 169 | /* We've read at least one byte, so ignore errors. But always | ||
| 170 | check for EOF, since feof may be true even though N > 0. | ||
| 171 | Otherwise, we could end up calling fread after EOF. */ | ||
| 172 | if (feof (stream)) | ||
| 173 | goto process_partial_block; | ||
| 174 | } | ||
| 175 | |||
| 176 | /* Process buffer with BLOCKSIZE bytes. Note that | ||
| 177 | BLOCKSIZE % 64 == 0 | ||
| 178 | */ | ||
| 179 | sha1_process_block (buffer, BLOCKSIZE, &ctx); | ||
| 180 | } | ||
| 181 | |||
| 182 | process_partial_block:; | ||
| 183 | |||
| 184 | /* Process any remaining bytes. */ | ||
| 185 | if (sum > 0) | ||
| 186 | sha1_process_bytes (buffer, sum, &ctx); | ||
| 187 | |||
| 188 | /* Construct result in desired memory. */ | ||
| 189 | sha1_finish_ctx (&ctx, resblock); | ||
| 190 | free (buffer); | ||
| 191 | return 0; | ||
| 192 | } | ||
| 193 | |||
| 194 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The | ||
| 195 | result is always in little endian byte order, so that a byte-wise | ||
| 196 | output yields to the wanted ASCII representation of the message | ||
| 197 | digest. */ | ||
| 198 | void * | ||
| 199 | sha1_buffer (const char *buffer, size_t len, void *resblock) | ||
| 200 | { | ||
| 201 | struct sha1_ctx ctx; | ||
| 202 | |||
| 203 | /* Initialize the computation context. */ | ||
| 204 | sha1_init_ctx (&ctx); | ||
| 205 | |||
| 206 | /* Process whole buffer but last len % 64 bytes. */ | ||
| 207 | sha1_process_bytes (buffer, len, &ctx); | ||
| 208 | |||
| 209 | /* Put result in desired memory area. */ | ||
| 210 | return sha1_finish_ctx (&ctx, resblock); | ||
| 211 | } | ||
| 212 | |||
| 213 | void | ||
| 214 | sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx) | ||
| 215 | { | ||
| 216 | /* When we already have some bits in our internal buffer concatenate | ||
| 217 | both inputs first. */ | ||
| 218 | if (ctx->buflen != 0) | ||
| 219 | { | ||
| 220 | size_t left_over = ctx->buflen; | ||
| 221 | size_t add = 128 - left_over > len ? len : 128 - left_over; | ||
| 222 | |||
| 223 | memcpy (&((char *) ctx->buffer)[left_over], buffer, add); | ||
| 224 | ctx->buflen += add; | ||
| 225 | |||
| 226 | if (ctx->buflen > 64) | ||
| 227 | { | ||
| 228 | sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx); | ||
| 229 | |||
| 230 | ctx->buflen &= 63; | ||
| 231 | /* The regions in the following copy operation cannot overlap. */ | ||
| 232 | memcpy (ctx->buffer, | ||
| 233 | &((char *) ctx->buffer)[(left_over + add) & ~63], | ||
| 234 | ctx->buflen); | ||
| 235 | } | ||
| 236 | |||
| 237 | buffer = (const char *) buffer + add; | ||
| 238 | len -= add; | ||
| 239 | } | ||
| 240 | |||
| 241 | /* Process available complete blocks. */ | ||
| 242 | if (len >= 64) | ||
| 243 | { | ||
| 244 | #if !_STRING_ARCH_unaligned | ||
| 245 | # define alignof(type) offsetof (struct { char c; type x; }, x) | ||
| 246 | # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0) | ||
| 247 | if (UNALIGNED_P (buffer)) | ||
| 248 | while (len > 64) | ||
| 249 | { | ||
| 250 | sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); | ||
| 251 | buffer = (const char *) buffer + 64; | ||
| 252 | len -= 64; | ||
| 253 | } | ||
| 254 | else | ||
| 255 | #endif | ||
| 256 | { | ||
| 257 | sha1_process_block (buffer, len & ~63, ctx); | ||
| 258 | buffer = (const char *) buffer + (len & ~63); | ||
| 259 | len &= 63; | ||
| 260 | } | ||
| 261 | } | ||
| 262 | |||
| 263 | /* Move remaining bytes in internal buffer. */ | ||
| 264 | if (len > 0) | ||
| 265 | { | ||
| 266 | size_t left_over = ctx->buflen; | ||
| 267 | |||
| 268 | memcpy (&((char *) ctx->buffer)[left_over], buffer, len); | ||
| 269 | left_over += len; | ||
| 270 | if (left_over >= 64) | ||
| 271 | { | ||
| 272 | sha1_process_block (ctx->buffer, 64, ctx); | ||
| 273 | left_over -= 64; | ||
| 274 | memcpy (ctx->buffer, &ctx->buffer[16], left_over); | ||
| 275 | } | ||
| 276 | ctx->buflen = left_over; | ||
| 277 | } | ||
| 278 | } | ||
| 279 | |||
| 280 | /* --- Code below is the primary difference between md5.c and sha1.c --- */ | ||
| 281 | |||
| 282 | /* SHA1 round constants */ | ||
| 283 | #define K1 0x5a827999 | ||
| 284 | #define K2 0x6ed9eba1 | ||
| 285 | #define K3 0x8f1bbcdc | ||
| 286 | #define K4 0xca62c1d6 | ||
| 287 | |||
| 288 | /* Round functions. Note that F2 is the same as F4. */ | ||
| 289 | #define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) ) | ||
| 290 | #define F2(B,C,D) (B ^ C ^ D) | ||
| 291 | #define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) ) | ||
| 292 | #define F4(B,C,D) (B ^ C ^ D) | ||
| 293 | |||
| 294 | /* Process LEN bytes of BUFFER, accumulating context into CTX. | ||
| 295 | It is assumed that LEN % 64 == 0. | ||
| 296 | Most of this code comes from GnuPG's cipher/sha1.c. */ | ||
| 297 | |||
| 298 | void | ||
| 299 | sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx) | ||
| 300 | { | ||
| 301 | const uint32_t *words = buffer; | ||
| 302 | size_t nwords = len / sizeof (uint32_t); | ||
| 303 | const uint32_t *endp = words + nwords; | ||
| 304 | uint32_t x[16]; | ||
| 305 | uint32_t a = ctx->A; | ||
| 306 | uint32_t b = ctx->B; | ||
| 307 | uint32_t c = ctx->C; | ||
| 308 | uint32_t d = ctx->D; | ||
| 309 | uint32_t e = ctx->E; | ||
| 310 | |||
| 311 | /* First increment the byte count. RFC 1321 specifies the possible | ||
| 312 | length of the file up to 2^64 bits. Here we only compute the | ||
| 313 | number of bytes. Do a double word increment. */ | ||
| 314 | ctx->total[0] += len; | ||
| 315 | if (ctx->total[0] < len) | ||
| 316 | ++ctx->total[1]; | ||
| 317 | |||
| 318 | #define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n)))) | ||
| 319 | |||
| 320 | #define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \ | ||
| 321 | ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \ | ||
| 322 | , (x[I&0x0f] = rol(tm, 1)) ) | ||
| 323 | |||
| 324 | #define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \ | ||
| 325 | + F( B, C, D ) \ | ||
| 326 | + K \ | ||
| 327 | + M; \ | ||
| 328 | B = rol( B, 30 ); \ | ||
| 329 | } while(0) | ||
| 330 | |||
| 331 | while (words < endp) | ||
| 332 | { | ||
| 333 | uint32_t tm; | ||
| 334 | int t; | ||
| 335 | for (t = 0; t < 16; t++) | ||
| 336 | { | ||
| 337 | x[t] = SWAP (*words); | ||
| 338 | words++; | ||
| 339 | } | ||
| 340 | |||
| 341 | R( a, b, c, d, e, F1, K1, x[ 0] ); | ||
| 342 | R( e, a, b, c, d, F1, K1, x[ 1] ); | ||
| 343 | R( d, e, a, b, c, F1, K1, x[ 2] ); | ||
| 344 | R( c, d, e, a, b, F1, K1, x[ 3] ); | ||
| 345 | R( b, c, d, e, a, F1, K1, x[ 4] ); | ||
| 346 | R( a, b, c, d, e, F1, K1, x[ 5] ); | ||
| 347 | R( e, a, b, c, d, F1, K1, x[ 6] ); | ||
| 348 | R( d, e, a, b, c, F1, K1, x[ 7] ); | ||
| 349 | R( c, d, e, a, b, F1, K1, x[ 8] ); | ||
| 350 | R( b, c, d, e, a, F1, K1, x[ 9] ); | ||
| 351 | R( a, b, c, d, e, F1, K1, x[10] ); | ||
| 352 | R( e, a, b, c, d, F1, K1, x[11] ); | ||
| 353 | R( d, e, a, b, c, F1, K1, x[12] ); | ||
| 354 | R( c, d, e, a, b, F1, K1, x[13] ); | ||
| 355 | R( b, c, d, e, a, F1, K1, x[14] ); | ||
| 356 | R( a, b, c, d, e, F1, K1, x[15] ); | ||
| 357 | R( e, a, b, c, d, F1, K1, M(16) ); | ||
| 358 | R( d, e, a, b, c, F1, K1, M(17) ); | ||
| 359 | R( c, d, e, a, b, F1, K1, M(18) ); | ||
| 360 | R( b, c, d, e, a, F1, K1, M(19) ); | ||
| 361 | R( a, b, c, d, e, F2, K2, M(20) ); | ||
| 362 | R( e, a, b, c, d, F2, K2, M(21) ); | ||
| 363 | R( d, e, a, b, c, F2, K2, M(22) ); | ||
| 364 | R( c, d, e, a, b, F2, K2, M(23) ); | ||
| 365 | R( b, c, d, e, a, F2, K2, M(24) ); | ||
| 366 | R( a, b, c, d, e, F2, K2, M(25) ); | ||
| 367 | R( e, a, b, c, d, F2, K2, M(26) ); | ||
| 368 | R( d, e, a, b, c, F2, K2, M(27) ); | ||
| 369 | R( c, d, e, a, b, F2, K2, M(28) ); | ||
| 370 | R( b, c, d, e, a, F2, K2, M(29) ); | ||
| 371 | R( a, b, c, d, e, F2, K2, M(30) ); | ||
| 372 | R( e, a, b, c, d, F2, K2, M(31) ); | ||
| 373 | R( d, e, a, b, c, F2, K2, M(32) ); | ||
| 374 | R( c, d, e, a, b, F2, K2, M(33) ); | ||
| 375 | R( b, c, d, e, a, F2, K2, M(34) ); | ||
| 376 | R( a, b, c, d, e, F2, K2, M(35) ); | ||
| 377 | R( e, a, b, c, d, F2, K2, M(36) ); | ||
| 378 | R( d, e, a, b, c, F2, K2, M(37) ); | ||
| 379 | R( c, d, e, a, b, F2, K2, M(38) ); | ||
| 380 | R( b, c, d, e, a, F2, K2, M(39) ); | ||
| 381 | R( a, b, c, d, e, F3, K3, M(40) ); | ||
| 382 | R( e, a, b, c, d, F3, K3, M(41) ); | ||
| 383 | R( d, e, a, b, c, F3, K3, M(42) ); | ||
| 384 | R( c, d, e, a, b, F3, K3, M(43) ); | ||
| 385 | R( b, c, d, e, a, F3, K3, M(44) ); | ||
| 386 | R( a, b, c, d, e, F3, K3, M(45) ); | ||
| 387 | R( e, a, b, c, d, F3, K3, M(46) ); | ||
| 388 | R( d, e, a, b, c, F3, K3, M(47) ); | ||
| 389 | R( c, d, e, a, b, F3, K3, M(48) ); | ||
| 390 | R( b, c, d, e, a, F3, K3, M(49) ); | ||
| 391 | R( a, b, c, d, e, F3, K3, M(50) ); | ||
| 392 | R( e, a, b, c, d, F3, K3, M(51) ); | ||
| 393 | R( d, e, a, b, c, F3, K3, M(52) ); | ||
| 394 | R( c, d, e, a, b, F3, K3, M(53) ); | ||
| 395 | R( b, c, d, e, a, F3, K3, M(54) ); | ||
| 396 | R( a, b, c, d, e, F3, K3, M(55) ); | ||
| 397 | R( e, a, b, c, d, F3, K3, M(56) ); | ||
| 398 | R( d, e, a, b, c, F3, K3, M(57) ); | ||
| 399 | R( c, d, e, a, b, F3, K3, M(58) ); | ||
| 400 | R( b, c, d, e, a, F3, K3, M(59) ); | ||
| 401 | R( a, b, c, d, e, F4, K4, M(60) ); | ||
| 402 | R( e, a, b, c, d, F4, K4, M(61) ); | ||
| 403 | R( d, e, a, b, c, F4, K4, M(62) ); | ||
| 404 | R( c, d, e, a, b, F4, K4, M(63) ); | ||
| 405 | R( b, c, d, e, a, F4, K4, M(64) ); | ||
| 406 | R( a, b, c, d, e, F4, K4, M(65) ); | ||
| 407 | R( e, a, b, c, d, F4, K4, M(66) ); | ||
| 408 | R( d, e, a, b, c, F4, K4, M(67) ); | ||
| 409 | R( c, d, e, a, b, F4, K4, M(68) ); | ||
| 410 | R( b, c, d, e, a, F4, K4, M(69) ); | ||
| 411 | R( a, b, c, d, e, F4, K4, M(70) ); | ||
| 412 | R( e, a, b, c, d, F4, K4, M(71) ); | ||
| 413 | R( d, e, a, b, c, F4, K4, M(72) ); | ||
| 414 | R( c, d, e, a, b, F4, K4, M(73) ); | ||
| 415 | R( b, c, d, e, a, F4, K4, M(74) ); | ||
| 416 | R( a, b, c, d, e, F4, K4, M(75) ); | ||
| 417 | R( e, a, b, c, d, F4, K4, M(76) ); | ||
| 418 | R( d, e, a, b, c, F4, K4, M(77) ); | ||
| 419 | R( c, d, e, a, b, F4, K4, M(78) ); | ||
| 420 | R( b, c, d, e, a, F4, K4, M(79) ); | ||
| 421 | |||
| 422 | a = ctx->A += a; | ||
| 423 | b = ctx->B += b; | ||
| 424 | c = ctx->C += c; | ||
| 425 | d = ctx->D += d; | ||
| 426 | e = ctx->E += e; | ||
| 427 | } | ||
| 428 | } | ||
diff --git a/gl/sha1.h b/gl/sha1.h new file mode 100644 index 00000000..de209b28 --- /dev/null +++ b/gl/sha1.h | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* Declarations of functions and data types used for SHA1 sum | ||
| 2 | library functions. | ||
| 3 | Copyright (C) 2000, 2001, 2003, 2005, 2006, 2008, 2009, 2010 Free Software | ||
| 4 | Foundation, Inc. | ||
| 5 | |||
| 6 | This program is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by the | ||
| 8 | Free Software Foundation; either version 3, or (at your option) any | ||
| 9 | later version. | ||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with this program; if not, write to the Free Software Foundation, | ||
| 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
| 19 | |||
| 20 | #ifndef SHA1_H | ||
| 21 | # define SHA1_H 1 | ||
| 22 | |||
| 23 | # include <stdio.h> | ||
| 24 | # include <stdint.h> | ||
| 25 | |||
| 26 | # ifdef __cplusplus | ||
| 27 | extern "C" { | ||
| 28 | # endif | ||
| 29 | |||
| 30 | #define SHA1_DIGEST_SIZE 20 | ||
| 31 | |||
| 32 | /* Structure to save state of computation between the single steps. */ | ||
| 33 | struct sha1_ctx | ||
| 34 | { | ||
| 35 | uint32_t A; | ||
| 36 | uint32_t B; | ||
| 37 | uint32_t C; | ||
| 38 | uint32_t D; | ||
| 39 | uint32_t E; | ||
| 40 | |||
| 41 | uint32_t total[2]; | ||
| 42 | uint32_t buflen; | ||
| 43 | uint32_t buffer[32]; | ||
| 44 | }; | ||
| 45 | |||
| 46 | |||
| 47 | /* Initialize structure containing state of computation. */ | ||
| 48 | extern void sha1_init_ctx (struct sha1_ctx *ctx); | ||
| 49 | |||
| 50 | /* Starting with the result of former calls of this function (or the | ||
| 51 | initialization function update the context for the next LEN bytes | ||
| 52 | starting at BUFFER. | ||
| 53 | It is necessary that LEN is a multiple of 64!!! */ | ||
| 54 | extern void sha1_process_block (const void *buffer, size_t len, | ||
| 55 | struct sha1_ctx *ctx); | ||
| 56 | |||
| 57 | /* Starting with the result of former calls of this function (or the | ||
| 58 | initialization function update the context for the next LEN bytes | ||
| 59 | starting at BUFFER. | ||
| 60 | It is NOT required that LEN is a multiple of 64. */ | ||
| 61 | extern void sha1_process_bytes (const void *buffer, size_t len, | ||
| 62 | struct sha1_ctx *ctx); | ||
| 63 | |||
| 64 | /* Process the remaining bytes in the buffer and put result from CTX | ||
| 65 | in first 20 bytes following RESBUF. The result is always in little | ||
| 66 | endian byte order, so that a byte-wise output yields to the wanted | ||
| 67 | ASCII representation of the message digest. */ | ||
| 68 | extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf); | ||
| 69 | |||
| 70 | |||
| 71 | /* Put result from CTX in first 20 bytes following RESBUF. The result is | ||
| 72 | always in little endian byte order, so that a byte-wise output yields | ||
| 73 | to the wanted ASCII representation of the message digest. */ | ||
| 74 | extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); | ||
| 75 | |||
| 76 | |||
| 77 | /* Compute SHA1 message digest for bytes read from STREAM. The | ||
| 78 | resulting message digest number will be written into the 20 bytes | ||
| 79 | beginning at RESBLOCK. */ | ||
| 80 | extern int sha1_stream (FILE *stream, void *resblock); | ||
| 81 | |||
| 82 | /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The | ||
| 83 | result is always in little endian byte order, so that a byte-wise | ||
| 84 | output yields to the wanted ASCII representation of the message | ||
| 85 | digest. */ | ||
| 86 | extern void *sha1_buffer (const char *buffer, size_t len, void *resblock); | ||
| 87 | |||
| 88 | # ifdef __cplusplus | ||
| 89 | } | ||
| 90 | # endif | ||
| 91 | |||
| 92 | #endif | ||
diff --git a/gl/stdbool.in.h b/gl/stdbool.in.h index e2312ecb..574c281a 100644 --- a/gl/stdbool.in.h +++ b/gl/stdbool.in.h | |||
| @@ -50,6 +50,9 @@ | |||
| 50 | with this substitute. With this substitute, only the values 0 and 1 | 50 | with this substitute. With this substitute, only the values 0 and 1 |
| 51 | give the expected result when converted to _Bool' or 'bool'. | 51 | give the expected result when converted to _Bool' or 'bool'. |
| 52 | 52 | ||
| 53 | - C99 allows the use of (_Bool)0.0 in constant expressions, but | ||
| 54 | this substitute cannot always provide this property. | ||
| 55 | |||
| 53 | Also, it is suggested that programs use 'bool' rather than '_Bool'; | 56 | Also, it is suggested that programs use 'bool' rather than '_Bool'; |
| 54 | this isn't required, but 'bool' is more common. */ | 57 | this isn't required, but 'bool' is more common. */ |
| 55 | 58 | ||
diff --git a/gl/stdio-write.c b/gl/stdio-write.c index f7da9e42..a6a0eb14 100644 --- a/gl/stdio-write.c +++ b/gl/stdio-write.c | |||
| @@ -63,7 +63,6 @@ | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | # if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */ | 65 | # if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */ |
| 66 | # if !DEPENDS_ON_LIBINTL /* avoid collision with intl/printf.c */ | ||
| 67 | int | 66 | int |
| 68 | printf (const char *format, ...) | 67 | printf (const char *format, ...) |
| 69 | { | 68 | { |
| @@ -76,7 +75,6 @@ printf (const char *format, ...) | |||
| 76 | 75 | ||
| 77 | return retval; | 76 | return retval; |
| 78 | } | 77 | } |
| 79 | # endif | ||
| 80 | # endif | 78 | # endif |
| 81 | 79 | ||
| 82 | # if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */ | 80 | # if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */ |
diff --git a/gl/stdio.in.h b/gl/stdio.in.h index dcb8ee57..80b9dbfd 100644 --- a/gl/stdio.in.h +++ b/gl/stdio.in.h | |||
| @@ -63,6 +63,10 @@ | |||
| 63 | 63 | ||
| 64 | /* The definition of _GL_WARN_ON_USE is copied here. */ | 64 | /* The definition of _GL_WARN_ON_USE is copied here. */ |
| 65 | 65 | ||
| 66 | /* Macros for stringification. */ | ||
| 67 | #define _GL_STDIO_STRINGIZE(token) #token | ||
| 68 | #define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token) | ||
| 69 | |||
| 66 | 70 | ||
| 67 | #if @GNULIB_DPRINTF@ | 71 | #if @GNULIB_DPRINTF@ |
| 68 | # if @REPLACE_DPRINTF@ | 72 | # if @REPLACE_DPRINTF@ |
| @@ -640,16 +644,26 @@ _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - " | |||
| 640 | #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@ | 644 | #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@ |
| 641 | # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \ | 645 | # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \ |
| 642 | || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@) | 646 | || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@) |
| 643 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | 647 | # if defined __GNUC__ |
| 648 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 644 | /* Don't break __attribute__((format(printf,M,N))). */ | 649 | /* Don't break __attribute__((format(printf,M,N))). */ |
| 645 | # define printf __printf__ | 650 | # define printf __printf__ |
| 646 | # endif | 651 | # endif |
| 647 | # define GNULIB_overrides_printf 1 | ||
| 648 | _GL_FUNCDECL_RPL_1 (__printf__, int, | 652 | _GL_FUNCDECL_RPL_1 (__printf__, int, |
| 649 | (const char *format, ...) | 653 | (const char *format, ...) |
| 654 | __asm__ (@ASM_SYMBOL_PREFIX@ | ||
| 655 | _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) | ||
| 650 | __attribute__ ((__format__ (__printf__, 1, 2))) | 656 | __attribute__ ((__format__ (__printf__, 1, 2))) |
| 651 | _GL_ARG_NONNULL ((1))); | 657 | _GL_ARG_NONNULL ((1))); |
| 652 | _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...)); | 658 | _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...)); |
| 659 | # else | ||
| 660 | _GL_FUNCDECL_RPL (printf, int, | ||
| 661 | (const char *format, ...) | ||
| 662 | __attribute__ ((__format__ (__printf__, 1, 2))) | ||
| 663 | _GL_ARG_NONNULL ((1))); | ||
| 664 | _GL_CXXALIAS_RPL (printf, int, (const char *format, ...)); | ||
| 665 | # endif | ||
| 666 | # define GNULIB_overrides_printf 1 | ||
| 653 | # else | 667 | # else |
| 654 | _GL_CXXALIAS_SYS (printf, int, (const char *format, ...)); | 668 | _GL_CXXALIAS_SYS (printf, int, (const char *format, ...)); |
| 655 | # endif | 669 | # endif |
diff --git a/gl/strerror.c b/gl/strerror.c index b0df7784..46153abf 100644 --- a/gl/strerror.c +++ b/gl/strerror.c | |||
| @@ -32,6 +32,9 @@ | |||
| 32 | 32 | ||
| 33 | # include "intprops.h" | 33 | # include "intprops.h" |
| 34 | 34 | ||
| 35 | /* Use the system functions, not the gnulib overrides in this file. */ | ||
| 36 | # undef sprintf | ||
| 37 | |||
| 35 | # undef strerror | 38 | # undef strerror |
| 36 | # if ! HAVE_DECL_STRERROR | 39 | # if ! HAVE_DECL_STRERROR |
| 37 | # define strerror(n) NULL | 40 | # define strerror(n) NULL |
diff --git a/gl/string.in.h b/gl/string.in.h index eb8d7588..13c0f095 100644 --- a/gl/string.in.h +++ b/gl/string.in.h | |||
| @@ -372,12 +372,23 @@ _GL_WARN_ON_USE (strndup, "strndup is unportable - " | |||
| 372 | MAXLEN bytes. If no '\0' terminator is found in that many bytes, | 372 | MAXLEN bytes. If no '\0' terminator is found in that many bytes, |
| 373 | return MAXLEN. */ | 373 | return MAXLEN. */ |
| 374 | #if @GNULIB_STRNLEN@ | 374 | #if @GNULIB_STRNLEN@ |
| 375 | # if ! @HAVE_DECL_STRNLEN@ | 375 | # if @REPLACE_STRNLEN@ |
| 376 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 377 | # undef strnlen | ||
| 378 | # define strnlen rpl_strnlen | ||
| 379 | # endif | ||
| 380 | _GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen) | ||
| 381 | __attribute__ ((__pure__)) | ||
| 382 | _GL_ARG_NONNULL ((1))); | ||
| 383 | _GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)); | ||
| 384 | # else | ||
| 385 | # if ! @HAVE_DECL_STRNLEN@ | ||
| 376 | _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) | 386 | _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) |
| 377 | __attribute__ ((__pure__)) | 387 | __attribute__ ((__pure__)) |
| 378 | _GL_ARG_NONNULL ((1))); | 388 | _GL_ARG_NONNULL ((1))); |
| 379 | # endif | 389 | # endif |
| 380 | _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); | 390 | _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); |
| 391 | # endif | ||
| 381 | _GL_CXXALIASWARN (strnlen); | 392 | _GL_CXXALIASWARN (strnlen); |
| 382 | #elif defined GNULIB_POSIXCHECK | 393 | #elif defined GNULIB_POSIXCHECK |
| 383 | # undef strnlen | 394 | # undef strnlen |
diff --git a/gl/sys_stat.in.h b/gl/sys_stat.in.h index a64bf029..dc7ef511 100644 --- a/gl/sys_stat.in.h +++ b/gl/sys_stat.in.h | |||
| @@ -56,7 +56,8 @@ | |||
| 56 | /* Before doing "#define mkdir rpl_mkdir" below, we need to include all | 56 | /* Before doing "#define mkdir rpl_mkdir" below, we need to include all |
| 57 | headers that may declare mkdir(). */ | 57 | headers that may declare mkdir(). */ |
| 58 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | 58 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
| 59 | # include <io.h> | 59 | # include <io.h> /* mingw32, mingw64 */ |
| 60 | # include <direct.h> /* mingw64 */ | ||
| 60 | #endif | 61 | #endif |
| 61 | 62 | ||
| 62 | #ifndef S_IFMT | 63 | #ifndef S_IFMT |
| @@ -455,7 +456,8 @@ _GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode)); | |||
| 455 | #else | 456 | #else |
| 456 | /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments. | 457 | /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments. |
| 457 | Additionally, it declares _mkdir (and depending on compile flags, an | 458 | Additionally, it declares _mkdir (and depending on compile flags, an |
| 458 | alias mkdir), only in the nonstandard <io.h>, which is included above. */ | 459 | alias mkdir), only in the nonstandard includes <direct.h> and <io.h>, |
| 460 | which are included above. */ | ||
| 459 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | 461 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
| 460 | 462 | ||
| 461 | static inline int | 463 | static inline int |
diff --git a/gl/time.in.h b/gl/time.in.h index 8e364feb..6fb4fd71 100644 --- a/gl/time.in.h +++ b/gl/time.in.h | |||
| @@ -48,10 +48,20 @@ | |||
| 48 | 48 | ||
| 49 | /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). | 49 | /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). |
| 50 | Or they define it with the wrong member names or define it in <sys/time.h> | 50 | Or they define it with the wrong member names or define it in <sys/time.h> |
| 51 | (e.g., FreeBSD circa 1997). */ | 51 | (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the |
| 52 | pthreads-win32 library defines it in <pthread.h>. */ | ||
| 52 | # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ | 53 | # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ |
| 53 | # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ | 54 | # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ |
| 54 | # include <sys/time.h> | 55 | # include <sys/time.h> |
| 56 | # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ | ||
| 57 | # include <pthread.h> | ||
| 58 | /* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */ | ||
| 59 | # undef asctime_r | ||
| 60 | # undef ctime_r | ||
| 61 | # undef gmtime_r | ||
| 62 | # undef localtime_r | ||
| 63 | # undef rand_r | ||
| 64 | # undef strtok_r | ||
| 55 | # else | 65 | # else |
| 56 | 66 | ||
| 57 | # ifdef __cplusplus | 67 | # ifdef __cplusplus |
diff --git a/gl/unistd.in.h b/gl/unistd.in.h index 45fc5dcf..7914f228 100644 --- a/gl/unistd.in.h +++ b/gl/unistd.in.h | |||
| @@ -86,7 +86,7 @@ | |||
| 86 | #endif | 86 | #endif |
| 87 | 87 | ||
| 88 | #if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \ | 88 | #if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \ |
| 89 | || @GNULIB_PREAD@ || defined GNULIB_POSIXCHECK) | 89 | || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK) |
| 90 | /* Get ssize_t. */ | 90 | /* Get ssize_t. */ |
| 91 | # include <sys/types.h> | 91 | # include <sys/types.h> |
| 92 | #endif | 92 | #endif |
| @@ -1016,6 +1016,40 @@ _GL_WARN_ON_USE (pread, "pread is unportable - " | |||
| 1016 | #endif | 1016 | #endif |
| 1017 | 1017 | ||
| 1018 | 1018 | ||
| 1019 | #if @GNULIB_PWRITE@ | ||
| 1020 | /* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET. | ||
| 1021 | Return the number of bytes written if successful, otherwise | ||
| 1022 | set errno and return -1. 0 indicates nothing written. See the | ||
| 1023 | POSIX:2001 specification | ||
| 1024 | <http://www.opengroup.org/susv3xsh/pwrite.html>. */ | ||
| 1025 | # if @REPLACE_PWRITE@ | ||
| 1026 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 1027 | # define pwrite rpl_pwrite | ||
| 1028 | # endif | ||
| 1029 | _GL_FUNCDECL_RPL (pwrite, ssize_t, | ||
| 1030 | (int fd, const void *buf, size_t bufsize, off_t offset) | ||
| 1031 | _GL_ARG_NONNULL ((2))); | ||
| 1032 | _GL_CXXALIAS_RPL (pwrite, ssize_t, | ||
| 1033 | (int fd, const void *buf, size_t bufsize, off_t offset)); | ||
| 1034 | # else | ||
| 1035 | # if !@HAVE_PWRITE@ | ||
| 1036 | _GL_FUNCDECL_SYS (pwrite, ssize_t, | ||
| 1037 | (int fd, const void *buf, size_t bufsize, off_t offset) | ||
| 1038 | _GL_ARG_NONNULL ((2))); | ||
| 1039 | # endif | ||
| 1040 | _GL_CXXALIAS_SYS (pwrite, ssize_t, | ||
| 1041 | (int fd, const void *buf, size_t bufsize, off_t offset)); | ||
| 1042 | # endif | ||
| 1043 | _GL_CXXALIASWARN (pwrite); | ||
| 1044 | #elif defined GNULIB_POSIXCHECK | ||
| 1045 | # undef pwrite | ||
| 1046 | # if HAVE_RAW_DECL_PWRITE | ||
| 1047 | _GL_WARN_ON_USE (pwrite, "pwrite is unportable - " | ||
| 1048 | "use gnulib module pwrite for portability"); | ||
| 1049 | # endif | ||
| 1050 | #endif | ||
| 1051 | |||
| 1052 | |||
| 1019 | #if @GNULIB_READLINK@ | 1053 | #if @GNULIB_READLINK@ |
| 1020 | /* Read the contents of the symbolic link FILE and place the first BUFSIZE | 1054 | /* Read the contents of the symbolic link FILE and place the first BUFSIZE |
| 1021 | bytes of it into BUF. Return the number of bytes placed into BUF if | 1055 | bytes of it into BUF. Return the number of bytes placed into BUF if |
| @@ -1164,12 +1198,23 @@ _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - " | |||
| 1164 | #if @GNULIB_TTYNAME_R@ | 1198 | #if @GNULIB_TTYNAME_R@ |
| 1165 | /* Store at most BUFLEN characters of the pathname of the terminal FD is | 1199 | /* Store at most BUFLEN characters of the pathname of the terminal FD is |
| 1166 | open on in BUF. Return 0 on success, otherwise an error number. */ | 1200 | open on in BUF. Return 0 on success, otherwise an error number. */ |
| 1167 | # if !@HAVE_TTYNAME_R@ | 1201 | # if @REPLACE_TTYNAME_R@ |
| 1202 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 1203 | # undef ttyname_r | ||
| 1204 | # define ttyname_r rpl_ttyname_r | ||
| 1205 | # endif | ||
| 1206 | _GL_FUNCDECL_RPL (ttyname_r, int, | ||
| 1207 | (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); | ||
| 1208 | _GL_CXXALIAS_RPL (ttyname_r, int, | ||
| 1209 | (int fd, char *buf, size_t buflen)); | ||
| 1210 | # else | ||
| 1211 | # if !@HAVE_TTYNAME_R@ | ||
| 1168 | _GL_FUNCDECL_SYS (ttyname_r, int, | 1212 | _GL_FUNCDECL_SYS (ttyname_r, int, |
| 1169 | (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); | 1213 | (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); |
| 1170 | # endif | 1214 | # endif |
| 1171 | _GL_CXXALIAS_SYS (ttyname_r, int, | 1215 | _GL_CXXALIAS_SYS (ttyname_r, int, |
| 1172 | (int fd, char *buf, size_t buflen)); | 1216 | (int fd, char *buf, size_t buflen)); |
| 1217 | # endif | ||
| 1173 | _GL_CXXALIASWARN (ttyname_r); | 1218 | _GL_CXXALIASWARN (ttyname_r); |
| 1174 | #elif defined GNULIB_POSIXCHECK | 1219 | #elif defined GNULIB_POSIXCHECK |
| 1175 | # undef ttyname_r | 1220 | # undef ttyname_r |
| @@ -1268,7 +1313,10 @@ _GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count) | |||
| 1268 | _GL_ARG_NONNULL ((2))); | 1313 | _GL_ARG_NONNULL ((2))); |
| 1269 | _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count)); | 1314 | _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count)); |
| 1270 | # else | 1315 | # else |
| 1271 | _GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count)); | 1316 | /* Need to cast, because on mingw, the third parameter is |
| 1317 | unsigned int count | ||
| 1318 | and the return type is 'int'. */ | ||
| 1319 | _GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count)); | ||
| 1272 | # endif | 1320 | # endif |
| 1273 | _GL_CXXALIASWARN (write); | 1321 | _GL_CXXALIASWARN (write); |
| 1274 | #endif | 1322 | #endif |
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c index 99d921e9..e618901b 100644 --- a/gl/vasnprintf.c +++ b/gl/vasnprintf.c | |||
| @@ -148,8 +148,14 @@ | |||
| 148 | # define USE_SNPRINTF 1 | 148 | # define USE_SNPRINTF 1 |
| 149 | # if HAVE_DECL__SNWPRINTF | 149 | # if HAVE_DECL__SNWPRINTF |
| 150 | /* On Windows, the function swprintf() has a different signature than | 150 | /* On Windows, the function swprintf() has a different signature than |
| 151 | on Unix; we use the _snwprintf() function instead. */ | 151 | on Unix; we use the function _snwprintf() or - on mingw - snwprintf() |
| 152 | # define SNPRINTF _snwprintf | 152 | instead. The mingw function snwprintf() has fewer bugs than the |
| 153 | MSVCRT function _snwprintf(), so prefer that. */ | ||
| 154 | # if defined __MINGW32__ | ||
| 155 | # define SNPRINTF snwprintf | ||
| 156 | # else | ||
| 157 | # define SNPRINTF _snwprintf | ||
| 158 | # endif | ||
| 153 | # else | 159 | # else |
| 154 | /* Unix. */ | 160 | /* Unix. */ |
| 155 | # define SNPRINTF swprintf | 161 | # define SNPRINTF swprintf |
| @@ -167,8 +173,15 @@ | |||
| 167 | # define USE_SNPRINTF 0 | 173 | # define USE_SNPRINTF 0 |
| 168 | # endif | 174 | # endif |
| 169 | # if HAVE_DECL__SNPRINTF | 175 | # if HAVE_DECL__SNPRINTF |
| 170 | /* Windows. */ | 176 | /* Windows. The mingw function snprintf() has fewer bugs than the MSVCRT |
| 171 | # define SNPRINTF _snprintf | 177 | function _snprintf(), so prefer that. */ |
| 178 | # if defined __MINGW32__ | ||
| 179 | # define SNPRINTF snprintf | ||
| 180 | /* Here we need to call the native snprintf, not rpl_snprintf. */ | ||
| 181 | # undef snprintf | ||
| 182 | # else | ||
| 183 | # define SNPRINTF _snprintf | ||
| 184 | # endif | ||
| 172 | # else | 185 | # else |
| 173 | /* Unix. */ | 186 | /* Unix. */ |
| 174 | # define SNPRINTF snprintf | 187 | # define SNPRINTF snprintf |
| @@ -194,7 +207,7 @@ | |||
| 194 | #undef remainder | 207 | #undef remainder |
| 195 | #define remainder rem | 208 | #define remainder rem |
| 196 | 209 | ||
| 197 | #if !USE_SNPRINTF && !WIDE_CHAR_VERSION | 210 | #if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && !WIDE_CHAR_VERSION |
| 198 | # if (HAVE_STRNLEN && !defined _AIX) | 211 | # if (HAVE_STRNLEN && !defined _AIX) |
| 199 | # define local_strnlen strnlen | 212 | # define local_strnlen strnlen |
| 200 | # else | 213 | # else |
| @@ -210,7 +223,7 @@ local_strnlen (const char *string, size_t maxlen) | |||
| 210 | # endif | 223 | # endif |
| 211 | #endif | 224 | #endif |
| 212 | 225 | ||
| 213 | #if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T && (WIDE_CHAR_VERSION || DCHAR_IS_TCHAR) | 226 | #if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T |
| 214 | # if HAVE_WCSLEN | 227 | # if HAVE_WCSLEN |
| 215 | # define local_wcslen wcslen | 228 | # define local_wcslen wcslen |
| 216 | # else | 229 | # else |
| @@ -233,7 +246,7 @@ local_wcslen (const wchar_t *s) | |||
| 233 | # endif | 246 | # endif |
| 234 | #endif | 247 | #endif |
| 235 | 248 | ||
| 236 | #if !USE_SNPRINTF && HAVE_WCHAR_T && WIDE_CHAR_VERSION | 249 | #if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && HAVE_WCHAR_T && WIDE_CHAR_VERSION |
| 237 | # if HAVE_WCSNLEN | 250 | # if HAVE_WCSNLEN |
| 238 | # define local_wcsnlen wcsnlen | 251 | # define local_wcsnlen wcsnlen |
| 239 | # else | 252 | # else |
| @@ -1474,6 +1487,258 @@ is_borderline (const char *digits, size_t precision) | |||
| 1474 | 1487 | ||
| 1475 | #endif | 1488 | #endif |
| 1476 | 1489 | ||
| 1490 | #if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 | ||
| 1491 | |||
| 1492 | /* Use a different function name, to make it possible that the 'wchar_t' | ||
| 1493 | parametrization and the 'char' parametrization get compiled in the same | ||
| 1494 | translation unit. */ | ||
| 1495 | # if WIDE_CHAR_VERSION | ||
| 1496 | # define MAX_ROOM_NEEDED wmax_room_needed | ||
| 1497 | # else | ||
| 1498 | # define MAX_ROOM_NEEDED max_room_needed | ||
| 1499 | # endif | ||
| 1500 | |||
| 1501 | /* Returns the number of TCHAR_T units needed as temporary space for the result | ||
| 1502 | of sprintf or SNPRINTF of a single conversion directive. */ | ||
| 1503 | static inline size_t | ||
| 1504 | MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, | ||
| 1505 | arg_type type, int flags, size_t width, int has_precision, | ||
| 1506 | size_t precision, int pad_ourselves) | ||
| 1507 | { | ||
| 1508 | size_t tmp_length; | ||
| 1509 | |||
| 1510 | switch (conversion) | ||
| 1511 | { | ||
| 1512 | case 'd': case 'i': case 'u': | ||
| 1513 | # if HAVE_LONG_LONG_INT | ||
| 1514 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
| 1515 | tmp_length = | ||
| 1516 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
| 1517 | * 0.30103 /* binary -> decimal */ | ||
| 1518 | ) | ||
| 1519 | + 1; /* turn floor into ceil */ | ||
| 1520 | else | ||
| 1521 | # endif | ||
| 1522 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
| 1523 | tmp_length = | ||
| 1524 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
| 1525 | * 0.30103 /* binary -> decimal */ | ||
| 1526 | ) | ||
| 1527 | + 1; /* turn floor into ceil */ | ||
| 1528 | else | ||
| 1529 | tmp_length = | ||
| 1530 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
| 1531 | * 0.30103 /* binary -> decimal */ | ||
| 1532 | ) | ||
| 1533 | + 1; /* turn floor into ceil */ | ||
| 1534 | if (tmp_length < precision) | ||
| 1535 | tmp_length = precision; | ||
| 1536 | /* Multiply by 2, as an estimate for FLAG_GROUP. */ | ||
| 1537 | tmp_length = xsum (tmp_length, tmp_length); | ||
| 1538 | /* Add 1, to account for a leading sign. */ | ||
| 1539 | tmp_length = xsum (tmp_length, 1); | ||
| 1540 | break; | ||
| 1541 | |||
| 1542 | case 'o': | ||
| 1543 | # if HAVE_LONG_LONG_INT | ||
| 1544 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
| 1545 | tmp_length = | ||
| 1546 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
| 1547 | * 0.333334 /* binary -> octal */ | ||
| 1548 | ) | ||
| 1549 | + 1; /* turn floor into ceil */ | ||
| 1550 | else | ||
| 1551 | # endif | ||
| 1552 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
| 1553 | tmp_length = | ||
| 1554 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
| 1555 | * 0.333334 /* binary -> octal */ | ||
| 1556 | ) | ||
| 1557 | + 1; /* turn floor into ceil */ | ||
| 1558 | else | ||
| 1559 | tmp_length = | ||
| 1560 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
| 1561 | * 0.333334 /* binary -> octal */ | ||
| 1562 | ) | ||
| 1563 | + 1; /* turn floor into ceil */ | ||
| 1564 | if (tmp_length < precision) | ||
| 1565 | tmp_length = precision; | ||
| 1566 | /* Add 1, to account for a leading sign. */ | ||
| 1567 | tmp_length = xsum (tmp_length, 1); | ||
| 1568 | break; | ||
| 1569 | |||
| 1570 | case 'x': case 'X': | ||
| 1571 | # if HAVE_LONG_LONG_INT | ||
| 1572 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
| 1573 | tmp_length = | ||
| 1574 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
| 1575 | * 0.25 /* binary -> hexadecimal */ | ||
| 1576 | ) | ||
| 1577 | + 1; /* turn floor into ceil */ | ||
| 1578 | else | ||
| 1579 | # endif | ||
| 1580 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
| 1581 | tmp_length = | ||
| 1582 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
| 1583 | * 0.25 /* binary -> hexadecimal */ | ||
| 1584 | ) | ||
| 1585 | + 1; /* turn floor into ceil */ | ||
| 1586 | else | ||
| 1587 | tmp_length = | ||
| 1588 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
| 1589 | * 0.25 /* binary -> hexadecimal */ | ||
| 1590 | ) | ||
| 1591 | + 1; /* turn floor into ceil */ | ||
| 1592 | if (tmp_length < precision) | ||
| 1593 | tmp_length = precision; | ||
| 1594 | /* Add 2, to account for a leading sign or alternate form. */ | ||
| 1595 | tmp_length = xsum (tmp_length, 2); | ||
| 1596 | break; | ||
| 1597 | |||
| 1598 | case 'f': case 'F': | ||
| 1599 | if (type == TYPE_LONGDOUBLE) | ||
| 1600 | tmp_length = | ||
| 1601 | (unsigned int) (LDBL_MAX_EXP | ||
| 1602 | * 0.30103 /* binary -> decimal */ | ||
| 1603 | * 2 /* estimate for FLAG_GROUP */ | ||
| 1604 | ) | ||
| 1605 | + 1 /* turn floor into ceil */ | ||
| 1606 | + 10; /* sign, decimal point etc. */ | ||
| 1607 | else | ||
| 1608 | tmp_length = | ||
| 1609 | (unsigned int) (DBL_MAX_EXP | ||
| 1610 | * 0.30103 /* binary -> decimal */ | ||
| 1611 | * 2 /* estimate for FLAG_GROUP */ | ||
| 1612 | ) | ||
| 1613 | + 1 /* turn floor into ceil */ | ||
| 1614 | + 10; /* sign, decimal point etc. */ | ||
| 1615 | tmp_length = xsum (tmp_length, precision); | ||
| 1616 | break; | ||
| 1617 | |||
| 1618 | case 'e': case 'E': case 'g': case 'G': | ||
| 1619 | tmp_length = | ||
| 1620 | 12; /* sign, decimal point, exponent etc. */ | ||
| 1621 | tmp_length = xsum (tmp_length, precision); | ||
| 1622 | break; | ||
| 1623 | |||
| 1624 | case 'a': case 'A': | ||
| 1625 | if (type == TYPE_LONGDOUBLE) | ||
| 1626 | tmp_length = | ||
| 1627 | (unsigned int) (LDBL_DIG | ||
| 1628 | * 0.831 /* decimal -> hexadecimal */ | ||
| 1629 | ) | ||
| 1630 | + 1; /* turn floor into ceil */ | ||
| 1631 | else | ||
| 1632 | tmp_length = | ||
| 1633 | (unsigned int) (DBL_DIG | ||
| 1634 | * 0.831 /* decimal -> hexadecimal */ | ||
| 1635 | ) | ||
| 1636 | + 1; /* turn floor into ceil */ | ||
| 1637 | if (tmp_length < precision) | ||
| 1638 | tmp_length = precision; | ||
| 1639 | /* Account for sign, decimal point etc. */ | ||
| 1640 | tmp_length = xsum (tmp_length, 12); | ||
| 1641 | break; | ||
| 1642 | |||
| 1643 | case 'c': | ||
| 1644 | # if HAVE_WINT_T && !WIDE_CHAR_VERSION | ||
| 1645 | if (type == TYPE_WIDE_CHAR) | ||
| 1646 | tmp_length = MB_CUR_MAX; | ||
| 1647 | else | ||
| 1648 | # endif | ||
| 1649 | tmp_length = 1; | ||
| 1650 | break; | ||
| 1651 | |||
| 1652 | case 's': | ||
| 1653 | # if HAVE_WCHAR_T | ||
| 1654 | if (type == TYPE_WIDE_STRING) | ||
| 1655 | { | ||
| 1656 | # if WIDE_CHAR_VERSION | ||
| 1657 | /* ISO C says about %ls in fwprintf: | ||
| 1658 | "If the precision is not specified or is greater than the size | ||
| 1659 | of the array, the array shall contain a null wide character." | ||
| 1660 | So if there is a precision, we must not use wcslen. */ | ||
| 1661 | const wchar_t *arg = ap->arg[arg_index].a.a_wide_string; | ||
| 1662 | |||
| 1663 | if (has_precision) | ||
| 1664 | tmp_length = local_wcsnlen (arg, precision); | ||
| 1665 | else | ||
| 1666 | tmp_length = local_wcslen (arg); | ||
| 1667 | # else | ||
| 1668 | /* ISO C says about %ls in fprintf: | ||
| 1669 | "If a precision is specified, no more than that many bytes are | ||
| 1670 | written (including shift sequences, if any), and the array | ||
| 1671 | shall contain a null wide character if, to equal the multibyte | ||
| 1672 | character sequence length given by the precision, the function | ||
| 1673 | would need to access a wide character one past the end of the | ||
| 1674 | array." | ||
| 1675 | So if there is a precision, we must not use wcslen. */ | ||
| 1676 | /* This case has already been handled separately in VASNPRINTF. */ | ||
| 1677 | abort (); | ||
| 1678 | # endif | ||
| 1679 | } | ||
| 1680 | else | ||
| 1681 | # endif | ||
| 1682 | { | ||
| 1683 | # if WIDE_CHAR_VERSION | ||
| 1684 | /* ISO C says about %s in fwprintf: | ||
| 1685 | "If the precision is not specified or is greater than the size | ||
| 1686 | of the converted array, the converted array shall contain a | ||
| 1687 | null wide character." | ||
| 1688 | So if there is a precision, we must not use strlen. */ | ||
| 1689 | /* This case has already been handled separately in VASNPRINTF. */ | ||
| 1690 | abort (); | ||
| 1691 | # else | ||
| 1692 | /* ISO C says about %s in fprintf: | ||
| 1693 | "If the precision is not specified or greater than the size of | ||
| 1694 | the array, the array shall contain a null character." | ||
| 1695 | So if there is a precision, we must not use strlen. */ | ||
| 1696 | const char *arg = ap->arg[arg_index].a.a_string; | ||
| 1697 | |||
| 1698 | if (has_precision) | ||
| 1699 | tmp_length = local_strnlen (arg, precision); | ||
| 1700 | else | ||
| 1701 | tmp_length = strlen (arg); | ||
| 1702 | # endif | ||
| 1703 | } | ||
| 1704 | break; | ||
| 1705 | |||
| 1706 | case 'p': | ||
| 1707 | tmp_length = | ||
| 1708 | (unsigned int) (sizeof (void *) * CHAR_BIT | ||
| 1709 | * 0.25 /* binary -> hexadecimal */ | ||
| 1710 | ) | ||
| 1711 | + 1 /* turn floor into ceil */ | ||
| 1712 | + 2; /* account for leading 0x */ | ||
| 1713 | break; | ||
| 1714 | |||
| 1715 | default: | ||
| 1716 | abort (); | ||
| 1717 | } | ||
| 1718 | |||
| 1719 | if (!pad_ourselves) | ||
| 1720 | { | ||
| 1721 | # if ENABLE_UNISTDIO | ||
| 1722 | /* Padding considers the number of characters, therefore the number of | ||
| 1723 | elements after padding may be | ||
| 1724 | > max (tmp_length, width) | ||
| 1725 | but is certainly | ||
| 1726 | <= tmp_length + width. */ | ||
| 1727 | tmp_length = xsum (tmp_length, width); | ||
| 1728 | # else | ||
| 1729 | /* Padding considers the number of elements, says POSIX. */ | ||
| 1730 | if (tmp_length < width) | ||
| 1731 | tmp_length = width; | ||
| 1732 | # endif | ||
| 1733 | } | ||
| 1734 | |||
| 1735 | tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ | ||
| 1736 | |||
| 1737 | return tmp_length; | ||
| 1738 | } | ||
| 1739 | |||
| 1740 | #endif | ||
| 1741 | |||
| 1477 | DCHAR_T * | 1742 | DCHAR_T * |
| 1478 | VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | 1743 | VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, |
| 1479 | const FCHAR_T *format, va_list args) | 1744 | const FCHAR_T *format, va_list args) |
| @@ -2103,7 +2368,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 2103 | } | 2368 | } |
| 2104 | } | 2369 | } |
| 2105 | #endif | 2370 | #endif |
| 2106 | #if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T | 2371 | #if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T |
| 2107 | else if (dp->conversion == 's' | 2372 | else if (dp->conversion == 's' |
| 2108 | # if WIDE_CHAR_VERSION | 2373 | # if WIDE_CHAR_VERSION |
| 2109 | && a.arg[dp->arg_index].type != TYPE_WIDE_STRING | 2374 | && a.arg[dp->arg_index].type != TYPE_WIDE_STRING |
| @@ -2592,8 +2857,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 2592 | count = wctomb (cbuf, *arg); | 2857 | count = wctomb (cbuf, *arg); |
| 2593 | # endif | 2858 | # endif |
| 2594 | if (count <= 0) | 2859 | if (count <= 0) |
| 2595 | /* Inconsistency. */ | 2860 | { |
| 2596 | abort (); | 2861 | /* Cannot convert. */ |
| 2862 | if (!(result == resultbuf || result == NULL)) | ||
| 2863 | free (result); | ||
| 2864 | if (buf_malloced != NULL) | ||
| 2865 | free (buf_malloced); | ||
| 2866 | CLEANUP (); | ||
| 2867 | errno = EILSEQ; | ||
| 2868 | return NULL; | ||
| 2869 | } | ||
| 2597 | ENSURE_ALLOCATION (xsum (length, count)); | 2870 | ENSURE_ALLOCATION (xsum (length, count)); |
| 2598 | memcpy (result + length, cbuf, count); | 2871 | memcpy (result + length, cbuf, count); |
| 2599 | length += count; | 2872 | length += count; |
| @@ -2616,8 +2889,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 2616 | length += n; | 2889 | length += n; |
| 2617 | } | 2890 | } |
| 2618 | } | 2891 | } |
| 2619 | } | ||
| 2620 | # endif | 2892 | # endif |
| 2893 | } | ||
| 2621 | #endif | 2894 | #endif |
| 2622 | #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL | 2895 | #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL |
| 2623 | else if ((dp->conversion == 'a' || dp->conversion == 'A') | 2896 | else if ((dp->conversion == 'a' || dp->conversion == 'A') |
| @@ -4301,11 +4574,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 4301 | { | 4574 | { |
| 4302 | arg_type type = a.arg[dp->arg_index].type; | 4575 | arg_type type = a.arg[dp->arg_index].type; |
| 4303 | int flags = dp->flags; | 4576 | int flags = dp->flags; |
| 4304 | #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION | 4577 | #if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION |
| 4305 | int has_width; | 4578 | int has_width; |
| 4306 | size_t width; | 4579 | size_t width; |
| 4307 | #endif | 4580 | #endif |
| 4308 | #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION | 4581 | #if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION |
| 4309 | int has_precision; | 4582 | int has_precision; |
| 4310 | size_t precision; | 4583 | size_t precision; |
| 4311 | #endif | 4584 | #endif |
| @@ -4330,7 +4603,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 4330 | TCHAR_T *tmp; | 4603 | TCHAR_T *tmp; |
| 4331 | #endif | 4604 | #endif |
| 4332 | 4605 | ||
| 4333 | #if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION | 4606 | #if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION |
| 4334 | has_width = 0; | 4607 | has_width = 0; |
| 4335 | width = 0; | 4608 | width = 0; |
| 4336 | if (dp->width_start != dp->width_end) | 4609 | if (dp->width_start != dp->width_end) |
| @@ -4364,7 +4637,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 4364 | } | 4637 | } |
| 4365 | #endif | 4638 | #endif |
| 4366 | 4639 | ||
| 4367 | #if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION | 4640 | #if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION |
| 4368 | has_precision = 0; | 4641 | has_precision = 0; |
| 4369 | precision = 6; | 4642 | precision = 6; |
| 4370 | if (dp->precision_start != dp->precision_end) | 4643 | if (dp->precision_start != dp->precision_end) |
| @@ -4437,246 +4710,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 4437 | #if !USE_SNPRINTF | 4710 | #if !USE_SNPRINTF |
| 4438 | /* Allocate a temporary buffer of sufficient size for calling | 4711 | /* Allocate a temporary buffer of sufficient size for calling |
| 4439 | sprintf. */ | 4712 | sprintf. */ |
| 4440 | { | 4713 | tmp_length = |
| 4441 | switch (dp->conversion) | 4714 | MAX_ROOM_NEEDED (&a, dp->arg_index, dp->conversion, type, |
| 4442 | { | 4715 | flags, width, has_precision, precision, |
| 4443 | 4716 | pad_ourselves); | |
| 4444 | case 'd': case 'i': case 'u': | ||
| 4445 | # if HAVE_LONG_LONG_INT | ||
| 4446 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
| 4447 | tmp_length = | ||
| 4448 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
| 4449 | * 0.30103 /* binary -> decimal */ | ||
| 4450 | ) | ||
| 4451 | + 1; /* turn floor into ceil */ | ||
| 4452 | else | ||
| 4453 | # endif | ||
| 4454 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
| 4455 | tmp_length = | ||
| 4456 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
| 4457 | * 0.30103 /* binary -> decimal */ | ||
| 4458 | ) | ||
| 4459 | + 1; /* turn floor into ceil */ | ||
| 4460 | else | ||
| 4461 | tmp_length = | ||
| 4462 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
| 4463 | * 0.30103 /* binary -> decimal */ | ||
| 4464 | ) | ||
| 4465 | + 1; /* turn floor into ceil */ | ||
| 4466 | if (tmp_length < precision) | ||
| 4467 | tmp_length = precision; | ||
| 4468 | /* Multiply by 2, as an estimate for FLAG_GROUP. */ | ||
| 4469 | tmp_length = xsum (tmp_length, tmp_length); | ||
| 4470 | /* Add 1, to account for a leading sign. */ | ||
| 4471 | tmp_length = xsum (tmp_length, 1); | ||
| 4472 | break; | ||
| 4473 | |||
| 4474 | case 'o': | ||
| 4475 | # if HAVE_LONG_LONG_INT | ||
| 4476 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
| 4477 | tmp_length = | ||
| 4478 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
| 4479 | * 0.333334 /* binary -> octal */ | ||
| 4480 | ) | ||
| 4481 | + 1; /* turn floor into ceil */ | ||
| 4482 | else | ||
| 4483 | # endif | ||
| 4484 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
| 4485 | tmp_length = | ||
| 4486 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
| 4487 | * 0.333334 /* binary -> octal */ | ||
| 4488 | ) | ||
| 4489 | + 1; /* turn floor into ceil */ | ||
| 4490 | else | ||
| 4491 | tmp_length = | ||
| 4492 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
| 4493 | * 0.333334 /* binary -> octal */ | ||
| 4494 | ) | ||
| 4495 | + 1; /* turn floor into ceil */ | ||
| 4496 | if (tmp_length < precision) | ||
| 4497 | tmp_length = precision; | ||
| 4498 | /* Add 1, to account for a leading sign. */ | ||
| 4499 | tmp_length = xsum (tmp_length, 1); | ||
| 4500 | break; | ||
| 4501 | |||
| 4502 | case 'x': case 'X': | ||
| 4503 | # if HAVE_LONG_LONG_INT | ||
| 4504 | if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) | ||
| 4505 | tmp_length = | ||
| 4506 | (unsigned int) (sizeof (unsigned long long) * CHAR_BIT | ||
| 4507 | * 0.25 /* binary -> hexadecimal */ | ||
| 4508 | ) | ||
| 4509 | + 1; /* turn floor into ceil */ | ||
| 4510 | else | ||
| 4511 | # endif | ||
| 4512 | if (type == TYPE_LONGINT || type == TYPE_ULONGINT) | ||
| 4513 | tmp_length = | ||
| 4514 | (unsigned int) (sizeof (unsigned long) * CHAR_BIT | ||
| 4515 | * 0.25 /* binary -> hexadecimal */ | ||
| 4516 | ) | ||
| 4517 | + 1; /* turn floor into ceil */ | ||
| 4518 | else | ||
| 4519 | tmp_length = | ||
| 4520 | (unsigned int) (sizeof (unsigned int) * CHAR_BIT | ||
| 4521 | * 0.25 /* binary -> hexadecimal */ | ||
| 4522 | ) | ||
| 4523 | + 1; /* turn floor into ceil */ | ||
| 4524 | if (tmp_length < precision) | ||
| 4525 | tmp_length = precision; | ||
| 4526 | /* Add 2, to account for a leading sign or alternate form. */ | ||
| 4527 | tmp_length = xsum (tmp_length, 2); | ||
| 4528 | break; | ||
| 4529 | |||
| 4530 | case 'f': case 'F': | ||
| 4531 | if (type == TYPE_LONGDOUBLE) | ||
| 4532 | tmp_length = | ||
| 4533 | (unsigned int) (LDBL_MAX_EXP | ||
| 4534 | * 0.30103 /* binary -> decimal */ | ||
| 4535 | * 2 /* estimate for FLAG_GROUP */ | ||
| 4536 | ) | ||
| 4537 | + 1 /* turn floor into ceil */ | ||
| 4538 | + 10; /* sign, decimal point etc. */ | ||
| 4539 | else | ||
| 4540 | tmp_length = | ||
| 4541 | (unsigned int) (DBL_MAX_EXP | ||
| 4542 | * 0.30103 /* binary -> decimal */ | ||
| 4543 | * 2 /* estimate for FLAG_GROUP */ | ||
| 4544 | ) | ||
| 4545 | + 1 /* turn floor into ceil */ | ||
| 4546 | + 10; /* sign, decimal point etc. */ | ||
| 4547 | tmp_length = xsum (tmp_length, precision); | ||
| 4548 | break; | ||
| 4549 | |||
| 4550 | case 'e': case 'E': case 'g': case 'G': | ||
| 4551 | tmp_length = | ||
| 4552 | 12; /* sign, decimal point, exponent etc. */ | ||
| 4553 | tmp_length = xsum (tmp_length, precision); | ||
| 4554 | break; | ||
| 4555 | |||
| 4556 | case 'a': case 'A': | ||
| 4557 | if (type == TYPE_LONGDOUBLE) | ||
| 4558 | tmp_length = | ||
| 4559 | (unsigned int) (LDBL_DIG | ||
| 4560 | * 0.831 /* decimal -> hexadecimal */ | ||
| 4561 | ) | ||
| 4562 | + 1; /* turn floor into ceil */ | ||
| 4563 | else | ||
| 4564 | tmp_length = | ||
| 4565 | (unsigned int) (DBL_DIG | ||
| 4566 | * 0.831 /* decimal -> hexadecimal */ | ||
| 4567 | ) | ||
| 4568 | + 1; /* turn floor into ceil */ | ||
| 4569 | if (tmp_length < precision) | ||
| 4570 | tmp_length = precision; | ||
| 4571 | /* Account for sign, decimal point etc. */ | ||
| 4572 | tmp_length = xsum (tmp_length, 12); | ||
| 4573 | break; | ||
| 4574 | |||
| 4575 | case 'c': | ||
| 4576 | # if HAVE_WINT_T && !WIDE_CHAR_VERSION | ||
| 4577 | if (type == TYPE_WIDE_CHAR) | ||
| 4578 | tmp_length = MB_CUR_MAX; | ||
| 4579 | else | ||
| 4580 | # endif | ||
| 4581 | tmp_length = 1; | ||
| 4582 | break; | ||
| 4583 | |||
| 4584 | case 's': | ||
| 4585 | # if HAVE_WCHAR_T | ||
| 4586 | if (type == TYPE_WIDE_STRING) | ||
| 4587 | { | ||
| 4588 | # if WIDE_CHAR_VERSION | ||
| 4589 | /* ISO C says about %ls in fwprintf: | ||
| 4590 | "If the precision is not specified or is greater | ||
| 4591 | than the size of the array, the array shall | ||
| 4592 | contain a null wide character." | ||
| 4593 | So if there is a precision, we must not use | ||
| 4594 | wcslen. */ | ||
| 4595 | const wchar_t *arg = | ||
| 4596 | a.arg[dp->arg_index].a.a_wide_string; | ||
| 4597 | |||
| 4598 | if (has_precision) | ||
| 4599 | tmp_length = local_wcsnlen (arg, precision); | ||
| 4600 | else | ||
| 4601 | tmp_length = local_wcslen (arg); | ||
| 4602 | # else | ||
| 4603 | /* ISO C says about %ls in fprintf: | ||
| 4604 | "If a precision is specified, no more than that | ||
| 4605 | many bytes are written (including shift | ||
| 4606 | sequences, if any), and the array shall contain | ||
| 4607 | a null wide character if, to equal the | ||
| 4608 | multibyte character sequence length given by | ||
| 4609 | the precision, the function would need to | ||
| 4610 | access a wide character one past the end of the | ||
| 4611 | array." | ||
| 4612 | So if there is a precision, we must not use | ||
| 4613 | wcslen. */ | ||
| 4614 | /* This case has already been handled above. */ | ||
| 4615 | abort (); | ||
| 4616 | # endif | ||
| 4617 | } | ||
| 4618 | else | ||
| 4619 | # endif | ||
| 4620 | { | ||
| 4621 | # if WIDE_CHAR_VERSION | ||
| 4622 | /* ISO C says about %s in fwprintf: | ||
| 4623 | "If the precision is not specified or is greater | ||
| 4624 | than the size of the converted array, the | ||
| 4625 | converted array shall contain a null wide | ||
| 4626 | character." | ||
| 4627 | So if there is a precision, we must not use | ||
| 4628 | strlen. */ | ||
| 4629 | /* This case has already been handled above. */ | ||
| 4630 | abort (); | ||
| 4631 | # else | ||
| 4632 | /* ISO C says about %s in fprintf: | ||
| 4633 | "If the precision is not specified or greater | ||
| 4634 | than the size of the array, the array shall | ||
| 4635 | contain a null character." | ||
| 4636 | So if there is a precision, we must not use | ||
| 4637 | strlen. */ | ||
| 4638 | const char *arg = a.arg[dp->arg_index].a.a_string; | ||
| 4639 | |||
| 4640 | if (has_precision) | ||
| 4641 | tmp_length = local_strnlen (arg, precision); | ||
| 4642 | else | ||
| 4643 | tmp_length = strlen (arg); | ||
| 4644 | # endif | ||
| 4645 | } | ||
| 4646 | break; | ||
| 4647 | |||
| 4648 | case 'p': | ||
| 4649 | tmp_length = | ||
| 4650 | (unsigned int) (sizeof (void *) * CHAR_BIT | ||
| 4651 | * 0.25 /* binary -> hexadecimal */ | ||
| 4652 | ) | ||
| 4653 | + 1 /* turn floor into ceil */ | ||
| 4654 | + 2; /* account for leading 0x */ | ||
| 4655 | break; | ||
| 4656 | |||
| 4657 | default: | ||
| 4658 | abort (); | ||
| 4659 | } | ||
| 4660 | |||
| 4661 | if (!pad_ourselves) | ||
| 4662 | { | ||
| 4663 | # if ENABLE_UNISTDIO | ||
| 4664 | /* Padding considers the number of characters, therefore | ||
| 4665 | the number of elements after padding may be | ||
| 4666 | > max (tmp_length, width) | ||
| 4667 | but is certainly | ||
| 4668 | <= tmp_length + width. */ | ||
| 4669 | tmp_length = xsum (tmp_length, width); | ||
| 4670 | # else | ||
| 4671 | /* Padding considers the number of elements, | ||
| 4672 | says POSIX. */ | ||
| 4673 | if (tmp_length < width) | ||
| 4674 | tmp_length = width; | ||
| 4675 | # endif | ||
| 4676 | } | ||
| 4677 | |||
| 4678 | tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ | ||
| 4679 | } | ||
| 4680 | 4717 | ||
| 4681 | if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) | 4718 | if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) |
| 4682 | tmp = tmpbuf; | 4719 | tmp = tmpbuf; |
| @@ -4916,6 +4953,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 4916 | } | 4953 | } |
| 4917 | #endif | 4954 | #endif |
| 4918 | 4955 | ||
| 4956 | errno = 0; | ||
| 4919 | switch (type) | 4957 | switch (type) |
| 4920 | { | 4958 | { |
| 4921 | case TYPE_SCHAR: | 4959 | case TYPE_SCHAR: |
| @@ -5062,15 +5100,44 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 5062 | /* Look at the snprintf() return value. */ | 5100 | /* Look at the snprintf() return value. */ |
| 5063 | if (retcount < 0) | 5101 | if (retcount < 0) |
| 5064 | { | 5102 | { |
| 5103 | # if !HAVE_SNPRINTF_RETVAL_C99 | ||
| 5065 | /* HP-UX 10.20 snprintf() is doubly deficient: | 5104 | /* HP-UX 10.20 snprintf() is doubly deficient: |
| 5066 | It doesn't understand the '%n' directive, | 5105 | It doesn't understand the '%n' directive, |
| 5067 | *and* it returns -1 (rather than the length | 5106 | *and* it returns -1 (rather than the length |
| 5068 | that would have been required) when the | 5107 | that would have been required) when the |
| 5069 | buffer is too small. */ | 5108 | buffer is too small. |
| 5070 | size_t bigger_need = | 5109 | But a failure at this point can also come |
| 5071 | xsum (xtimes (allocated, 2), 12); | 5110 | from other reasons than a too small buffer, |
| 5072 | ENSURE_ALLOCATION (bigger_need); | 5111 | such as an invalid wide string argument to |
| 5073 | continue; | 5112 | the %ls directive, or possibly an invalid |
| 5113 | floating-point argument. */ | ||
| 5114 | size_t tmp_length = | ||
| 5115 | MAX_ROOM_NEEDED (&a, dp->arg_index, | ||
| 5116 | dp->conversion, type, flags, | ||
| 5117 | width, has_precision, | ||
| 5118 | precision, pad_ourselves); | ||
| 5119 | |||
| 5120 | if (maxlen < tmp_length) | ||
| 5121 | { | ||
| 5122 | /* Make more room. But try to do through | ||
| 5123 | this reallocation only once. */ | ||
| 5124 | size_t bigger_need = | ||
| 5125 | xsum (length, | ||
| 5126 | xsum (tmp_length, | ||
| 5127 | TCHARS_PER_DCHAR - 1) | ||
| 5128 | / TCHARS_PER_DCHAR); | ||
| 5129 | /* And always grow proportionally. | ||
| 5130 | (There may be several arguments, each | ||
| 5131 | needing a little more room than the | ||
| 5132 | previous one.) */ | ||
| 5133 | size_t bigger_need2 = | ||
| 5134 | xsum (xtimes (allocated, 2), 12); | ||
| 5135 | if (bigger_need < bigger_need2) | ||
| 5136 | bigger_need = bigger_need2; | ||
| 5137 | ENSURE_ALLOCATION (bigger_need); | ||
| 5138 | continue; | ||
| 5139 | } | ||
| 5140 | # endif | ||
| 5074 | } | 5141 | } |
| 5075 | else | 5142 | else |
| 5076 | count = retcount; | 5143 | count = retcount; |
| @@ -5081,12 +5148,21 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 5081 | /* Attempt to handle failure. */ | 5148 | /* Attempt to handle failure. */ |
| 5082 | if (count < 0) | 5149 | if (count < 0) |
| 5083 | { | 5150 | { |
| 5151 | /* SNPRINTF or sprintf failed. Save and use the errno | ||
| 5152 | that it has set, if any. */ | ||
| 5153 | int saved_errno = errno; | ||
| 5154 | |||
| 5084 | if (!(result == resultbuf || result == NULL)) | 5155 | if (!(result == resultbuf || result == NULL)) |
| 5085 | free (result); | 5156 | free (result); |
| 5086 | if (buf_malloced != NULL) | 5157 | if (buf_malloced != NULL) |
| 5087 | free (buf_malloced); | 5158 | free (buf_malloced); |
| 5088 | CLEANUP (); | 5159 | CLEANUP (); |
| 5089 | errno = EINVAL; | 5160 | errno = |
| 5161 | (saved_errno != 0 | ||
| 5162 | ? saved_errno | ||
| 5163 | : (dp->conversion == 'c' || dp->conversion == 's' | ||
| 5164 | ? EILSEQ | ||
| 5165 | : EINVAL)); | ||
| 5090 | return NULL; | 5166 | return NULL; |
| 5091 | } | 5167 | } |
| 5092 | 5168 | ||
| @@ -5422,6 +5498,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 5422 | length += count; | 5498 | length += count; |
| 5423 | break; | 5499 | break; |
| 5424 | } | 5500 | } |
| 5501 | #undef pad_ourselves | ||
| 5502 | #undef prec_ourselves | ||
| 5425 | } | 5503 | } |
| 5426 | } | 5504 | } |
| 5427 | } | 5505 | } |
| @@ -5473,6 +5551,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, | |||
| 5473 | } | 5551 | } |
| 5474 | } | 5552 | } |
| 5475 | 5553 | ||
| 5554 | #undef MAX_ROOM_NEEDED | ||
| 5476 | #undef TCHARS_PER_DCHAR | 5555 | #undef TCHARS_PER_DCHAR |
| 5477 | #undef SNPRINTF | 5556 | #undef SNPRINTF |
| 5478 | #undef USE_SNPRINTF | 5557 | #undef USE_SNPRINTF |
diff --git a/gl/verify.h b/gl/verify.h index bcd3f5a0..4ad780c8 100644 --- a/gl/verify.h +++ b/gl/verify.h | |||
| @@ -69,13 +69,14 @@ | |||
| 69 | if the entity names are not disambiguated. A workaround is to | 69 | if the entity names are not disambiguated. A workaround is to |
| 70 | attach the current line number to the entity name: | 70 | attach the current line number to the entity name: |
| 71 | 71 | ||
| 72 | #define GL_CONCAT0(x, y) x##y | 72 | #define _GL_CONCAT0(x, y) x##y |
| 73 | #define GL_CONCAT(x, y) GL_CONCAT0 (x, y) | 73 | #define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y) |
| 74 | extern struct {...} * GL_CONCAT(dummy,__LINE__); | 74 | extern struct {...} * _GL_CONCAT (dummy, __LINE__); |
| 75 | 75 | ||
| 76 | But this has the problem that two invocations of verify from | 76 | But this has the problem that two invocations of verify from |
| 77 | within the same macro would collide, since the __LINE__ value | 77 | within the same macro would collide, since the __LINE__ value |
| 78 | would be the same for both invocations. | 78 | would be the same for both invocations. (The GCC __COUNTER__ |
| 79 | macro solves this problem, but is not portable.) | ||
| 79 | 80 | ||
| 80 | A solution is to use the sizeof operator. It yields a number, | 81 | A solution is to use the sizeof operator. It yields a number, |
| 81 | getting rid of the identity of the type. Declarations like | 82 | getting rid of the identity of the type. Declarations like |
| @@ -103,20 +104,41 @@ | |||
| 103 | 104 | ||
| 104 | extern int (*dummy (void)) [sizeof (struct {...})]; | 105 | extern int (*dummy (void)) [sizeof (struct {...})]; |
| 105 | 106 | ||
| 107 | * GCC warns about duplicate declarations of the dummy function if | ||
| 108 | -Wredundant_decls is used. GCC 4.3 and later have a builtin | ||
| 109 | __COUNTER__ macro that can let us generate unique identifiers for | ||
| 110 | each dummy function, to suppress this warning. | ||
| 111 | |||
| 106 | * This implementation exploits the fact that GCC does not warn about | 112 | * This implementation exploits the fact that GCC does not warn about |
| 107 | the last declaration mentioned above. If a future version of GCC | 113 | the last declaration mentioned above. If a future version of GCC |
| 108 | introduces a warning for this, the problem could be worked around | 114 | introduces a warning for this, the problem could be worked around |
| 109 | by using code specialized to GCC, e.g.,: | 115 | by using code specialized to GCC, just as __COUNTER__ is already |
| 116 | being used if available. | ||
| 110 | 117 | ||
| 111 | #if 4 <= __GNUC__ | 118 | #if 4 <= __GNUC__ |
| 112 | # define verify(R) \ | 119 | # define verify(R) [another version to keep GCC happy] |
| 113 | extern int (* verify_function__ (void)) \ | ||
| 114 | [__builtin_constant_p (R) && (R) ? 1 : -1] | ||
| 115 | #endif | 120 | #endif |
| 116 | 121 | ||
| 117 | * In C++, any struct definition inside sizeof is invalid. | 122 | * In C++, any struct definition inside sizeof is invalid. |
| 118 | Use a template type to work around the problem. */ | 123 | Use a template type to work around the problem. */ |
| 119 | 124 | ||
| 125 | /* Concatenate two preprocessor tokens. */ | ||
| 126 | # define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y) | ||
| 127 | # define _GL_CONCAT0(x, y) x##y | ||
| 128 | |||
| 129 | /* _GL_COUNTER is an integer, preferably one that changes each time we | ||
| 130 | use it. Use __COUNTER__ if it works, falling back on __LINE__ | ||
| 131 | otherwise. __LINE__ isn't perfect, but it's better than a | ||
| 132 | constant. */ | ||
| 133 | # if defined __COUNTER__ && __COUNTER__ != __COUNTER__ | ||
| 134 | # define _GL_COUNTER __COUNTER__ | ||
| 135 | # else | ||
| 136 | # define _GL_COUNTER __LINE__ | ||
| 137 | # endif | ||
| 138 | |||
| 139 | /* Generate a symbol with the given prefix, making it unique if | ||
| 140 | possible. */ | ||
| 141 | # define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) | ||
| 120 | 142 | ||
| 121 | /* Verify requirement R at compile-time, as an integer constant expression. | 143 | /* Verify requirement R at compile-time, as an integer constant expression. |
| 122 | Return 1. */ | 144 | Return 1. */ |
| @@ -135,6 +157,7 @@ template <int w> | |||
| 135 | /* Verify requirement R at compile-time, as a declaration without a | 157 | /* Verify requirement R at compile-time, as a declaration without a |
| 136 | trailing ';'. */ | 158 | trailing ';'. */ |
| 137 | 159 | ||
| 138 | # define verify(R) extern int (* verify_function__ (void)) [verify_true (R)] | 160 | # define verify(R) \ |
| 161 | extern int (* _GL_GENSYM (verify_function) (void)) [verify_true (R)] | ||
| 139 | 162 | ||
| 140 | #endif | 163 | #endif |
diff --git a/gl/wchar.in.h b/gl/wchar.in.h index dd41d353..88d47dbc 100644 --- a/gl/wchar.in.h +++ b/gl/wchar.in.h | |||
| @@ -407,7 +407,7 @@ _GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - " | |||
| 407 | _GL_FUNCDECL_RPL (wcwidth, int, (wchar_t)); | 407 | _GL_FUNCDECL_RPL (wcwidth, int, (wchar_t)); |
| 408 | _GL_CXXALIAS_RPL (wcwidth, int, (wchar_t)); | 408 | _GL_CXXALIAS_RPL (wcwidth, int, (wchar_t)); |
| 409 | # else | 409 | # else |
| 410 | # if !defined wcwidth && !@HAVE_DECL_WCWIDTH@ | 410 | # if !@HAVE_DECL_WCWIDTH@ |
| 411 | /* wcwidth exists but is not declared. */ | 411 | /* wcwidth exists but is not declared. */ |
| 412 | _GL_FUNCDECL_SYS (wcwidth, int, (wchar_t)); | 412 | _GL_FUNCDECL_SYS (wcwidth, int, (wchar_t)); |
| 413 | # endif | 413 | # endif |
diff --git a/lib/Makefile.am b/lib/Makefile.am index 17e4c1b0..99fa591a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
| @@ -4,6 +4,7 @@ SUBDIRS = . tests | |||
| 4 | 4 | ||
| 5 | noinst_LIBRARIES = libnagiosplug.a | 5 | noinst_LIBRARIES = libnagiosplug.a |
| 6 | 6 | ||
| 7 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" | ||
| 7 | 8 | ||
| 8 | libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c | 9 | libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c |
| 9 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h | 10 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h |
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am index 694baf00..06a4b423 100644 --- a/lib/tests/Makefile.am +++ b/lib/tests/Makefile.am | |||
| @@ -5,6 +5,8 @@ noinst_PROGRAMS = @EXTRA_TEST@ | |||
| 5 | TESTS = @EXTRA_TEST@ | 5 | TESTS = @EXTRA_TEST@ |
| 6 | check_PROGRAMS = @EXTRA_TEST@ | 6 | check_PROGRAMS = @EXTRA_TEST@ |
| 7 | 7 | ||
| 8 | AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" | ||
| 9 | |||
| 8 | INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 10 | INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
| 9 | 11 | ||
| 10 | EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3 | 12 | EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3 |
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 3a45944a..53369077 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
| @@ -21,6 +21,11 @@ | |||
| 21 | 21 | ||
| 22 | #include "tap.h" | 22 | #include "tap.h" |
| 23 | 23 | ||
| 24 | #include <sys/types.h> | ||
| 25 | #include <sys/stat.h> | ||
| 26 | |||
| 27 | #include "utils_base.c" | ||
| 28 | |||
| 24 | int | 29 | int |
| 25 | main (int argc, char **argv) | 30 | main (int argc, char **argv) |
| 26 | { | 31 | { |
| @@ -28,8 +33,31 @@ main (int argc, char **argv) | |||
| 28 | double temp; | 33 | double temp; |
| 29 | thresholds *thresholds = NULL; | 34 | thresholds *thresholds = NULL; |
| 30 | int rc; | 35 | int rc; |
| 36 | char *temp_string; | ||
| 37 | state_key *temp_state_key = NULL; | ||
| 38 | state_data *temp_state_data; | ||
| 39 | time_t current_time; | ||
| 40 | char *temp_filename; | ||
| 41 | FILE *temp_fp; | ||
| 42 | |||
| 43 | plan_tests(141); | ||
| 44 | |||
| 45 | ok( this_nagios_plugin==NULL, "nagios_plugin not initialised"); | ||
| 46 | |||
| 47 | np_init( "check_test", argc, argv ); | ||
| 48 | |||
| 49 | ok( this_nagios_plugin!=NULL, "nagios_plugin now initialised"); | ||
| 50 | ok( !strcmp(this_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" ); | ||
| 51 | |||
| 52 | ok( this_nagios_plugin->argc==argc, "Argc set" ); | ||
| 53 | ok( this_nagios_plugin->argv==argv, "Argv set" ); | ||
| 31 | 54 | ||
| 32 | plan_tests(81+23); | 55 | np_set_args(0,0); |
| 56 | |||
| 57 | ok( this_nagios_plugin->argc==0, "argc changed" ); | ||
| 58 | ok( this_nagios_plugin->argv==0, "argv changed" ); | ||
| 59 | |||
| 60 | np_set_args(argc, argv); | ||
| 33 | 61 | ||
| 34 | range = parse_range_string("6"); | 62 | range = parse_range_string("6"); |
| 35 | ok( range != NULL, "'6' is valid range"); | 63 | ok( range != NULL, "'6' is valid range"); |
| @@ -251,5 +279,157 @@ main (int argc, char **argv) | |||
| 251 | test=np_extract_ntpvar("", "foo"); | 279 | test=np_extract_ntpvar("", "foo"); |
| 252 | ok(!test, "Empty string return NULL"); | 280 | ok(!test, "Empty string return NULL"); |
| 253 | 281 | ||
| 282 | |||
| 283 | /* This is the result of running ./test_utils */ | ||
| 284 | temp_string = (char *) _np_state_generate_key(); | ||
| 285 | ok(!strcmp(temp_string, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got hash with exe and no parameters" ) || | ||
| 286 | diag( "You are probably running in wrong directory. Must run as ./test_utils" ); | ||
| 287 | |||
| 288 | |||
| 289 | this_nagios_plugin->argc=4; | ||
| 290 | this_nagios_plugin->argv[0] = "./test_utils"; | ||
| 291 | this_nagios_plugin->argv[1] = "here"; | ||
| 292 | this_nagios_plugin->argv[2] = "--and"; | ||
| 293 | this_nagios_plugin->argv[3] = "now"; | ||
| 294 | temp_string = (char *) _np_state_generate_key(); | ||
| 295 | ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" ); | ||
| 296 | |||
| 297 | unsetenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); | ||
| 298 | temp_string = (char *) _np_state_calculate_location_prefix(); | ||
| 299 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" ); | ||
| 300 | |||
| 301 | setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "", 1); | ||
| 302 | temp_string = (char *) _np_state_calculate_location_prefix(); | ||
| 303 | ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" ); | ||
| 304 | |||
| 305 | setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "/usr/local/nagios/var", 1); | ||
| 306 | temp_string = (char *) _np_state_calculate_location_prefix(); | ||
| 307 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" ); | ||
| 308 | |||
| 309 | |||
| 310 | |||
| 311 | ok(temp_state_key==NULL, "temp_state_key initially empty"); | ||
| 312 | |||
| 313 | this_nagios_plugin->argc=1; | ||
| 314 | this_nagios_plugin->argv[0] = "./test_utils"; | ||
| 315 | np_enable_state(NULL, 51); | ||
| 316 | temp_state_key = this_nagios_plugin->state; | ||
| 317 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | ||
| 318 | ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); | ||
| 319 | |||
| 320 | |||
| 321 | np_enable_state("allowedchars_in_keyname", 77); | ||
| 322 | temp_state_key = this_nagios_plugin->state; | ||
| 323 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | ||
| 324 | ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" ); | ||
| 325 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" ); | ||
| 326 | |||
| 327 | |||
| 328 | /* Don't do this test just yet. Will die */ | ||
| 329 | /* | ||
| 330 | np_enable_state("bad^chars$in@here", 77); | ||
| 331 | temp_state_key = this_nagios_plugin->state; | ||
| 332 | ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" ); | ||
| 333 | */ | ||
| 334 | |||
| 335 | np_enable_state("funnykeyname", 54); | ||
| 336 | temp_state_key = this_nagios_plugin->state; | ||
| 337 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | ||
| 338 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); | ||
| 339 | |||
| 340 | |||
| 341 | |||
| 342 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/funnykeyname"), "Got internal filename" ); | ||
| 343 | ok( temp_state_key->data_version==54, "Version set" ); | ||
| 344 | |||
| 345 | temp_state_data = np_state_read(temp_state_key); | ||
| 346 | ok( temp_state_data==NULL, "Got no state data as file does not exist" ); | ||
| 347 | |||
| 348 | |||
| 349 | /* | ||
| 350 | temp_fp = fopen("var/statefile", "r"); | ||
| 351 | if (temp_fp==NULL) | ||
| 352 | printf("Error opening. errno=%d\n", errno); | ||
| 353 | printf("temp_fp=%s\n", temp_fp); | ||
| 354 | ok( _np_state_read_file(temp_fp) == TRUE, "Can read state file" ); | ||
| 355 | fclose(temp_fp); | ||
| 356 | */ | ||
| 357 | |||
| 358 | temp_state_key->_filename="var/statefile"; | ||
| 359 | temp_state_data = np_state_read(temp_state_key); | ||
| 360 | ok( this_nagios_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not"); | ||
| 361 | ok( this_nagios_plugin->state->state_data->time==1234567890, "Got time" ); | ||
| 362 | ok( !strcmp((char *)this_nagios_plugin->state->state_data->data, "String to read"), "Data as expected" ); | ||
| 363 | |||
| 364 | temp_state_key->data_version=53; | ||
| 365 | temp_state_data = np_state_read(temp_state_key); | ||
| 366 | ok( temp_state_data==NULL, "Older data version gives NULL" ); | ||
| 367 | temp_state_key->data_version=54; | ||
| 368 | |||
| 369 | temp_state_key->_filename="var/nonexistant"; | ||
| 370 | temp_state_data = np_state_read(temp_state_key); | ||
| 371 | ok( temp_state_data==NULL, "Missing file gives NULL" ); | ||
| 372 | ok( this_nagios_plugin->state->state_data==NULL, "No state information" ); | ||
| 373 | |||
| 374 | temp_state_key->_filename="var/oldformat"; | ||
| 375 | temp_state_data = np_state_read(temp_state_key); | ||
| 376 | ok( temp_state_data==NULL, "Old file format gives NULL" ); | ||
| 377 | |||
| 378 | temp_state_key->_filename="var/baddate"; | ||
| 379 | temp_state_data = np_state_read(temp_state_key); | ||
| 380 | ok( temp_state_data==NULL, "Bad date gives NULL" ); | ||
| 381 | |||
| 382 | temp_state_key->_filename="var/missingdataline"; | ||
| 383 | temp_state_data = np_state_read(temp_state_key); | ||
| 384 | ok( temp_state_data==NULL, "Missing data line gives NULL" ); | ||
| 385 | |||
| 386 | |||
| 387 | |||
| 388 | |||
| 389 | unlink("var/generated"); | ||
| 390 | temp_state_key->_filename="var/generated"; | ||
| 391 | current_time=1234567890; | ||
| 392 | np_state_write_string(current_time, "String to read"); | ||
| 393 | ok(system("cmp var/generated var/statefile")==0, "Generated file same as expected"); | ||
| 394 | |||
| 395 | |||
| 396 | |||
| 397 | |||
| 398 | unlink("var/generated_directory/statefile"); | ||
| 399 | unlink("var/generated_directory"); | ||
| 400 | temp_state_key->_filename="var/generated_directory/statefile"; | ||
| 401 | current_time=1234567890; | ||
| 402 | np_state_write_string(current_time, "String to read"); | ||
| 403 | ok(system("cmp var/generated_directory/statefile var/statefile")==0, "Have created directory"); | ||
| 404 | |||
| 405 | /* This test to check cannot write to dir - can't automate yet */ | ||
| 406 | /* | ||
| 407 | unlink("var/generated_bad_dir"); | ||
| 408 | mkdir("var/generated_bad_dir", S_IRUSR); | ||
| 409 | np_state_write_string(current_time, "String to read"); | ||
| 410 | */ | ||
| 411 | |||
| 412 | |||
| 413 | temp_state_key->_filename="var/generated"; | ||
| 414 | time(¤t_time); | ||
| 415 | np_state_write_string(0, "String to read"); | ||
| 416 | temp_state_data = np_state_read(temp_state_key); | ||
| 417 | /* Check time is set to current_time */ | ||
| 418 | ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); | ||
| 419 | ok(this_nagios_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); | ||
| 420 | |||
| 421 | |||
| 422 | /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ | ||
| 423 | /* | ||
| 424 | temp_state_key->_filename="/dev/do/not/expect/to/be/able/to/write"; | ||
| 425 | np_state_write_string(0, "Bad file"); | ||
| 426 | */ | ||
| 427 | |||
| 428 | |||
| 429 | np_cleanup(); | ||
| 430 | |||
| 431 | ok( this_nagios_plugin==NULL, "Free'd this_nagios_plugin" ); | ||
| 432 | |||
| 254 | return exit_status(); | 433 | return exit_status(); |
| 255 | } | 434 | } |
| 435 | |||
diff --git a/lib/tests/var/.gitignore b/lib/tests/var/.gitignore new file mode 100644 index 00000000..95a59c17 --- /dev/null +++ b/lib/tests/var/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | generated | ||
| 2 | generated_directory/ | ||
diff --git a/lib/tests/var/baddate b/lib/tests/var/baddate new file mode 100644 index 00000000..2fda432e --- /dev/null +++ b/lib/tests/var/baddate | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # NP State file | ||
| 2 | 1 | ||
| 3 | 54 | ||
| 4 | 2147483647 | ||
| 5 | Date in future!!!! | ||
diff --git a/lib/tests/var/missingdataline b/lib/tests/var/missingdataline new file mode 100644 index 00000000..d87f73aa --- /dev/null +++ b/lib/tests/var/missingdataline | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | # NP State file | ||
| 2 | 1 | ||
| 3 | 54 | ||
| 4 | 1234567890 | ||
diff --git a/lib/tests/var/oldformat b/lib/tests/var/oldformat new file mode 100644 index 00000000..102f8c9f --- /dev/null +++ b/lib/tests/var/oldformat | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # NP State file | ||
| 2 | 0 | ||
| 3 | 54 | ||
| 4 | 1234567890 | ||
| 5 | String to read | ||
diff --git a/lib/tests/var/statefile b/lib/tests/var/statefile new file mode 100644 index 00000000..5002139c --- /dev/null +++ b/lib/tests/var/statefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | # NP State file | ||
| 2 | 1 | ||
| 3 | 54 | ||
| 4 | 1234567890 | ||
| 5 | String to read | ||
diff --git a/lib/utils_base.c b/lib/utils_base.c index 4303e159..6de92cbd 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
| @@ -27,6 +27,56 @@ | |||
| 27 | #include "common.h" | 27 | #include "common.h" |
| 28 | #include <stdarg.h> | 28 | #include <stdarg.h> |
| 29 | #include "utils_base.h" | 29 | #include "utils_base.h" |
| 30 | #include <fcntl.h> | ||
| 31 | |||
| 32 | #define np_free(ptr) { if(ptr) { free(ptr); ptr = NULL; } } | ||
| 33 | |||
| 34 | nagios_plugin *this_nagios_plugin=NULL; | ||
| 35 | |||
| 36 | void np_init( char *plugin_name, int argc, char **argv ) { | ||
| 37 | if (this_nagios_plugin==NULL) { | ||
| 38 | this_nagios_plugin = malloc(sizeof(nagios_plugin)); | ||
| 39 | if (this_nagios_plugin==NULL) { | ||
| 40 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | ||
| 41 | strerror(errno)); | ||
| 42 | } | ||
| 43 | this_nagios_plugin->plugin_name = strdup(plugin_name); | ||
| 44 | if (this_nagios_plugin->plugin_name==NULL) | ||
| 45 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | ||
| 46 | this_nagios_plugin->argc = argc; | ||
| 47 | this_nagios_plugin->argv = argv; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | void np_set_args( int argc, char **argv ) { | ||
| 52 | if (this_nagios_plugin==NULL) | ||
| 53 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | ||
| 54 | |||
| 55 | this_nagios_plugin->argc = argc; | ||
| 56 | this_nagios_plugin->argv = argv; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | void np_cleanup() { | ||
| 61 | if (this_nagios_plugin!=NULL) { | ||
| 62 | if(this_nagios_plugin->state!=NULL) { | ||
| 63 | if(this_nagios_plugin->state->state_data) { | ||
| 64 | np_free(this_nagios_plugin->state->state_data->data); | ||
| 65 | np_free(this_nagios_plugin->state->state_data); | ||
| 66 | } | ||
| 67 | np_free(this_nagios_plugin->state->name); | ||
| 68 | np_free(this_nagios_plugin->state); | ||
| 69 | } | ||
| 70 | np_free(this_nagios_plugin->plugin_name); | ||
| 71 | np_free(this_nagios_plugin); | ||
| 72 | } | ||
| 73 | this_nagios_plugin=NULL; | ||
| 74 | } | ||
| 75 | |||
| 76 | /* Hidden function to get a pointer to this_nagios_plugin for testing */ | ||
| 77 | void _get_nagios_plugin( nagios_plugin **pointer ){ | ||
| 78 | *pointer = this_nagios_plugin; | ||
| 79 | } | ||
| 30 | 80 | ||
| 31 | void | 81 | void |
| 32 | die (int result, const char *fmt, ...) | 82 | die (int result, const char *fmt, ...) |
| @@ -35,6 +85,9 @@ die (int result, const char *fmt, ...) | |||
| 35 | va_start (ap, fmt); | 85 | va_start (ap, fmt); |
| 36 | vprintf (fmt, ap); | 86 | vprintf (fmt, ap); |
| 37 | va_end (ap); | 87 | va_end (ap); |
| 88 | if(this_nagios_plugin!=NULL) { | ||
| 89 | np_cleanup(); | ||
| 90 | } | ||
| 38 | exit (result); | 91 | exit (result); |
| 39 | } | 92 | } |
| 40 | 93 | ||
| @@ -102,7 +155,7 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st | |||
| 102 | thresholds *temp_thresholds = NULL; | 155 | thresholds *temp_thresholds = NULL; |
| 103 | 156 | ||
| 104 | if ((temp_thresholds = malloc(sizeof(thresholds))) == NULL) | 157 | if ((temp_thresholds = malloc(sizeof(thresholds))) == NULL) |
| 105 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s\n"), | 158 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), |
| 106 | strerror(errno)); | 159 | strerror(errno)); |
| 107 | 160 | ||
| 108 | temp_thresholds->warning = NULL; | 161 | temp_thresholds->warning = NULL; |
| @@ -310,3 +363,302 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { | |||
| 310 | return value; | 363 | return value; |
| 311 | } | 364 | } |
| 312 | 365 | ||
| 366 | /* | ||
| 367 | * Returns a string to use as a keyname, based on an md5 hash of argv, thus | ||
| 368 | * hopefully a unique key per service/plugin invocation. Use the extra-opts | ||
| 369 | * parse of argv, so that uniqueness in parameters are reflected there. | ||
| 370 | */ | ||
| 371 | char *_np_state_generate_key() { | ||
| 372 | struct sha1_ctx ctx; | ||
| 373 | int i; | ||
| 374 | char **argv = this_nagios_plugin->argv; | ||
| 375 | unsigned char result[20]; | ||
| 376 | char keyname[41]; | ||
| 377 | char *p=NULL; | ||
| 378 | |||
| 379 | sha1_init_ctx(&ctx); | ||
| 380 | |||
| 381 | for(i=0; i<this_nagios_plugin->argc; i++) { | ||
| 382 | sha1_process_bytes(argv[i], strlen(argv[i]), &ctx); | ||
| 383 | } | ||
| 384 | |||
| 385 | sha1_finish_ctx(&ctx, &result); | ||
| 386 | |||
| 387 | for (i=0; i<20; ++i) { | ||
| 388 | sprintf(&keyname[2*i], "%02x", result[i]); | ||
| 389 | } | ||
| 390 | keyname[40]='\0'; | ||
| 391 | |||
| 392 | p = strdup(keyname); | ||
| 393 | if(p==NULL) { | ||
| 394 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | ||
| 395 | } | ||
| 396 | return p; | ||
| 397 | } | ||
| 398 | |||
| 399 | void _cleanup_state_data() { | ||
| 400 | if (this_nagios_plugin->state->state_data!=NULL) { | ||
| 401 | np_free(this_nagios_plugin->state->state_data->data); | ||
| 402 | np_free(this_nagios_plugin->state->state_data); | ||
| 403 | } | ||
| 404 | } | ||
| 405 | |||
| 406 | /* | ||
| 407 | * Internal function. Returns either: | ||
| 408 | * envvar NAGIOS_PLUGIN_STATE_DIRECTORY | ||
| 409 | * statically compiled shared state directory | ||
| 410 | */ | ||
| 411 | char* _np_state_calculate_location_prefix(){ | ||
| 412 | char *env_dir; | ||
| 413 | |||
| 414 | env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); | ||
| 415 | if(env_dir && env_dir[0] != '\0') | ||
| 416 | return env_dir; | ||
| 417 | return NP_STATE_DIR_PREFIX; | ||
| 418 | } | ||
| 419 | |||
| 420 | /* | ||
| 421 | * Initiatializer for state routines. | ||
| 422 | * Sets variables. Generates filename. Returns np_state_key. die with | ||
| 423 | * UNKNOWN if exception | ||
| 424 | */ | ||
| 425 | void np_enable_state(char *keyname, int expected_data_version) { | ||
| 426 | state_key *this_state = NULL; | ||
| 427 | char *temp_filename = NULL; | ||
| 428 | char *temp_keyname = NULL; | ||
| 429 | char *p=NULL; | ||
| 430 | |||
| 431 | if(this_nagios_plugin==NULL) | ||
| 432 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | ||
| 433 | |||
| 434 | this_state = (state_key *) malloc(sizeof(state_key)); | ||
| 435 | if(this_state==NULL) | ||
| 436 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | ||
| 437 | strerror(errno)); | ||
| 438 | |||
| 439 | if(keyname==NULL) { | ||
| 440 | temp_keyname = _np_state_generate_key(); | ||
| 441 | } else { | ||
| 442 | temp_keyname = strdup(keyname); | ||
| 443 | if(temp_keyname==NULL) | ||
| 444 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | ||
| 445 | } | ||
| 446 | /* Die if invalid characters used for keyname */ | ||
| 447 | p = temp_keyname; | ||
| 448 | while(*p!='\0') { | ||
| 449 | if(! (isalnum(*p) || *p == '_')) { | ||
| 450 | die(STATE_UNKNOWN, _("Invalid character for keyname - only alphanumerics or '_'")); | ||
| 451 | } | ||
| 452 | p++; | ||
| 453 | } | ||
| 454 | this_state->name=temp_keyname; | ||
| 455 | this_state->plugin_name=this_nagios_plugin->plugin_name; | ||
| 456 | this_state->data_version=expected_data_version; | ||
| 457 | this_state->state_data=NULL; | ||
| 458 | |||
| 459 | /* Calculate filename */ | ||
| 460 | asprintf(&temp_filename, "%s/%s/%s", _np_state_calculate_location_prefix(), this_nagios_plugin->plugin_name, this_state->name); | ||
| 461 | this_state->_filename=temp_filename; | ||
| 462 | |||
| 463 | this_nagios_plugin->state = this_state; | ||
| 464 | } | ||
| 465 | |||
| 466 | /* | ||
| 467 | * Will return NULL if no data is available (first run). If key currently | ||
| 468 | * exists, read data. If state file format version is not expected, return | ||
| 469 | * as if no data. Get state data version number and compares to expected. | ||
| 470 | * If numerically lower, then return as no previous state. die with UNKNOWN | ||
| 471 | * if exceptional error. | ||
| 472 | */ | ||
| 473 | state_data *np_state_read() { | ||
| 474 | state_key *my_state_key; | ||
| 475 | state_data *this_state_data=NULL; | ||
| 476 | FILE *statefile; | ||
| 477 | int c; | ||
| 478 | int rc = FALSE; | ||
| 479 | |||
| 480 | if(this_nagios_plugin==NULL) | ||
| 481 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | ||
| 482 | |||
| 483 | /* Open file. If this fails, no previous state found */ | ||
| 484 | statefile = fopen( this_nagios_plugin->state->_filename, "r" ); | ||
| 485 | if(statefile!=NULL) { | ||
| 486 | |||
| 487 | this_state_data = (state_data *) malloc(sizeof(state_data)); | ||
| 488 | if(this_state_data==NULL) | ||
| 489 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | ||
| 490 | strerror(errno)); | ||
| 491 | |||
| 492 | this_state_data->data=NULL; | ||
| 493 | this_nagios_plugin->state->state_data = this_state_data; | ||
| 494 | |||
| 495 | rc = _np_state_read_file(statefile); | ||
| 496 | |||
| 497 | fclose(statefile); | ||
| 498 | } | ||
| 499 | |||
| 500 | if(rc==FALSE) { | ||
| 501 | _cleanup_state_data(); | ||
| 502 | } | ||
| 503 | |||
| 504 | return this_nagios_plugin->state->state_data; | ||
| 505 | } | ||
| 506 | |||
| 507 | /* | ||
| 508 | * Read the state file | ||
| 509 | */ | ||
| 510 | int _np_state_read_file(FILE *f) { | ||
| 511 | int c, status=FALSE; | ||
| 512 | size_t pos; | ||
| 513 | char *line; | ||
| 514 | int i; | ||
| 515 | int failure=0; | ||
| 516 | time_t current_time, data_time; | ||
| 517 | enum { STATE_FILE_VERSION, STATE_DATA_VERSION, STATE_DATA_TIME, STATE_DATA_TEXT, STATE_DATA_END } expected=STATE_FILE_VERSION; | ||
| 518 | |||
| 519 | time(¤t_time); | ||
| 520 | |||
| 521 | /* Note: This introduces a limit of 1024 bytes in the string data */ | ||
| 522 | line = (char *) malloc(1024); | ||
| 523 | if(line==NULL) | ||
| 524 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | ||
| 525 | strerror(errno)); | ||
| 526 | |||
| 527 | while(!failure && (fgets(line,1024,f))!=NULL){ | ||
| 528 | pos=strlen(line); | ||
| 529 | if(line[pos-1]=='\n') { | ||
| 530 | line[pos-1]='\0'; | ||
| 531 | } | ||
| 532 | |||
| 533 | if(line[0] == '#') continue; | ||
| 534 | |||
| 535 | switch(expected) { | ||
| 536 | case STATE_FILE_VERSION: | ||
| 537 | i=atoi(line); | ||
| 538 | if(i!=NP_STATE_FORMAT_VERSION) | ||
| 539 | failure++; | ||
| 540 | else | ||
| 541 | expected=STATE_DATA_VERSION; | ||
| 542 | break; | ||
| 543 | case STATE_DATA_VERSION: | ||
| 544 | i=atoi(line); | ||
| 545 | if(i != this_nagios_plugin->state->data_version) | ||
| 546 | failure++; | ||
| 547 | else | ||
| 548 | expected=STATE_DATA_TIME; | ||
| 549 | break; | ||
| 550 | case STATE_DATA_TIME: | ||
| 551 | /* If time > now, error */ | ||
| 552 | data_time=strtoul(line,NULL,10); | ||
| 553 | if(data_time > current_time) | ||
| 554 | failure++; | ||
| 555 | else { | ||
| 556 | this_nagios_plugin->state->state_data->time = data_time; | ||
| 557 | expected=STATE_DATA_TEXT; | ||
| 558 | } | ||
| 559 | break; | ||
| 560 | case STATE_DATA_TEXT: | ||
| 561 | this_nagios_plugin->state->state_data->data = strdup(line); | ||
| 562 | if(this_nagios_plugin->state->state_data->data==NULL) | ||
| 563 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | ||
| 564 | expected=STATE_DATA_END; | ||
| 565 | status=TRUE; | ||
| 566 | break; | ||
| 567 | case STATE_DATA_END: | ||
| 568 | ; | ||
| 569 | } | ||
| 570 | } | ||
| 571 | |||
| 572 | np_free(line); | ||
| 573 | return status; | ||
| 574 | } | ||
| 575 | |||
| 576 | /* | ||
| 577 | * If time=NULL, use current time. Create state file, with state format | ||
| 578 | * version, default text. Writes version, time, and data. Avoid locking | ||
| 579 | * problems - use mv to write and then swap. Possible loss of state data if | ||
| 580 | * two things writing to same key at same time. | ||
| 581 | * Will die with UNKNOWN if errors | ||
| 582 | */ | ||
| 583 | void np_state_write_string(time_t data_time, char *data_string) { | ||
| 584 | FILE *fp; | ||
| 585 | char *temp_file=NULL; | ||
| 586 | int fd=0, result=0; | ||
| 587 | time_t current_time; | ||
| 588 | size_t len; | ||
| 589 | char *directories=NULL; | ||
| 590 | char *p=NULL; | ||
| 591 | |||
| 592 | if(data_time==0) | ||
| 593 | time(¤t_time); | ||
| 594 | else | ||
| 595 | current_time=data_time; | ||
| 596 | |||
| 597 | /* If file doesn't currently exist, create directories */ | ||
| 598 | if(access(this_nagios_plugin->state->_filename,F_OK)!=0) { | ||
| 599 | asprintf(&directories, "%s", this_nagios_plugin->state->_filename); | ||
| 600 | if(directories==NULL) | ||
| 601 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | ||
| 602 | strerror(errno)); | ||
| 603 | |||
| 604 | for(p=directories+1; *p; p++) { | ||
| 605 | if(*p=='/') { | ||
| 606 | *p='\0'; | ||
| 607 | if((access(directories,F_OK)!=0) && (mkdir(directories, S_IRWXU)!=0)) { | ||
| 608 | /* Can't free this! Otherwise error message is wrong! */ | ||
| 609 | /* np_free(directories); */ | ||
| 610 | die(STATE_UNKNOWN, _("Cannot create directory: %s"), directories); | ||
| 611 | } | ||
| 612 | *p='/'; | ||
| 613 | } | ||
| 614 | } | ||
| 615 | np_free(directories); | ||
| 616 | } | ||
| 617 | |||
| 618 | asprintf(&temp_file,"%s.XXXXXX",this_nagios_plugin->state->_filename); | ||
| 619 | if(temp_file==NULL) | ||
| 620 | die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), | ||
| 621 | strerror(errno)); | ||
| 622 | |||
| 623 | if((fd=mkstemp(temp_file))==-1) { | ||
| 624 | np_free(temp_file); | ||
| 625 | die(STATE_UNKNOWN, _("Cannot create temporary filename")); | ||
| 626 | } | ||
| 627 | |||
| 628 | fp=(FILE *)fdopen(fd,"w"); | ||
| 629 | if(fp==NULL) { | ||
| 630 | close(fd); | ||
| 631 | unlink(temp_file); | ||
| 632 | np_free(temp_file); | ||
| 633 | die(STATE_UNKNOWN, _("Unable to open temporary state file")); | ||
| 634 | } | ||
| 635 | |||
| 636 | fprintf(fp,"# NP State file\n"); | ||
| 637 | fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION); | ||
| 638 | fprintf(fp,"%d\n",this_nagios_plugin->state->data_version); | ||
| 639 | fprintf(fp,"%lu\n",current_time); | ||
| 640 | fprintf(fp,"%s\n",data_string); | ||
| 641 | |||
| 642 | fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP); | ||
| 643 | |||
| 644 | fflush(fp); | ||
| 645 | |||
| 646 | result=fclose(fp); | ||
| 647 | |||
| 648 | fsync(fd); | ||
| 649 | |||
| 650 | if(result!=0) { | ||
| 651 | unlink(temp_file); | ||
| 652 | np_free(temp_file); | ||
| 653 | die(STATE_UNKNOWN, _("Error writing temp file")); | ||
| 654 | } | ||
| 655 | |||
| 656 | if(rename(temp_file, this_nagios_plugin->state->_filename)!=0) { | ||
| 657 | unlink(temp_file); | ||
| 658 | np_free(temp_file); | ||
| 659 | die(STATE_UNKNOWN, _("Cannot rename state temp file")); | ||
| 660 | } | ||
| 661 | |||
| 662 | np_free(temp_file); | ||
| 663 | } | ||
| 664 | |||
diff --git a/lib/utils_base.h b/lib/utils_base.h index 49e40a63..0cb371fd 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | #define _UTILS_BASE_ | 2 | #define _UTILS_BASE_ |
| 3 | /* Header file for nagios plugins utils_base.c */ | 3 | /* Header file for nagios plugins utils_base.c */ |
| 4 | 4 | ||
| 5 | #include "sha1.h" | ||
| 6 | |||
| 5 | /* This file holds header information for thresholds - use this in preference to | 7 | /* This file holds header information for thresholds - use this in preference to |
| 6 | individual plugin logic */ | 8 | individual plugin logic */ |
| 7 | 9 | ||
| @@ -28,6 +30,30 @@ typedef struct thresholds_struct { | |||
| 28 | range *critical; | 30 | range *critical; |
| 29 | } thresholds; | 31 | } thresholds; |
| 30 | 32 | ||
| 33 | #define NP_STATE_FORMAT_VERSION 1 | ||
| 34 | |||
| 35 | typedef struct state_data_struct { | ||
| 36 | time_t time; | ||
| 37 | void *data; | ||
| 38 | int length; /* Of binary data */ | ||
| 39 | } state_data; | ||
| 40 | |||
| 41 | |||
| 42 | typedef struct state_key_struct { | ||
| 43 | char *name; | ||
| 44 | char *plugin_name; | ||
| 45 | int data_version; | ||
| 46 | char *_filename; | ||
| 47 | state_data *state_data; | ||
| 48 | } state_key; | ||
| 49 | |||
| 50 | typedef struct np_struct { | ||
| 51 | char *plugin_name; | ||
| 52 | state_key *state; | ||
| 53 | int argc; | ||
| 54 | char **argv; | ||
| 55 | } nagios_plugin; | ||
| 56 | |||
| 31 | range *parse_range_string (char *); | 57 | range *parse_range_string (char *); |
| 32 | int _set_thresholds(thresholds **, char *, char *); | 58 | int _set_thresholds(thresholds **, char *, char *); |
| 33 | void set_thresholds(thresholds **, char *, char *); | 59 | void set_thresholds(thresholds **, char *, char *); |
| @@ -67,4 +93,13 @@ char *np_extract_value(const char*, const char*, char); | |||
| 67 | */ | 93 | */ |
| 68 | #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',') | 94 | #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',') |
| 69 | 95 | ||
| 96 | |||
| 97 | void np_enable_state(char *, int); | ||
| 98 | state_data *np_state_read(); | ||
| 99 | void np_state_write_string(time_t, char *); | ||
| 100 | |||
| 101 | void np_init(char *, int argc, char **argv); | ||
| 102 | void np_set_args(int argc, char **argv); | ||
| 103 | void np_cleanup(); | ||
| 104 | |||
| 70 | #endif /* _UTILS_BASE_ */ | 105 | #endif /* _UTILS_BASE_ */ |
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 4570fb7a..36a28b0b 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
| @@ -39,7 +39,7 @@ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ | |||
| 39 | check_nagios check_by_ssh check_dns check_nt check_ide_smart \ | 39 | check_nagios check_by_ssh check_dns check_nt check_ide_smart \ |
| 40 | check_procs check_mysql_query check_apt | 40 | check_procs check_mysql_query check_apt |
| 41 | 41 | ||
| 42 | EXTRA_DIST = t utils.c netutils.c sslutils.c popen.c utils.h netutils.h \ | 42 | EXTRA_DIST = t tests utils.c netutils.c sslutils.c popen.c utils.h netutils.h \ |
| 43 | popen.h common.h runcmd.c runcmd.h | 43 | popen.h common.h runcmd.c runcmd.h |
| 44 | 44 | ||
| 45 | PLUGINHDRS = common.h | 45 | PLUGINHDRS = common.h |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 2bc6024f..bf210222 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -59,6 +59,10 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
| 59 | 59 | ||
| 60 | #define MAX_OIDS 8 | 60 | #define MAX_OIDS 8 |
| 61 | 61 | ||
| 62 | /* Longopts only arguments */ | ||
| 63 | #define L_CALCULATE_RATE CHAR_MAX+1 | ||
| 64 | #define L_RATE_MULTIPLIER CHAR_MAX+2 | ||
| 65 | |||
| 62 | /* Gobble to string - stop incrementing c when c[0] match one of the | 66 | /* Gobble to string - stop incrementing c when c[0] match one of the |
| 63 | * characters in s */ | 67 | * characters in s */ |
| 64 | #define GOBBLE_TOS(c, s) while(c[0]!='\0' && strchr(s, c[0])==NULL) { c++; } | 68 | #define GOBBLE_TOS(c, s) while(c[0]!='\0' && strchr(s, c[0])==NULL) { c++; } |
| @@ -131,12 +135,16 @@ char *delimiter; | |||
| 131 | char *output_delim; | 135 | char *output_delim; |
| 132 | char *miblist = NULL; | 136 | char *miblist = NULL; |
| 133 | int needmibs = FALSE; | 137 | int needmibs = FALSE; |
| 138 | int calculate_rate = 0; | ||
| 139 | int rate_multiplier = 1; | ||
| 140 | state_data *previous_state; | ||
| 141 | double previous_value[MAX_OIDS]; | ||
| 134 | 142 | ||
| 135 | 143 | ||
| 136 | int | 144 | int |
| 137 | main (int argc, char **argv) | 145 | main (int argc, char **argv) |
| 138 | { | 146 | { |
| 139 | int i, len, line; | 147 | int i, len, line, total_oids; |
| 140 | unsigned int bk_count = 0, dq_count = 0; | 148 | unsigned int bk_count = 0, dq_count = 0; |
| 141 | int iresult = STATE_UNKNOWN; | 149 | int iresult = STATE_UNKNOWN; |
| 142 | int result = STATE_UNKNOWN; | 150 | int result = STATE_UNKNOWN; |
| @@ -154,6 +162,17 @@ main (int argc, char **argv) | |||
| 154 | char *th_crit=NULL; | 162 | char *th_crit=NULL; |
| 155 | char type[8] = ""; | 163 | char type[8] = ""; |
| 156 | output chld_out, chld_err; | 164 | output chld_out, chld_err; |
| 165 | char *previous_string=NULL; | ||
| 166 | char *ap=NULL; | ||
| 167 | char *state_string=NULL; | ||
| 168 | size_t response_length, current_length, string_length; | ||
| 169 | char *temp_string=NULL; | ||
| 170 | int is_numeric=0; | ||
| 171 | time_t current_time; | ||
| 172 | double temp_double; | ||
| 173 | time_t duration; | ||
| 174 | char *conv = "12345678"; | ||
| 175 | int is_counter=0; | ||
| 157 | 176 | ||
| 158 | setlocale (LC_ALL, ""); | 177 | setlocale (LC_ALL, ""); |
| 159 | bindtextdomain (PACKAGE, LOCALEDIR); | 178 | bindtextdomain (PACKAGE, LOCALEDIR); |
| @@ -173,12 +192,33 @@ main (int argc, char **argv) | |||
| 173 | timeout_interval = DEFAULT_TIMEOUT; | 192 | timeout_interval = DEFAULT_TIMEOUT; |
| 174 | retries = DEFAULT_RETRIES; | 193 | retries = DEFAULT_RETRIES; |
| 175 | 194 | ||
| 195 | np_init( (char *) progname, argc, argv ); | ||
| 196 | |||
| 176 | /* Parse extra opts if any */ | 197 | /* Parse extra opts if any */ |
| 177 | argv=np_extra_opts (&argc, argv, progname); | 198 | argv=np_extra_opts (&argc, argv, progname); |
| 178 | 199 | ||
| 200 | np_set_args(argc, argv); | ||
| 201 | |||
| 179 | if (process_arguments (argc, argv) == ERROR) | 202 | if (process_arguments (argc, argv) == ERROR) |
| 180 | usage4 (_("Could not parse arguments")); | 203 | usage4 (_("Could not parse arguments")); |
| 181 | 204 | ||
| 205 | if(calculate_rate) { | ||
| 206 | if (!strcmp(label, "SNMP")) | ||
| 207 | label = strdup("SNMP RATE"); | ||
| 208 | time(¤t_time); | ||
| 209 | i=0; | ||
| 210 | previous_state = np_state_read(); | ||
| 211 | if(previous_state!=NULL) { | ||
| 212 | /* Split colon separated values */ | ||
| 213 | previous_string = strdup((char *) previous_state->data); | ||
| 214 | while((ap = strsep(&previous_string, ":")) != NULL) { | ||
| 215 | if(verbose>2) | ||
| 216 | printf("State for %d=%s\n", i, ap); | ||
| 217 | previous_value[i++]=strtod(ap,NULL); | ||
| 218 | } | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 182 | /* Populate the thresholds */ | 222 | /* Populate the thresholds */ |
| 183 | th_warn=warning_thresholds; | 223 | th_warn=warning_thresholds; |
| 184 | th_crit=critical_thresholds; | 224 | th_crit=critical_thresholds; |
| @@ -271,7 +311,10 @@ main (int argc, char **argv) | |||
| 271 | } | 311 | } |
| 272 | 312 | ||
| 273 | for (line=0, i=0; line < chld_out.lines; line++, i++) { | 313 | for (line=0, i=0; line < chld_out.lines; line++, i++) { |
| 274 | const char *conv = "%.0f"; | 314 | if(calculate_rate) |
| 315 | conv = "%.10g"; | ||
| 316 | else | ||
| 317 | conv = "%.0f"; | ||
| 275 | 318 | ||
| 276 | ptr = chld_out.line[line]; | 319 | ptr = chld_out.line[line]; |
| 277 | oidname = strpcpy (oidname, ptr, delimiter); | 320 | oidname = strpcpy (oidname, ptr, delimiter); |
| @@ -286,21 +329,34 @@ main (int argc, char **argv) | |||
| 286 | /* Clean up type array - Sol10 does not necessarily zero it out */ | 329 | /* Clean up type array - Sol10 does not necessarily zero it out */ |
| 287 | bzero(type, sizeof(type)); | 330 | bzero(type, sizeof(type)); |
| 288 | 331 | ||
| 332 | is_counter=0; | ||
| 289 | /* We strip out the datatype indicator for PHBs */ | 333 | /* We strip out the datatype indicator for PHBs */ |
| 290 | if (strstr (response, "Gauge: ")) | 334 | if (strstr (response, "Gauge: ")) { |
| 291 | show = strstr (response, "Gauge: ") + 7; | 335 | show = strstr (response, "Gauge: ") + 7; |
| 292 | else if (strstr (response, "Gauge32: ")) | 336 | is_numeric++; |
| 337 | } | ||
| 338 | else if (strstr (response, "Gauge32: ")) { | ||
| 293 | show = strstr (response, "Gauge32: ") + 9; | 339 | show = strstr (response, "Gauge32: ") + 9; |
| 340 | is_numeric++; | ||
| 341 | } | ||
| 294 | else if (strstr (response, "Counter32: ")) { | 342 | else if (strstr (response, "Counter32: ")) { |
| 295 | show = strstr (response, "Counter32: ") + 11; | 343 | show = strstr (response, "Counter32: ") + 11; |
| 296 | strcpy(type, "c"); | 344 | is_numeric++; |
| 345 | is_counter=1; | ||
| 346 | if(!calculate_rate) | ||
| 347 | strcpy(type, "c"); | ||
| 297 | } | 348 | } |
| 298 | else if (strstr (response, "Counter64: ")) { | 349 | else if (strstr (response, "Counter64: ")) { |
| 299 | show = strstr (response, "Counter64: ") + 11; | 350 | show = strstr (response, "Counter64: ") + 11; |
| 300 | strcpy(type, "c"); | 351 | is_numeric++; |
| 352 | is_counter=1; | ||
| 353 | if(!calculate_rate) | ||
| 354 | strcpy(type, "c"); | ||
| 301 | } | 355 | } |
| 302 | else if (strstr (response, "INTEGER: ")) | 356 | else if (strstr (response, "INTEGER: ")) { |
| 303 | show = strstr (response, "INTEGER: ") + 9; | 357 | show = strstr (response, "INTEGER: ") + 9; |
| 358 | is_numeric++; | ||
| 359 | } | ||
| 304 | else if (strstr (response, "STRING: ")) { | 360 | else if (strstr (response, "STRING: ")) { |
| 305 | show = strstr (response, "STRING: ") + 8; | 361 | show = strstr (response, "STRING: ") + 8; |
| 306 | conv = "%.10g"; | 362 | conv = "%.10g"; |
| @@ -345,14 +401,33 @@ main (int argc, char **argv) | |||
| 345 | 401 | ||
| 346 | iresult = STATE_DEPENDENT; | 402 | iresult = STATE_DEPENDENT; |
| 347 | 403 | ||
| 348 | /* Process this block for integer comparisons */ | 404 | /* Process this block for numeric comparisons */ |
| 349 | if (thlds[i]->warning || thlds[i]->critical) { | 405 | if (is_numeric) { |
| 350 | ptr = strpbrk (show, "0123456789"); | 406 | ptr = strpbrk (show, "0123456789"); |
| 351 | if (ptr == NULL) | 407 | if (ptr == NULL) |
| 352 | die (STATE_UNKNOWN,_("No valid data returned")); | 408 | die (STATE_UNKNOWN,_("No valid data returned")); |
| 353 | response_value[i] = strtod (ptr, NULL); | 409 | response_value[i] = strtod (ptr, NULL); |
| 354 | iresult = get_status(response_value[i], thlds[i]); | 410 | |
| 355 | asprintf (&show, conv, response_value[i]); | 411 | if(calculate_rate) { |
| 412 | if (previous_state!=NULL) { | ||
| 413 | duration = current_time-previous_state->time; | ||
| 414 | if(duration<=0) | ||
| 415 | die(STATE_UNKNOWN,_("Time duration between plugin calls is invalid")); | ||
| 416 | temp_double = (response_value[i]-previous_value[i])/duration; | ||
| 417 | /* Simple overflow catcher (same as in rrdtool, rrd_update.c) */ | ||
| 418 | if(is_counter) { | ||
| 419 | if(temp_double<(double)0.0) | ||
| 420 | temp_double+=(double)4294967296.0; /* 2^32 */ | ||
| 421 | if(temp_double<(double)0.0) | ||
| 422 | temp_double+=(double)18446744069414584320.0; /* 2^64-2^32 */; | ||
| 423 | } | ||
| 424 | iresult = get_status(temp_double, thlds[i]); | ||
| 425 | asprintf (&show, conv, temp_double); | ||
| 426 | } | ||
| 427 | } else { | ||
| 428 | iresult = get_status(response_value[i], thlds[i]); | ||
| 429 | asprintf (&show, conv, response_value[i]); | ||
| 430 | } | ||
| 356 | } | 431 | } |
| 357 | 432 | ||
| 358 | /* Process this block for string matching */ | 433 | /* Process this block for string matching */ |
| @@ -380,6 +455,7 @@ main (int argc, char **argv) | |||
| 380 | } | 455 | } |
| 381 | 456 | ||
| 382 | /* Process this block for existence-nonexistence checks */ | 457 | /* Process this block for existence-nonexistence checks */ |
| 458 | /* TV: Should this be outside of this else block? */ | ||
| 383 | else { | 459 | else { |
| 384 | if (eval_method[i] & CRIT_PRESENT) | 460 | if (eval_method[i] & CRIT_PRESENT) |
| 385 | iresult = STATE_CRITICAL; | 461 | iresult = STATE_CRITICAL; |
| @@ -393,7 +469,7 @@ main (int argc, char **argv) | |||
| 393 | result = max_state (result, iresult); | 469 | result = max_state (result, iresult); |
| 394 | 470 | ||
| 395 | /* Prepend a label for this OID if there is one */ | 471 | /* Prepend a label for this OID if there is one */ |
| 396 | if (nlabels > (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) | 472 | if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) |
| 397 | asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, | 473 | asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, |
| 398 | (i == 0) ? " " : output_delim, | 474 | (i == 0) ? " " : output_delim, |
| 399 | labels[i], mark (iresult), show, mark (iresult)); | 475 | labels[i], mark (iresult), show, mark (iresult)); |
| @@ -409,7 +485,13 @@ main (int argc, char **argv) | |||
| 409 | ptr = NULL; | 485 | ptr = NULL; |
| 410 | strtod(show, &ptr); | 486 | strtod(show, &ptr); |
| 411 | if (ptr > show) { | 487 | if (ptr > show) { |
| 412 | strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1); | 488 | if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) |
| 489 | temp_string=labels[i]; | ||
| 490 | else | ||
| 491 | temp_string=oidname; | ||
| 492 | if(calculate_rate) | ||
| 493 | asprintf(&temp_string,"%s-rate",temp_string); | ||
| 494 | strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 413 | strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1); | 495 | strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1); |
| 414 | len = sizeof(perfstr)-strlen(perfstr)-1; | 496 | len = sizeof(perfstr)-strlen(perfstr)-1; |
| 415 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); | 497 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); |
| @@ -419,6 +501,44 @@ main (int argc, char **argv) | |||
| 419 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 501 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
| 420 | } | 502 | } |
| 421 | } | 503 | } |
| 504 | total_oids=i; | ||
| 505 | |||
| 506 | /* Save state data, as all data collected now */ | ||
| 507 | if(calculate_rate) { | ||
| 508 | string_length=1024; | ||
| 509 | state_string=malloc(string_length); | ||
| 510 | if(state_string==NULL) | ||
| 511 | die(STATE_UNKNOWN, _("Cannot malloc")); | ||
| 512 | |||
| 513 | current_length=0; | ||
| 514 | for(i=0; i<total_oids; i++) { | ||
| 515 | asprintf(&temp_string,"%.0f",response_value[i]); | ||
| 516 | if(temp_string==NULL) | ||
| 517 | die(STATE_UNKNOWN,_("Cannot asprintf()")); | ||
| 518 | response_length = strlen(temp_string); | ||
| 519 | if(current_length+response_length>string_length) { | ||
| 520 | string_length=current_length+1024; | ||
| 521 | state_string=realloc(state_string,string_length); | ||
| 522 | if(state_string==NULL) | ||
| 523 | die(STATE_UNKNOWN, _("Cannot realloc()")); | ||
| 524 | } | ||
| 525 | strcpy(&state_string[current_length],temp_string); | ||
| 526 | current_length=current_length+response_length; | ||
| 527 | state_string[current_length]=':'; | ||
| 528 | current_length++; | ||
| 529 | free(temp_string); | ||
| 530 | } | ||
| 531 | state_string[--current_length]='\0'; | ||
| 532 | if (verbose > 2) | ||
| 533 | printf("State string=%s\n",state_string); | ||
| 534 | |||
| 535 | /* This is not strictly the same as time now, but any subtle variations will cancel out */ | ||
| 536 | np_state_write_string(current_time, state_string ); | ||
| 537 | if(previous_state==NULL) { | ||
| 538 | /* Or should this be highest state? */ | ||
| 539 | die( STATE_OK, _("No previous data to calculate rate - assume okay" ) ); | ||
| 540 | } | ||
| 541 | } | ||
| 422 | 542 | ||
| 423 | printf ("%s %s -%s %s\n", label, state_text (result), outbuff, perfstr); | 543 | printf ("%s %s -%s %s\n", label, state_text (result), outbuff, perfstr); |
| 424 | if (mult_resp) printf ("%s", mult_resp); | 544 | if (mult_resp) printf ("%s", mult_resp); |
| @@ -462,6 +582,8 @@ process_arguments (int argc, char **argv) | |||
| 462 | {"authpasswd", required_argument, 0, 'A'}, | 582 | {"authpasswd", required_argument, 0, 'A'}, |
| 463 | {"privpasswd", required_argument, 0, 'X'}, | 583 | {"privpasswd", required_argument, 0, 'X'}, |
| 464 | {"next", no_argument, 0, 'n'}, | 584 | {"next", no_argument, 0, 'n'}, |
| 585 | {"rate", no_argument, 0, L_CALCULATE_RATE}, | ||
| 586 | {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, | ||
| 465 | {0, 0, 0, 0} | 587 | {0, 0, 0, 0} |
| 466 | }; | 588 | }; |
| 467 | 589 | ||
| @@ -609,7 +731,6 @@ process_arguments (int argc, char **argv) | |||
| 609 | output_delim = strscpy (output_delim, optarg); | 731 | output_delim = strscpy (output_delim, optarg); |
| 610 | break; | 732 | break; |
| 611 | case 'l': /* label */ | 733 | case 'l': /* label */ |
| 612 | label = optarg; | ||
| 613 | nlabels++; | 734 | nlabels++; |
| 614 | if (nlabels >= labels_size) { | 735 | if (nlabels >= labels_size) { |
| 615 | labels_size += 8; | 736 | labels_size += 8; |
| @@ -666,7 +787,15 @@ process_arguments (int argc, char **argv) | |||
| 666 | unitv[nunits - 1] = ptr; | 787 | unitv[nunits - 1] = ptr; |
| 667 | } | 788 | } |
| 668 | break; | 789 | break; |
| 669 | 790 | case L_CALCULATE_RATE: | |
| 791 | if(calculate_rate==0) | ||
| 792 | np_enable_state(NULL, 1); | ||
| 793 | calculate_rate = 1; | ||
| 794 | break; | ||
| 795 | case L_RATE_MULTIPLIER: | ||
| 796 | if(!is_integer(optarg)||(rate_multiplier=atoi(optarg)<=0)) | ||
| 797 | usage2(_("Rate multiplier must be a positive integer"),optarg); | ||
| 798 | break; | ||
| 670 | } | 799 | } |
| 671 | } | 800 | } |
| 672 | 801 | ||
| @@ -905,6 +1034,8 @@ print_help (void) | |||
| 905 | printf (" %s\n", _("Warning threshold range(s)")); | 1034 | printf (" %s\n", _("Warning threshold range(s)")); |
| 906 | printf (" %s\n", "-c, --critical=THRESHOLD(s)"); | 1035 | printf (" %s\n", "-c, --critical=THRESHOLD(s)"); |
| 907 | printf (" %s\n", _("Critical threshold range(s)")); | 1036 | printf (" %s\n", _("Critical threshold range(s)")); |
| 1037 | printf (" %s\n", "--rate"); | ||
| 1038 | printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); | ||
| 908 | 1039 | ||
| 909 | /* Tests Against Strings */ | 1040 | /* Tests Against Strings */ |
| 910 | printf (" %s\n", "-s, --string=STRING"); | 1041 | printf (" %s\n", "-s, --string=STRING"); |
| @@ -914,7 +1045,7 @@ print_help (void) | |||
| 914 | printf (" %s\n", "-R, --eregi=REGEX"); | 1045 | printf (" %s\n", "-R, --eregi=REGEX"); |
| 915 | printf (" %s\n", _("Return OK state (for that OID) if case-insensitive extended REGEX matches")); | 1046 | printf (" %s\n", _("Return OK state (for that OID) if case-insensitive extended REGEX matches")); |
| 916 | printf (" %s\n", "-l, --label=STRING"); | 1047 | printf (" %s\n", "-l, --label=STRING"); |
| 917 | printf (" %s\n", _("Prefix label for output from plugin (default -s 'SNMP')")); | 1048 | printf (" %s\n", _("Prefix label for output from plugin (default -l 'SNMP')")); |
| 918 | 1049 | ||
| 919 | /* Output Formatting */ | 1050 | /* Output Formatting */ |
| 920 | printf (" %s\n", "-u, --units=STRING"); | 1051 | printf (" %s\n", "-u, --units=STRING"); |
| @@ -945,6 +1076,16 @@ print_help (void) | |||
| 945 | printf (" %s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value")); | 1076 | printf (" %s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value")); |
| 946 | printf (" %s\n", _("returned from the SNMP query is an unsigned integer.")); | 1077 | printf (" %s\n", _("returned from the SNMP query is an unsigned integer.")); |
| 947 | 1078 | ||
| 1079 | printf("\n"); | ||
| 1080 | printf("%s\n", _("Rate Calculation:")); | ||
| 1081 | printf(" %s\n", _("In many places, SNMP returns counters that are only meaningful when")); | ||
| 1082 | printf(" %s\n", _("calculating the counter difference since the last check. check_snmp")); | ||
| 1083 | printf(" %s\n", _("saves the last state information in a file so that the rate can be")); | ||
| 1084 | printf(" %s\n", _("calculated. Use the --rate option to save state information. On the")); | ||
| 1085 | printf(" %s\n", _("first run, there will be no prior state - this will return with OK.")); | ||
| 1086 | printf(" %s\n", _("The state is uniquely determined by the arguments to the plugin, so")); | ||
| 1087 | printf(" %s\n", _("changing the arguments will create a new state file.")); | ||
| 1088 | |||
| 948 | printf (UT_SUPPORT); | 1089 | printf (UT_SUPPORT); |
| 949 | } | 1090 | } |
| 950 | 1091 | ||
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index b5f3f89e..17420792 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
| @@ -51,7 +51,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | my $tests = 9; | 54 | my $tests = 21; |
| 55 | if (-x "./check_snmp") { | 55 | if (-x "./check_snmp") { |
| 56 | plan tests => $tests; | 56 | plan tests => $tests; |
| 57 | } else { | 57 | } else { |
| @@ -106,3 +106,40 @@ like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C | |||
| 106 | "And now have fun with with this: \"C:\\\\\" | 106 | "And now have fun with with this: \"C:\\\\\" |
| 107 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); | 107 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); |
| 108 | 108 | ||
| 109 | system("rm /usr/local/nagios/var/check_snmp/*"); | ||
| 110 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | ||
| 111 | is($res->return_code, 0, "Returns OK"); | ||
| 112 | is($res->output, "No previous data to calculate rate - assume okay"); | ||
| 113 | |||
| 114 | # Need to sleep, otherwise duration=0 | ||
| 115 | sleep 1; | ||
| 116 | |||
| 117 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | ||
| 118 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); | ||
| 119 | is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10-rate=666 "); | ||
| 120 | |||
| 121 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | ||
| 122 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); | ||
| 123 | is($res->output, "Time duration between plugin calls is invalid"); | ||
| 124 | |||
| 125 | |||
| 126 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | ||
| 127 | is($res->return_code, 0, "OK for first call" ); | ||
| 128 | is($res->output, "No previous data to calculate rate - assume okay" ); | ||
| 129 | |||
| 130 | # Need to sleep, otherwise duration=0 | ||
| 131 | sleep 1; | ||
| 132 | |||
| 133 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | ||
| 134 | is($res->return_code, 0, "OK as no thresholds" ); | ||
| 135 | is($res->output, "SNMP RATE OK - inoctets 666 | inoctets-rate=666 ", "Check label"); | ||
| 136 | |||
| 137 | sleep 2; | ||
| 138 | |||
| 139 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | ||
| 140 | is($res->return_code, 0, "OK as no thresholds" ); | ||
| 141 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets-rate=333 ", "Check rate decreases due to longer interval"); | ||
| 142 | |||
| 143 | |||
| 144 | |||
| 145 | |||
diff --git a/plugins/tests/check_snmp_agent.pl b/plugins/tests/check_snmp_agent.pl index 302ba6e7..425caeb3 100644 --- a/plugins/tests/check_snmp_agent.pl +++ b/plugins/tests/check_snmp_agent.pl | |||
| @@ -33,9 +33,9 @@ ends with with this: C:\\'; | |||
| 33 | my $multilin5 = 'And now have fun with with this: "C:\\" | 33 | my $multilin5 = 'And now have fun with with this: "C:\\" |
| 34 | because we\'re not done yet!'; | 34 | because we\'re not done yet!'; |
| 35 | 35 | ||
| 36 | my @fields = (ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_UNSIGNED, ASN_UNSIGNED, ASN_COUNTER, ASN_COUNTER64, ASN_UNSIGNED); | 36 | my @fields = (ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_UNSIGNED, ASN_UNSIGNED, ASN_COUNTER, ASN_COUNTER64, ASN_UNSIGNED, ASN_COUNTER); |
| 37 | my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32))); | 37 | my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32)), 64000); |
| 38 | my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef); | 38 | my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef, 666); |
| 39 | 39 | ||
| 40 | # Number of elements in our OID | 40 | # Number of elements in our OID |
| 41 | my $oidelts; | 41 | my $oidelts; |
