util/u_process: implement util_get_process_name for Windows

There's not yet any users of this function on Windows, but it prints a
warning during builds, and seems easy enough to implement. So let's add
a trivial implementation.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7548>
This commit is contained in:
Erik Faye-Lund 2020-11-11 15:46:14 +01:00 committed by Marge Bot
parent d442a99238
commit 1a5400a9e9
2 changed files with 25 additions and 4 deletions

View file

@ -52,10 +52,14 @@ expect_equal_str(const char *expected, const char *actual, const char *test)
static void
test_util_get_process_name (void)
{
#if !DETECT_OS_WINDOWS
const char* name = util_get_process_name();
expect_equal_str("process_test", name, "util_get_process_name");
#endif
#if DETECT_OS_WINDOWS
const char *expected = "process_test.exe";
#else
const char *expected = "process_test";
#endif
const char *name = util_get_process_name();
expect_equal_str(expected, name, "util_get_process_name");
}
/* This test gets the real path from Meson (BUILD_FULL_PATH env var),

View file

@ -135,6 +135,23 @@ __getProgramName()
}
# define GET_PROGRAM_NAME() __getProgramName()
#elif defined(WIN32)
static const char *
__getProgramName()
{
static const char *progname;
if (progname == NULL) {
static char buf[MAX_PATH];
GetModuleFileNameA(NULL, buf, sizeof(buf));
progname = strrchr(buf, '\\');
if (progname)
progname++;
else
progname = buf;
}
return progname;
}
# define GET_PROGRAM_NAME() __getProgramName()
#endif
#if !defined(GET_PROGRAM_NAME)