David Carlier implemented SDL_GetBasePath() for OpenBSD
authorSam Lantinga <slouken@libsdl.org>
Sun, 31 Jan 2016 21:11:15 -0800
changeset 10061698a7d8626b9
parent 10060 739bc5c7d339
child 10062 c31b24c7babc
David Carlier implemented SDL_GetBasePath() for OpenBSD
src/filesystem/unix/SDL_sysfilesystem.c
     1.1 --- a/src/filesystem/unix/SDL_sysfilesystem.c	Sun Jan 31 11:29:11 2016 -0800
     1.2 +++ b/src/filesystem/unix/SDL_sysfilesystem.c	Sun Jan 31 21:11:15 2016 -0800
     1.3 @@ -33,7 +33,7 @@
     1.4  #include <sys/types.h>
     1.5  #include <limits.h>
     1.6  
     1.7 -#ifdef __FREEBSD__
     1.8 +#if defined(__FREEBSD__) || defined(__OPENBSD__)
     1.9  #include <sys/sysctl.h>
    1.10  #endif
    1.11  
    1.12 @@ -90,7 +90,26 @@
    1.13              return NULL;
    1.14          }
    1.15      }
    1.16 -#elif defined(__SOLARIS__)
    1.17 +#endif
    1.18 +#if defined(__OPENBSD__)
    1.19 +    char **retvalargs;
    1.20 +    size_t len;
    1.21 +    const int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
    1.22 +    if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
    1.23 +        retvalargs = SDL_malloc(len);
    1.24 +        if (!retvalargs) {
    1.25 +            SDL_OutOfMemory();
    1.26 +            return NULL;
    1.27 +        }
    1.28 +        sysctl(mib, 4, retvalargs, &len, NULL, 0);
    1.29 +        retval = SDL_malloc(PATH_MAX + 1);
    1.30 +        if (retval)
    1.31 +            realpath(retvalargs[0], retval);
    1.32 +
    1.33 +        SDL_free(retvalargs);
    1.34 +    }
    1.35 +#endif
    1.36 +#if defined(__SOLARIS__)
    1.37      const char *path = getexecname();
    1.38      if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
    1.39          retval = SDL_strdup(path);