set_program_name__(const char *argv0, const char *version, const char *date,
const char *time)
{
- const char *slash = strrchr(argv0, '/');
+#ifdef _WIN32
+ char *basename;
+ size_t max_len = strlen(argv0) + 1;
+ if (program_name) {
+ return;
+ }
+ basename = xmalloc(max_len);
+ _splitpath_s(argv0, NULL, 0, NULL, 0, basename, max_len, NULL, 0);
+ assert_single_threaded();
+ program_name = basename;
+#else
+ const char *slash = strrchr(argv0, '/');
assert_single_threaded();
-
program_name = slash ? slash + 1 : argv0;
+#endif
free(program_version);
return ok;
}
+#ifdef _WIN32
+\f
+/* Calls FormatMessage() with GetLastError() as an argument. Returns
+ * pointer to a buffer that receives the null-terminated string that specifies
+ * the formatted message and that has to be freed by the caller with
+ * LocalFree(). */
+char *
+ovs_lasterror_to_string(void)
+{
+ char *buffer;
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0,
+ (char *)&buffer, 0, NULL);
+ return buffer;
+}
+#endif