[Mesa-dev] [PATCH] r300g: add program name check for BSD

Jonathan Gray jsg at jsg.id.au
Wed Jun 26 21:08:44 PDT 2013


On Wed, Jun 26, 2013 at 09:49:08AM -0600, Brian Paul wrote:
> On 06/26/2013 01:11 AM, Jonathan Gray wrote:
> >program_invocation_short_name is glibc specific.  Provide an
> >alternative using getprogname(), which can be found on *BSD and OS X.
> >
> >Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
> >---
> >  src/gallium/drivers/r300/r300_chipset.c | 10 +++++++++-
> >  1 file changed, 9 insertions(+), 1 deletion(-)
> >
> >diff --git src/gallium/drivers/r300/r300_chipset.c src/gallium/drivers/r300/r300_chipset.c
> >index 11061ed..7f51ccb 100644
> >--- src/gallium/drivers/r300/r300_chipset.c
> >+++ src/gallium/drivers/r300/r300_chipset.c
> >@@ -30,6 +30,14 @@
> >  #include <stdio.h>
> >  #include <errno.h>
> >
> >+#undef GET_PROGRAM_NAME
> >+#ifdef __GLIBC__
> >+#	define GET_PROGRAM_NAME() program_invocation_short_name
> >+#else /* *BSD and OS X */
> >+#	include <stdlib.h>
> >+#	define GET_PROGRAM_NAME() getprogname()
> >+#endif
> >+
> >  /* r300_chipset: A file all to itself for deducing the various properties of
> >   * Radeons. */
> >
> >@@ -49,7 +57,7 @@ static void r300_apply_hyperz_blacklist(struct r300_capabilities* caps)
> >      int i;
> >
> >      for (i = 0; i < Elements(list); i++) {
> >-        if (strcmp(list[i], program_invocation_short_name) == 0) {
> >+        if (strcmp(list[i], GET_PROGRAM_NAME()) == 0) {
> >              caps->zmask_ram = 0;
> >              caps->hiz_ram = 0;
> >              break;
> >
> 
> I think a new gallium utility function for this would be helpful.
> In fact I've already implemented something like this for our windows
> driver.
> 
> Does the attached code look OK you to guys?

looks good to me, a few nitpicks inline

> 
> -Brian
> 
> 

> #include "pipe/p_config.h"
> #include "os/os_process.h"
> #include "util/u_memory.h"
> 
> #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
> #  include <windows.h>
> #endif

it isn't clear if stdlib.h is included here?

> 
> 
> /**
>  * Return the name of the current process.
>  * \param procname  returns the process name, always 0-terminated
>  * \param size  size of the procname buffer
>  * \return  TRUE or FALSE for success, failure
>  */
> boolean
> os_get_process_name(char *procname, size_t size)
> {
>    const char *name;
> #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
>    char szProcessPath[MAX_PATH];
>    char *lpProcessName;
>    char *lpProcessExt;
> 
>    GetModuleFileNameA(NULL, szProcessPath, Elements(szProcessPath));
> 
>    lpProcessName = strrchr(szProcessPath, '\\');
>    lpProcessName = lpProcessName ? lpProcessName + 1 : szProcessPath;
> 
>    lpProcessExt = strrchr(lpProcessName, '.');
>    if (lpProcessExt) {
>       *lpProcessExt = '\0';
>    }
> 
>    name = lpProcessName;
> 
> #elif defined(__GLIBC__)
>    name = program_invocation_short_name;
> #else /* *BSD and OS X */
>    name = getprogname();
> #endif
> 
>    assert(procname);
>    assert(size > 0);
> 
>    if (name) {
>       strncpy(procname, name, size);
>       procname[size - 1] = 0;

and this should be '\0' not 0, though the end result is the same

>       return TRUE;
>    }
>    else {
>       return FALSE;
>    }
> }



More information about the mesa-dev mailing list