diff options
author | Simon McVittie <smcv@collabora.com> | 2022-07-20 13:27:46 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2022-07-20 13:27:46 +0000 |
commit | 702ca4d13c02bf051954f19b9504f187d2cd25f7 (patch) | |
tree | 3b7b8835ab5e445e2fb53130fa7ae360e705cf92 | |
parent | 536b39a11c5af942fb7fff16c7b316b6532a59a0 (diff) | |
parent | 98eff5513ea8a3523c05a93abd28d64a89e6fb80 (diff) |
Merge branch 'require-c99' into 'master'
Officially drop support for non-C99 compilers, and start using C99 low-hanging fruit
Closes #404
See merge request dbus/dbus!331
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | README.win | 7 | ||||
-rw-r--r-- | cmake/ConfigureChecks.cmake | 48 | ||||
-rw-r--r-- | cmake/config.h.cmake | 26 | ||||
-rw-r--r-- | configure.ac | 57 | ||||
-rw-r--r-- | dbus/dbus-hash.h | 2 | ||||
-rw-r--r-- | dbus/dbus-message.c | 2 | ||||
-rw-r--r-- | dbus/dbus-pipe.h | 2 | ||||
-rw-r--r-- | dbus/dbus-string.c | 4 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-unix.c | 10 | ||||
-rw-r--r-- | dbus/dbus-sysdeps-win.c | 8 | ||||
-rw-r--r-- | dbus/dbus-sysdeps.h | 2 | ||||
-rw-r--r-- | meson.build | 53 | ||||
-rw-r--r-- | tools/Makefile.am | 2 | ||||
-rw-r--r-- | tools/dbus-send.c | 12 | ||||
-rw-r--r-- | tools/strtoll.c | 166 | ||||
-rw-r--r-- | tools/strtoull.c | 145 |
17 files changed, 24 insertions, 529 deletions
@@ -1,6 +1,13 @@ dbus 1.15.0 (UNRELEASED) ======================== +Dependencies: + +• dbus now requires either a C99 compiler (such as gcc or clang), + or Microsoft Visual Studio 2015 or later. Some workarounds for + pre-C99 environments are currently still present, but we plan to + remove them during this development cycle. + Feature removal: • Remove support for the obsolete pam_console and pam_foreground modules @@ -13,8 +13,11 @@ test not running yet and there is help needed to get them running. Supported compilers ------------------- -On windows Microsoft Visual Studio 2010 (Express and professional variants) -and mingw-w64|32 are known to work. +Building dbus for Windows requires either Microsoft Visual Studio 2015 +or later, or a recent mingw-w64 compiler. + +Compilers older than the ones we test in continuous integration are +not supported. Building -------- diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 17b2e201..6ce85204 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -17,7 +17,6 @@ check_include_file(io.h HAVE_IO_H) # internal check_include_file(linux/close_range.h HAVE_LINUX_CLOSE_RANGE_H) check_include_file(locale.h HAVE_LOCALE_H) check_include_file(signal.h HAVE_SIGNAL_H) -check_include_file(stdint.h HAVE_STDINT_H) # dbus-pipe.h check_include_file(stdio.h HAVE_STDIO_H) # dbus-sysdeps.h check_include_file(syslog.h HAVE_SYSLOG_H) check_include_files("stdint.h;sys/types.h;sys/event.h" HAVE_SYS_EVENT_H) @@ -50,8 +49,6 @@ check_symbol_exists(socketpair "sys/socket.h" HAVE_SOCKETPAIR) # check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE) # dbus-test-main.c check_symbol_exists(localeconv "locale.h" HAVE_LOCALECONV) # dbus-sysdeps.c check_symbol_exists(poll "poll.h" HAVE_POLL) # dbus-sysdeps-unix.c -check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL) # dbus-send.c -check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL) # dbus-send.c set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) check_symbol_exists(pipe2 "fcntl.h;unistd.h" HAVE_PIPE2) check_symbol_exists(accept4 "sys/socket.h" HAVE_ACCEPT4) @@ -81,51 +78,6 @@ epoll_create1 (EPOLL_CLOEXEC); }" DBUS_HAVE_LINUX_EPOLL) CHECK_C_SOURCE_COMPILES(" -#include <stdarg.h> -#include <stdlib.h> -static void f (int i, ...) { - va_list args1, args2; - va_start (args1, i); - va_copy (args2, args1); - if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) - exit (1); - va_end (args1); va_end (args2); -} -int main() { - f (0, 42); - return 0; -} -" HAVE_VA_COPY) - -CHECK_C_SOURCE_COMPILES(" -#include <stdarg.h> -#include <stdlib.h> -static void f (int i, ...) { - va_list args1, args2; - va_start (args1, i); - __va_copy (args2, args1); - if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) - exit (1); - va_end (args1); va_end (args2); -} -int main() { - f (0, 42); - return 0; -} -" HAVE___VA_COPY) - -if(HAVE_VA_COPY) - set(DBUS_VA_COPY va_copy CACHE STRING "va_copy function") -elseif(HAVE___VA_COPY) - set(DBUS_VA_COPY __va_copy CACHE STRING "va_copy function") -elseif(MSVC) - # this is used for msvc < 2013 - set(DBUS_VA_COPY _DBUS_VA_COPY_ASSIGN) -else() - message(FATAL_ERROR "dbus requires an ISO C99-compatible va_copy() macro, or a similar __va_copy(), or MSVC >= 2010") -endif() - -CHECK_C_SOURCE_COMPILES(" int main() { int a = 4; int b = __sync_sub_and_fetch(&a, 4); diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index b70f8390..b8d98fb2 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -83,12 +83,6 @@ # define DBUS_ENABLE_X11_AUTOLAUNCH 1 #endif -/* A 'va_copy' style function */ -#cmakedefine DBUS_VA_COPY @DBUS_VA_COPY@ - -/* for msvc */ -#define _DBUS_VA_COPY_ASSIGN(a1,a2) { a1 = a2; } - #cmakedefine DBUS_WITH_GLIB 1 #cmakedefine GLIB_VERSION_MIN_REQUIRED @GLIB_VERSION_MIN_REQUIRED@ #cmakedefine GLIB_VERSION_MAX_ALLOWED @GLIB_VERSION_MAX_ALLOWED@ @@ -120,9 +114,6 @@ /* Define to 1 if you have signal.h */ #cmakedefine HAVE_SIGNAL_H 1 -/* Define to 1 if you have stdint.h */ -#cmakedefine HAVE_STDINT_H 1 - /* Define to 1 if you have stdio.h */ #cmakedefine HAVE_STDIO_H 1 @@ -191,12 +182,6 @@ /* Define to 1 if you have localeconv */ #cmakedefine HAVE_LOCALECONV 1 -/* Define to 1 if you have strtoll */ -#cmakedefine HAVE_STRTOLL 1 - -/* Define to 1 if you have strtoull */ -#cmakedefine HAVE_STRTOULL 1 - /* Define to 1 if you have pip2 */ #cmakedefine HAVE_PIPE2 1 @@ -261,14 +246,7 @@ # define uid_t int # define gid_t int # else -# define snprintf _snprintf typedef int mode_t; -# if !defined(_WIN32_WCE) -# define strtoll _strtoi64 -# define strtoull _strtoui64 -# define HAVE_STRTOLL 1 -# define HAVE_STRTOULL 1 -# endif # endif #endif // defined(_WIN32) || defined(_WIN64) @@ -280,10 +258,6 @@ #define SIGHUP 1 #endif -# if defined(_MSC_VER) && !defined(inline) -#define inline __inline -#endif - #ifdef DBUS_WIN #define FD_SETSIZE @FD_SETSIZE@ #endif diff --git a/configure.ac b/configure.ac index 0c5cdfea..238b1ac5 100644 --- a/configure.ac +++ b/configure.ac @@ -101,7 +101,6 @@ AC_USE_SYSTEM_EXTENSIONS AC_SYS_LARGEFILE AC_ISC_POSIX AC_HEADER_STDC -AC_C_INLINE AM_PROG_LIBTOOL AC_PROG_MKDIR_P PKG_PROG_PKG_CONFIG @@ -404,8 +403,6 @@ setlocale setresuid setrlimit socketpair -strtoll -strtoull unsetenv usleep ]) @@ -422,7 +419,6 @@ errno.h linux/close_range.h locale.h signal.h -stdint.h sys/prctl.h sys/random.h sys/resource.h @@ -568,59 +564,6 @@ esac # the AC_INCLUDES_DEFAULT. AC_CHECK_DECLS([environ]) -dnl ********************************** -dnl *** va_copy checks (from GLib) *** -dnl ********************************** -dnl we currently check for all three va_copy possibilities, so we get -dnl all results in config.log for bug reports. -AC_CACHE_CHECK([for an implementation of va_copy()],dbus_cv_va_copy,[ - AC_LINK_IFELSE([AC_LANG_SOURCE([#include <stdarg.h> -#include <stdlib.h> - static void f (int i, ...) { - va_list args1, args2; - va_start (args1, i); - va_copy (args2, args1); - if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) - exit (1); - va_end (args1); va_end (args2); - } - int main() { - f (0, 42); - return 0; - }])], - [dbus_cv_va_copy=yes], - [dbus_cv_va_copy=no]) -]) -AC_CACHE_CHECK([for an implementation of __va_copy()],dbus_cv___va_copy,[ - AC_LINK_IFELSE([AC_LANG_SOURCE([#include <stdarg.h> -#include <stdlib.h> - static void f (int i, ...) { - va_list args1, args2; - va_start (args1, i); - __va_copy (args2, args1); - if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) - exit (1); - va_end (args1); va_end (args2); - } - int main() { - f (0, 42); - return 0; - }])], - [dbus_cv___va_copy=yes], - [dbus_cv___va_copy=no]) -]) - -if test "x$dbus_cv_va_copy" = "xyes"; then - dbus_va_copy_func=va_copy -else if test "x$dbus_cv___va_copy" = "xyes"; then - dbus_va_copy_func=__va_copy -fi -fi - -AS_IF([test -n "$dbus_va_copy_func"], - [AC_DEFINE_UNQUOTED([DBUS_VA_COPY], [$dbus_va_copy_func], [A 'va_copy' style function])], - [AC_MSG_ERROR([dbus requires an ISO C99-compatible va_copy() macro, or a compatible __va_copy(), or MSVC >= 2010 and CMake])]) - #### Atomic integers AC_CACHE_CHECK([whether $CC knows __sync_sub_and_fetch()], diff --git a/dbus/dbus-hash.h b/dbus/dbus-hash.h index ea6fef0d..dc36633a 100644 --- a/dbus/dbus-hash.h +++ b/dbus/dbus-hash.h @@ -24,9 +24,7 @@ #ifndef DBUS_HASH_H #define DBUS_HASH_H -#ifdef HAVE_STDINT_H #include <stdint.h> -#endif #ifdef HAVE_INTTYPES_H #include <inttypes.h> diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 4c36aa39..19a43750 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -843,7 +843,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, /* copy var_args first, then we can do another iteration over it to * free memory and close unix fds if parse failed at some point. */ - DBUS_VA_COPY (copy_args, var_args); + va_copy (copy_args, var_args); while (spec_type != DBUS_TYPE_INVALID) { diff --git a/dbus/dbus-pipe.h b/dbus/dbus-pipe.h index 637d29ea..a0ff072b 100644 --- a/dbus/dbus-pipe.h +++ b/dbus/dbus-pipe.h @@ -25,9 +25,7 @@ #ifndef DBUS_PIPE_H #define DBUS_PIPE_H -#ifdef HAVE_STDINT_H #include <stdint.h> -#endif #ifdef HAVE_INTTYPES_H #include <inttypes.h> diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index 05c83231..1fecd6dd 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -41,8 +41,6 @@ #include "dbus-marshal-basic.h" /* probably should be removed by moving the usage of DBUS_TYPE * into the marshaling-related files */ -/* for DBUS_VA_COPY */ -#include "dbus-sysdeps.h" /** * @defgroup DBusString DBusString class @@ -1112,7 +1110,7 @@ _dbus_string_append_printf_valist (DBusString *str, DBUS_STRING_PREAMBLE (str); - DBUS_VA_COPY (args_copy, args); + va_copy (args_copy, args); /* Measure the message length without terminating nul */ len = _dbus_printf_string_upper_bound (format, args); diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 18bd1282..252798e3 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3825,7 +3825,7 @@ _dbus_printf_string_upper_bound (const char *format, int len; va_list args_copy; - DBUS_VA_COPY (args_copy, args); + va_copy (args_copy, args); len = vsnprintf (static_buf, bufsize, format, args_copy); va_end (args_copy); @@ -3843,7 +3843,7 @@ _dbus_printf_string_upper_bound (const char *format, * or the real length could be coincidentally the same. Which is it? * If vsnprintf returns the truncated length, we'll go to the slow * path. */ - DBUS_VA_COPY (args_copy, args); + va_copy (args_copy, args); if (vsnprintf (static_buf, 1, format, args_copy) == 1) len = -1; @@ -3864,7 +3864,7 @@ _dbus_printf_string_upper_bound (const char *format, if (buf == NULL) return -1; - DBUS_VA_COPY (args_copy, args); + va_copy (args_copy, args); len = vsnprintf (buf, bufsize, format, args_copy); va_end (args_copy); @@ -5097,7 +5097,7 @@ _dbus_logv (DBusSystemLogSeverity severity, _dbus_assert_not_reached ("invalid log severity"); } - DBUS_VA_COPY (tmp, args); + va_copy (tmp, args); vsyslog (flags, msg, tmp); va_end (tmp); } @@ -5107,7 +5107,7 @@ _dbus_logv (DBusSystemLogSeverity severity, if (log_flags & DBUS_LOG_FLAGS_STDERR) #endif { - DBUS_VA_COPY (tmp, args); + va_copy (tmp, args); fprintf (stderr, "%s[" DBUS_PID_FORMAT "]: ", syslog_tag, _dbus_getpid ()); vfprintf (stderr, msg, tmp); fputc ('\n', stderr); diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index e71f35d2..df4a4ce3 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -744,7 +744,7 @@ int _dbus_printf_string_upper_bound (const char *format, va_list args_copy; bufsize = sizeof (buf); - DBUS_VA_COPY (args_copy, args); + va_copy (args_copy, args); len = _vsnprintf (buf, bufsize - 1, format, args_copy); va_end (args_copy); @@ -759,7 +759,7 @@ int _dbus_printf_string_upper_bound (const char *format, if (p == NULL) return -1; - DBUS_VA_COPY (args_copy, args); + va_copy (args_copy, args); len = _vsnprintf (p, bufsize - 1, format, args_copy); va_end (args_copy); free (p); @@ -4249,7 +4249,7 @@ _dbus_logv (DBusSystemLogSeverity severity, { DBusString out = _DBUS_STRING_INIT_INVALID; const char *message = NULL; - DBUS_VA_COPY (tmp, args); + va_copy (tmp, args); if (!_dbus_string_init (&out)) goto out; @@ -4276,7 +4276,7 @@ out: if (log_flags & DBUS_LOG_FLAGS_STDERR) { - DBUS_VA_COPY (tmp, args); + va_copy (tmp, args); fprintf (stderr, "%s[%lu]: %s: ", log_tag, _dbus_pid_for_log (), s); vfprintf (stderr, msg, tmp); fprintf (stderr, "\n"); diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 5270a5de..7023ea71 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -30,9 +30,7 @@ #include "config.h" #endif -#ifdef HAVE_STDINT_H #include <stdint.h> -#endif #ifdef HAVE_INTTYPES_H #include <inttypes.h> diff --git a/meson.build b/meson.build index 8c45522f..c6dbb578 100644 --- a/meson.build +++ b/meson.build @@ -595,8 +595,6 @@ check_functions = [ 'setresuid', 'setrlimit', 'socketpair', - 'strtoll', - 'strtoull', 'unsetenv', 'usleep', ] @@ -619,7 +617,6 @@ check_headers = [ 'linux/close_range.h', 'locale.h', 'signal.h', - 'stdint.h', 'syslog.h', 'sys/prctl.h', 'sys/random.h', @@ -642,56 +639,6 @@ have_backtrace = (cc.has_header('execinfo.h', args: compile_args_c) ) config.set('HAVE_BACKTRACE', have_backtrace) - -# ********************************** -# *** va_copy checks (from GLib) *** -# ********************************** -# we currently check for all three va_copy possibilities, so we get -# all results in config.log for bug reports. - -# Can't use cc.has_function here because va_copy is not -# exactly a function -va_copy_check = ''' -#include <stdarg.h> -#include <stdlib.h> - -static void f (int i, ...) -{ - va_list args1, args2; - va_start (args1, i); - @0@ (args2, args1); - - if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) - exit (1); - - va_end (args1); - va_end (args2); -} - -int main() -{ - f (0, 42); - return 0; -} -''' - -has_va_copy = cc.links(va_copy_check.format('va_copy'), args: compile_args_c) -has___va_copy = cc.links(va_copy_check.format('__va_copy'), args: compile_args_c) - -if has_va_copy - va_copy = 'va_copy' -elif has___va_copy - va_copy = '__va_copy' -elif cc.get_id() == 'msvc' - va_copy = '_DBUS_VA_COPY_ASSIGN' - config.set('_DBUS_VA_COPY_ASSIGN(a1,a2)', '{ a1 = a2; }') -else - error('dbus requires an ISO C99-compatible va_copy() macro, ' - + 'or a compatible __va_copy()') -endif -config.set('DBUS_VA_COPY', va_copy) - - # Can't use cc.has_function here because atomic operations are not # exactly functions config.set10( diff --git a/tools/Makefile.am b/tools/Makefile.am index dee5f862..5488b54d 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -140,7 +140,7 @@ SUFFIXES = .rc dbus_update_activation_environment_SOURCES += disable-uac.rc endif -EXTRA_DIST = run-with-tmp-session-bus.sh strtoll.c strtoull.c Win32.Manifest +EXTRA_DIST = run-with-tmp-session-bus.sh Win32.Manifest CLEANFILES = \ run-with-tmp-session-bus.conf \ $(nodist_dbus_update_activation_environment_SOURCES) diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 86858c50..3063290f 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -27,18 +27,6 @@ #include <dbus/dbus.h> #include "dbus/dbus-internals.h" -#ifndef HAVE_STRTOLL -#undef strtoll -#define strtoll mystrtoll -#include "strtoll.c" -#endif - -#ifndef HAVE_STRTOULL -#undef strtoull -#define strtoull mystrtoull -#include "strtoull.c" -#endif - #ifdef DBUS_WINCE #ifndef strdup #define strdup _strdup diff --git a/tools/strtoll.c b/tools/strtoll.c deleted file mode 100644 index 00f14c3c..00000000 --- a/tools/strtoll.c +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" - -#include <limits.h> -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif -#include <stdlib.h> -#ifdef DBUS_WINCE -#include <windows.h> -#endif - -#ifndef isspace -#define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n') -#endif - -/* Minimum and maximum values a `signed long long int' can hold. */ -#ifndef LLONG_MAX -# define LLONG_MAX 9223372036854775807LL -#endif - -#ifndef LLONG_MIN -# define LLONG_MIN (-LLONG_MAX - 1LL) -#endif -/* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */ -#ifndef ULLONG_MAX -# define ULLONG_MAX 18446744073709551615ULL -#endif -/* - * Convert a string to a long long integer. - * - * Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -long long strtoll (const char*, char **, int); - -long long -strtoll(const char * nptr, char ** endptr, int base) -{ - const char *s; - unsigned long long acc; - char c; - unsigned long long cutoff; - int neg, any, cutlim; - - /* - * Skip white space and pick up leading +/- sign if any. - * If base is 0, allow 0x for hex and 0 for octal, else - * assume decimal; if base is already 16, allow 0x. - */ - s = nptr; - do { - c = *s++; - } while (isspace((unsigned char)c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X') && - ((s[1] >= '0' && s[1] <= '9') || - (s[1] >= 'A' && s[1] <= 'F') || - (s[1] >= 'a' && s[1] <= 'f'))) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - acc = any = 0; - if (base < 2 || base > 36) - goto noconv; - - /* - * Compute the cutoff value between legal numbers and illegal - * numbers. That is the largest legal value, divided by the - * base. An input number that is greater than this value, if - * followed by a legal input character, is too big. One that - * is equal to this value may be valid or not; the limit - * between valid and invalid numbers is then based on the last - * digit. For instance, if the range for quads is - * [-9223372036854775808..9223372036854775807] and the input base - * is 10, cutoff will be set to 922337203685477580 and cutlim to - * either 7 (neg==0) or 8 (neg==1), meaning that if we have - * accumulated a value > 922337203685477580, or equal but the - * next digit is > 7 (or 8), the number is too big, and we will - * return a range error. - * - * Set 'any' if any `digits' consumed; make it negative to indicate - * overflow. - */ - cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX - : LLONG_MAX; - cutlim = cutoff % base; - cutoff /= base; - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') - c -= '0'; - else if (c >= 'A' && c <= 'Z') - c -= 'A' - 10; - else if (c >= 'a' && c <= 'z') - c -= 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) - any = -1; - else { - any = 1; - acc *= base; - acc += c; - } - } - if (any < 0) { - acc = neg ? LLONG_MIN : LLONG_MAX; -#ifdef DBUS_WINCE - SetLastError (ERROR_ARITHMETIC_OVERFLOW); -#else - errno = ERANGE; -#endif - } else if (!any) { -noconv: -#ifdef DBUS_WINCE - SetLastError (ERROR_INVALID_PARAMETER); -#else - errno = EINVAL; -#endif - } else if (neg) - acc = -acc; - if (endptr != NULL) - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} diff --git a/tools/strtoull.c b/tools/strtoull.c deleted file mode 100644 index 35595542..00000000 --- a/tools/strtoull.c +++ /dev/null @@ -1,145 +0,0 @@ -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" - -#include <limits.h> -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif -#include <stdlib.h> -#ifdef DBUS_WINCE -#include <windows.h> -#endif - -#ifndef isspace -#define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n') -#endif - -/* Minimum and maximum values a `signed long long int' can hold. */ -#ifndef LLONG_MAX -# define LLONG_MAX 9223372036854775807LL -#endif - -#ifndef LLONG_MIN -# define LLONG_MIN (-LLONG_MAX - 1LL) -#endif -/* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */ -#ifndef ULLONG_MAX -# define ULLONG_MAX 18446744073709551615ULL -#endif - -/* - * Convert a string to an unsigned long long integer. - * - * Assumes that the upper and lower case - * alphabets and digits are each contiguous. - */ -unsigned long long strtoull (const char *, char **, int); - -unsigned long long -strtoull(const char * nptr, char ** endptr, int base) -{ - const char *s; - unsigned long long acc; - char c; - unsigned long long cutoff; - int neg, any, cutlim; - - /* - * See strtoq for comments as to the logic used. - */ - s = nptr; - do { - c = *s++; - } while (isspace((unsigned char)c)); - if (c == '-') { - neg = 1; - c = *s++; - } else { - neg = 0; - if (c == '+') - c = *s++; - } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X') && - ((s[1] >= '0' && s[1] <= '9') || - (s[1] >= 'A' && s[1] <= 'F') || - (s[1] >= 'a' && s[1] <= 'f'))) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - acc = any = 0; - if (base < 2 || base > 36) - goto noconv; - - cutoff = ULLONG_MAX / base; - cutlim = ULLONG_MAX % base; - for ( ; ; c = *s++) { - if (c >= '0' && c <= '9') - c -= '0'; - else if (c >= 'A' && c <= 'Z') - c -= 'A' - 10; - else if (c >= 'a' && c <= 'z') - c -= 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) - any = -1; - else { - any = 1; - acc *= base; - acc += c; - } - } - if (any < 0) { - acc = ULLONG_MAX; -#ifdef DBUS_WINCE - SetLastError (ERROR_ARITHMETIC_OVERFLOW); -#else - errno = ERANGE; -#endif - } else if (!any) { -noconv: -#ifdef DBUS_WINCE - SetLastError (ERROR_INVALID_PARAMETER); -#else - errno = EINVAL; -#endif - } else if (neg) - acc = -acc; - if (endptr != NULL) - *endptr = (char *)(any ? s - 1 : nptr); - return (acc); -} |