src/filesystem/unix/SDL_sysfilesystem.c
changeset 7692 e1036c58fac7
parent 7668 66da4242ce53
child 7693 4907ee4d2883
     1.1 --- a/src/filesystem/unix/SDL_sysfilesystem.c	Thu Aug 22 17:26:22 2013 -0300
     1.2 +++ b/src/filesystem/unix/SDL_sysfilesystem.c	Fri Aug 23 21:38:54 2013 -0400
     1.3 @@ -26,9 +26,14 @@
     1.4  /* System dependent filesystem routines                                */
     1.5  
     1.6  #include <unistd.h>
     1.7 +#include <stdlib.h>
     1.8  #include <sys/stat.h>
     1.9  #include <sys/types.h>
    1.10  
    1.11 +#ifdef __FREEBSD__
    1.12 +#include <sys/sysctl.h>
    1.13 +#endif
    1.14 +
    1.15  #include "SDL_error.h"
    1.16  #include "SDL_stdinc.h"
    1.17  #include "SDL_filesystem.h"
    1.18 @@ -73,9 +78,41 @@
    1.19  {
    1.20      char *retval = NULL;
    1.21  
    1.22 +#if defined(__FREEBSD__)
    1.23 +    char fullpath[PATH_MAX];
    1.24 +    size_t buflen = sizeof (fullpath);
    1.25 +    int mib[4];
    1.26 +    mib[0] = CTL_KERN;
    1.27 +    mib[1] = KERN_PROC;
    1.28 +    mib[2] = KERN_PROC_PATHNAME;
    1.29 +    mib[3] = -1;
    1.30 +    if (sysctl(mib, 4, fullpath, &buflen, NULL, 0) != -1) {
    1.31 +        retval = SDL_strdup(fullpath);
    1.32 +        if (!retval) {
    1.33 +            SDL_OutOfMemory();
    1.34 +            return NULL;
    1.35 +        }
    1.36 +    }
    1.37 +#elif defined(__SOLARIS__)
    1.38 +    const char *path = getexecname();
    1.39 +    if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
    1.40 +        retval = SDL_strdup(fullpath);
    1.41 +        if (!retval) {
    1.42 +            SDL_OutOfMemory();
    1.43 +            return NULL;
    1.44 +        }
    1.45 +    }
    1.46 +#endif
    1.47 +
    1.48      /* is a Linux-style /proc filesystem available? */
    1.49 -    if (access("/proc", F_OK) == 0) {
    1.50 -        retval = readSymLink("/proc/self/exe");
    1.51 +    if (!retval && (access("/proc", F_OK) == 0)) {
    1.52 +        #if defined(__FREEBSD__)
    1.53 +        retval = readSymLink("/proc/curproc/file");
    1.54 +        #elif defined(__NETBSD__)
    1.55 +        retval = readSymLink("/proc/curproc/exe");
    1.56 +        #else
    1.57 +        retval = readSymLink("/proc/self/exe");  /* linux. */
    1.58 +        #endif
    1.59          if (retval == NULL) {
    1.60              /* older kernels don't have /proc/self ... try PID version... */
    1.61              char path[64];