From 1037c0cab5246cd19ed987fa974c73303c4c72bb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 8 Mar 2018 18:53:31 +0000 Subject: [PATCH] _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 https://bugs.freedesktop.org/show_bug.cgi?id=61922 --- dbus/dbus-sysdeps-unix.c | 14 ++++++++++++++ dbus/dbus-sysdeps-win.c | 14 ++++++++++++++ dbus/dbus-sysdeps.h | 2 ++ 3 files changed, 30 insertions(+) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index beeb34ee..d4f448a7 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 4e71d1cf..37faacb3 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 0d1ff7c4..13aeb758 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); -- 2.12.3