diff options
author | Alexander Kanavin <alex@linutronix.de> | 2023-08-22 14:02:16 +0200 |
---|---|---|
committer | Alexander Kanavin <alex@linutronix.de> | 2023-08-23 14:42:05 +0200 |
commit | 4c658af0b8524caaaa25a94f82c918e1bd7e8545 (patch) | |
tree | a317e32f7e1b605e51ac92a0d412c3f75ac5c19d /dbus/dbus-sysdeps.c | |
parent | 67a7ee7792d30f8f64ca2d517b1a9339c67ebed5 (diff) |
time: use dbus_int64_t for seconds instead of long
On 32 bit systems long will overflow in 2038, causing complete breakage.
This is confirmed by running dbus's test suite on a 32 bit system
with system time set to 2040 (and configured to use 64 bit time_t of course).
Note that both timespec and timeval are specified with time_t for the
seconds component. This should propagate everywhere where that data is
passed and stored, but previously _dbus_get_monotonic_time() and
_dbus_get_monotonic_time() would truncate it to long.
Also add a function for parsing dbus_int64_t from
files, as existing functions can only handle long.
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Diffstat (limited to 'dbus/dbus-sysdeps.c')
-rw-r--r-- | dbus/dbus-sysdeps.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 537e7635..8b82bfd5 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -508,6 +508,45 @@ _dbus_string_parse_uint (const DBusString *str, return TRUE; } +/** + * Parses a dbus_int64_t integer contained in a DBusString. Either return parameter + * may be #NULL if you aren't interested in it. The integer is parsed + * and stored in value_return. Return parameters are not initialized + * if the function returns #FALSE. + * + * @param str the string + * @param start the byte index of the start of the integer + * @param value_return return location of the integer value or #NULL + * @param end_return return location of the end of the integer, or #NULL + * @returns #TRUE on success + */ +dbus_bool_t +_dbus_string_parse_int64 (const DBusString *str, + int start, + dbus_int64_t *value_return, + int *end_return) +{ + dbus_int64_t v; + const char *p; + char *end; + + p = _dbus_string_get_const_data_len (str, start, + _dbus_string_get_length (str) - start); + + end = NULL; + _dbus_set_errno_to_zero (); + v = strtoll (p, &end, 0); + if (end == NULL || end == p || errno != 0) + return FALSE; + + if (value_return) + *value_return = v; + if (end_return) + *end_return = start + (end - p); + + return TRUE; +} + /** @} */ /* DBusString group */ /** |