Subversion Repositories eduke32

Rev

Rev 5005 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5005 Rev 5037
Line 25... Line 25...
25
# include <io.h>
25
# include <io.h>
26
#else
26
#else
27
# include <dirent.h>
27
# include <dirent.h>
28
#endif
28
#endif
29
29
30
#if defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
30
#if defined __linux || defined EDUKE32_BSD
31
# include <libgen.h> // for dirname()
31
# include <libgen.h> // for dirname()
32
#endif
32
#endif
33
#if defined(__FreeBSD__)
33
#if defined __FreeBSD__
-
 
34
# include <limits.h> // for PATH_MAX
34
# include <sys/sysctl.h> // for sysctl() to get path to executable
35
# include <sys/sysctl.h> // for sysctl() to get path to executable
35
#endif
36
#endif
36
37
37
#include "baselayer.h"
38
#include "baselayer.h"
38
39
Line 302... Line 303...
302
                dir = Bstrdup(appdir);
303
                dir = Bstrdup(appdir);
303
    }
304
    }
304
305
305
#elif defined EDUKE32_OSX
306
#elif defined EDUKE32_OSX
306
    dir = osx_getappdir();
307
    dir = osx_getappdir();
-
 
308
#elif defined __FreeBSD__
-
 
309
    // the sysctl should also work when /proc/ is not mounted (which seems to
-
 
310
    // be common on FreeBSD), so use it..
-
 
311
    char buf[PATH_MAX] = {0};
-
 
312
    int name[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
-
 
313
    size_t len = sizeof(buf)-1;
-
 
314
    int ret = sysctl(name, sizeof(name)/sizeof(name[0]), buf, &len, NULL, 0);
-
 
315
    if(ret == 0 && buf[0] != '\0') {
-
 
316
        // again, remove executable name with dirname()
-
 
317
        // on FreeBSD dirname() seems to use some internal buffer
-
 
318
        dir = strdup(dirname(buf));
-
 
319
    }
307
#elif defined(__linux) || defined(__NetBSD__) || defined(__OpenBSD__)
320
#elif defined __linux || defined EDUKE32_BSD
308
    char buf[PATH_MAX] = {0};
321
    char buf[PATH_MAX] = {0};
309
    char buf2[PATH_MAX] = {0};
322
    char buf2[PATH_MAX] = {0};
310
#  ifdef __linux
323
#  ifdef __linux
311
    Bsnprintf(buf, sizeof(buf), "/proc/%d/exe", getpid());
324
    Bsnprintf(buf, sizeof(buf), "/proc/%d/exe", getpid());
312
#  else // the BSDs.. except for FreeBSD which has a sysctl
325
#  else // the BSDs.. except for FreeBSD which has a sysctl
Line 317... Line 330...
317
        // remove executable name with dirname(3)
330
        // remove executable name with dirname(3)
318
        // on Linux, dirname() will modify buf2 (cutting off executable name) and return it
331
        // on Linux, dirname() will modify buf2 (cutting off executable name) and return it
319
        // on FreeBSD it seems to use some internal buffer instead.. anyway, just strdup()
332
        // on FreeBSD it seems to use some internal buffer instead.. anyway, just strdup()
320
        dir = Bstrdup(dirname(buf2));
333
        dir = Bstrdup(dirname(buf2));
321
    }
334
    }
322
#elif defined(__FreeBSD__)
-
 
323
    // the sysctl should also work when /proc/ is not mounted (which seems to
-
 
324
    // be common on FreeBSD), so use it..
-
 
325
    char buf[PATH_MAX] = {0};
-
 
326
    int name[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
-
 
327
    size_t len = sizeof(buf)-1;
-
 
328
    int ret = sysctl(name, sizeof(name)/sizeof(name[0]), buf, &len, NULL, 0);
-
 
329
    if(ret == 0 && buf[0] != '\0') {
-
 
330
        // again, remove executable name with dirname()
-
 
331
        // on FreeBSD dirname() seems to use some internal buffer
-
 
332
        dir = strdup(dirname(buf));
-
 
333
    }
-
 
334
#endif
335
#endif
335
336
336
    return dir;
337
    return dir;
337
}
338
}
338
339