util: Pre-allocate buffer for ovs_lasterror_to_string().
[sliver-openvswitch.git] / lib / socket-util.c
index f5d3137..d83ddf1 100644 (file)
@@ -35,6 +35,7 @@
 #include <unistd.h>
 #include "dynamic-string.h"
 #include "fatal-signal.h"
+#include "ovs-thread.h"
 #include "packets.h"
 #include "poll-loop.h"
 #include "util.h"
@@ -1344,3 +1345,19 @@ ss_length(const struct sockaddr_storage *ss)
         OVS_NOT_REACHED();
     }
 }
+
+/* For Windows socket calls, 'errno' is not set.  One has to call
+ * WSAGetLastError() to get the error number and then pass it to
+ * this function to get the correct error string.
+ *
+ * ovs_strerror() calls strerror_r() and would not get the correct error
+ * string for Windows sockets, but is good for POSIX. */
+const char *
+sock_strerror(int error)
+{
+#ifdef _WIN32
+    return ovs_format_message(error);
+#else
+    return ovs_strerror(error);
+#endif
+}