1 /**************************************************************************
3 * Copyright 2013 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "pipe/p_config.h"
30 #include "os/os_process.h"
31 #include "util/u_memory.h"
33 #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
35 #elif defined(__GLIBC__) || defined(__CYGWIN__)
37 #elif defined(PIPE_OS_BSD) || defined(PIPE_OS_APPLE)
39 #elif defined(PIPE_OS_HAIKU)
40 # include <kernel/OS.h>
41 # include <kernel/image.h>
43 #warning unexpected platform in os_process.c
48 * Return the name of the current process.
49 * \param procname returns the process name
50 * \param size size of the procname buffer
51 * \return TRUE or FALSE for success, failure
54 os_get_process_name(char *procname, size_t size)
58 /* First, check if the GALLIUM_PROCESS_NAME env var is set to
59 * override the normal process name query.
61 name = os_get_option("GALLIUM_PROCESS_NAME");
66 #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
67 char szProcessPath[MAX_PATH];
71 GetModuleFileNameA(NULL, szProcessPath, ARRAY_SIZE(szProcessPath));
73 lpProcessName = strrchr(szProcessPath, '\\');
74 lpProcessName = lpProcessName ? lpProcessName + 1 : szProcessPath;
76 lpProcessExt = strrchr(lpProcessName, '.');
83 #elif defined(__GLIBC__) || defined(__CYGWIN__)
84 name = program_invocation_short_name;
85 #elif defined(PIPE_OS_BSD) || defined(PIPE_OS_APPLE)
88 #elif defined(PIPE_OS_HAIKU)
90 get_image_info(B_CURRENT_TEAM, &info);
93 #warning unexpected platform in os_process.c
102 if (name && procname && size > 0) {
103 strncpy(procname, name, size);
104 procname[size - 1] = '\0';