src/filesystem/unix/SDL_sysfilesystem.c
changeset 7692 e1036c58fac7
parent 7668 66da4242ce53
child 7693 4907ee4d2883
equal deleted inserted replaced
7691:cf99258f905c 7692:e1036c58fac7
    24 
    24 
    25 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    25 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    26 /* System dependent filesystem routines                                */
    26 /* System dependent filesystem routines                                */
    27 
    27 
    28 #include <unistd.h>
    28 #include <unistd.h>
       
    29 #include <stdlib.h>
    29 #include <sys/stat.h>
    30 #include <sys/stat.h>
    30 #include <sys/types.h>
    31 #include <sys/types.h>
       
    32 
       
    33 #ifdef __FREEBSD__
       
    34 #include <sys/sysctl.h>
       
    35 #endif
    31 
    36 
    32 #include "SDL_error.h"
    37 #include "SDL_error.h"
    33 #include "SDL_stdinc.h"
    38 #include "SDL_stdinc.h"
    34 #include "SDL_filesystem.h"
    39 #include "SDL_filesystem.h"
    35 
    40 
    71 char *
    76 char *
    72 SDL_GetBasePath(void)
    77 SDL_GetBasePath(void)
    73 {
    78 {
    74     char *retval = NULL;
    79     char *retval = NULL;
    75 
    80 
       
    81 #if defined(__FREEBSD__)
       
    82     char fullpath[PATH_MAX];
       
    83     size_t buflen = sizeof (fullpath);
       
    84     int mib[4];
       
    85     mib[0] = CTL_KERN;
       
    86     mib[1] = KERN_PROC;
       
    87     mib[2] = KERN_PROC_PATHNAME;
       
    88     mib[3] = -1;
       
    89     if (sysctl(mib, 4, fullpath, &buflen, NULL, 0) != -1) {
       
    90         retval = SDL_strdup(fullpath);
       
    91         if (!retval) {
       
    92             SDL_OutOfMemory();
       
    93             return NULL;
       
    94         }
       
    95     }
       
    96 #elif defined(__SOLARIS__)
       
    97     const char *path = getexecname();
       
    98     if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
       
    99         retval = SDL_strdup(fullpath);
       
   100         if (!retval) {
       
   101             SDL_OutOfMemory();
       
   102             return NULL;
       
   103         }
       
   104     }
       
   105 #endif
       
   106 
    76     /* is a Linux-style /proc filesystem available? */
   107     /* is a Linux-style /proc filesystem available? */
    77     if (access("/proc", F_OK) == 0) {
   108     if (!retval && (access("/proc", F_OK) == 0)) {
    78         retval = readSymLink("/proc/self/exe");
   109         #if defined(__FREEBSD__)
       
   110         retval = readSymLink("/proc/curproc/file");
       
   111         #elif defined(__NETBSD__)
       
   112         retval = readSymLink("/proc/curproc/exe");
       
   113         #else
       
   114         retval = readSymLink("/proc/self/exe");  /* linux. */
       
   115         #endif
    79         if (retval == NULL) {
   116         if (retval == NULL) {
    80             /* older kernels don't have /proc/self ... try PID version... */
   117             /* older kernels don't have /proc/self ... try PID version... */
    81             char path[64];
   118             char path[64];
    82             const int rc = (int) SDL_snprintf(path, sizeof(path),
   119             const int rc = (int) SDL_snprintf(path, sizeof(path),
    83                                               "/proc/%llu/exe",
   120                                               "/proc/%llu/exe",