From: Simon McVittie Date: Thu, 8 Mar 2018 18:53:31 +0000 (+0000) Subject: _dbus_get_low_level_socket_errno: Add X-Git-Tag: dbus-1.13.4~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc15de1f7b3525babd723151927fc739d7f8a249;p=thirdparty%2Fdbus.git _dbus_get_low_level_socket_errno: Add Some libdbus functions have as their API "this function sets errno", but that just leads to strangeness on Windows, where socket (Winsock) functions don't actually set errno themselves, leading to those functions having to copy the Winsock error into errno to fake the Unix-like behaviour. With hindsight, that was probably a bad idea. This function should be portable enough to be used with functions that are essentially the same on Unix and Windows, like inet_ntop(). Signed-off-by: Simon McVittie Reviewed-by: Ralf Habacker Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61922 --- diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index beeb34ee0..d4f448a78 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -4849,4 +4849,18 @@ _dbus_logv (DBusSystemLogSeverity severity, } } +/* + * Return the low-level representation of a socket error, as used by + * cross-platform socket APIs like inet_ntop(), send() and recv(). This + * is the standard errno on Unix, but is WSAGetLastError() on Windows. + * + * Some libdbus internal functions copy this into errno, but with + * hindsight that was probably a design flaw. + */ +int +_dbus_get_low_level_socket_errno (void) +{ + return errno; +} + /* tests in dbus-sysdeps-util.c */ diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 4e71d1cf2..37faacb32 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3749,5 +3749,19 @@ _dbus_logv (DBusSystemLogSeverity severity, } } +/* + * Return the low-level representation of a socket error, as used by + * cross-platform socket APIs like inet_ntop(), send() and recv(). This + * is the standard errno on Unix, but is WSAGetLastError() on Windows. + * + * Some libdbus internal functions copy this into errno, but with + * hindsight that was probably a design flaw. + */ +int +_dbus_get_low_level_socket_errno (void) +{ + return WSAGetLastError (); +} + /** @} end of sysdeps-win */ /* tests in dbus-sysdeps-util.c */ diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 0d1ff7c46..13aeb758f 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -479,6 +479,8 @@ const char* _dbus_error_from_errno (int error_number); DBUS_PRIVATE_EXPORT const char* _dbus_error_from_system_errno (void); +int _dbus_get_low_level_socket_errno (void); + int _dbus_save_socket_errno (void); void _dbus_restore_socket_errno (int saved_errno); void _dbus_set_errno_to_zero (void);