program_invocation_name isn't available on macOS, let's use getprogname() instead.
Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- libs/vkd3d/utils.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index cdc5512..a5f18ef 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -577,7 +577,16 @@ HRESULT vkd3d_load_vk_device_procs(struct vkd3d_vk_device_procs *procs, return S_OK; }
-#ifdef _GNU_SOURCE +#ifdef __APPLE__ + +bool vkd3d_get_program_name(char program_name[PATH_MAX]) +{ + strncpy(program_name, getprogname(), PATH_MAX); + program_name[PATH_MAX - 1] = '\0'; + return true; +} + +#elif defined(_GNU_SOURCE)
bool vkd3d_get_program_name(char program_name[PATH_MAX]) {
On Thu, Aug 1, 2019 at 4:46 AM Jactry Zeng jzeng@codeweavers.com wrote:
-#ifdef _GNU_SOURCE +#ifdef __APPLE__
It's probably better to test for getprogname() instead of __APPLE__.
+bool vkd3d_get_program_name(char program_name[PATH_MAX]) +{
- strncpy(program_name, getprogname(), PATH_MAX);
- program_name[PATH_MAX - 1] = '\0';
strncpy() always adds a terminating null byte.
- return true;
+}
vkd3d_get_program_name() is supposed to get just the name of the executable, e.g. it needs to extract it from the full path. Our other implementation also extracts the executable name when a program is run under Wine. I'm afraid it might not be as simple as calling getprogrname().
Moreover, in the long term it might not be necessary to have an implementation of vkd3d_get_program_name() for programs running under Wine. We'll probably start filling vkd3d_application_info in Wine after the next vkd3d release.
Józef Kucia joseph.kucia@gmail.com wrote:
+bool vkd3d_get_program_name(char program_name[PATH_MAX]) +{
- strncpy(program_name, getprogname(), PATH_MAX);
- program_name[PATH_MAX - 1] = '\0';
strncpy() always adds a terminating null byte.
It doesn not in case of insufficient target buffer size. That's probably not the common case though, however strncpy() always fills up the buffer with zeros which is worst behaviour ever, so it's probably better to just use plain strcpy().
On Thu, Aug 1, 2019 at 9:43 AM Dmitry Timoshkov dmitry@baikal.ru wrote:
It doesn not in case of insufficient target buffer size. That's probably not the common case though, however strncpy() always fills up the buffer with zeros which is worst behaviour ever, so it's probably better to just use plain strcpy().
Right, we even place '\0' ourselves in vkd3d_get_program_name(). Sorry for the misleading comment.