]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
_dbus_get_low_level_socket_errno: Add
authorSimon McVittie <smcv@collabora.com>
Thu, 8 Mar 2018 18:53:31 +0000 (18:53 +0000)
committerSimon McVittie <smcv@collabora.com>
Fri, 9 Mar 2018 12:25:46 +0000 (12:25 +0000)
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 <smcv@collabora.com>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61922

dbus/dbus-sysdeps-unix.c
dbus/dbus-sysdeps-win.c
dbus/dbus-sysdeps.h

index beeb34ee096f193876cdd8e0da06787c7d4c2c1f..d4f448a7872ba2aec5adf29596861237dacf73e7 100644 (file)
@@ -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 */
index 4e71d1cf27cf1031ccc778ee384ca36bdf184abc..37faacb32e151ae0c7dc68347add4d4bee99f81e 100644 (file)
@@ -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 */
index 0d1ff7c46a4e46b9a2b3cb3fe51b25b738cebd62..13aeb758fd0b882854741a0dae8907b33b423478 100644 (file)
@@ -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);