21 #include <dirent.h> |
21 #include <dirent.h> |
22 #include <time.h> |
22 #include <time.h> |
23 #include <errno.h> |
23 #include <errno.h> |
24 #include <limits.h> |
24 #include <limits.h> |
25 |
25 |
|
26 #include <sys/types.h> |
|
27 #include <sys/sysctl.h> |
|
28 |
|
29 |
26 #if PHYSFS_PLATFORM_LINUX && !defined(PHYSFS_HAVE_MNTENT_H) |
30 #if PHYSFS_PLATFORM_LINUX && !defined(PHYSFS_HAVE_MNTENT_H) |
27 #define PHYSFS_HAVE_MNTENT_H 1 |
31 #define PHYSFS_HAVE_MNTENT_H 1 |
28 #elif PHYSFS_PLATFORM_SOLARIS && !defined(PHYSFS_HAVE_SYS_MNTTAB_H) |
32 #elif PHYSFS_PLATFORM_SOLARIS && !defined(PHYSFS_HAVE_SYS_MNTTAB_H) |
29 #define PHYSFS_HAVE_SYS_MNTTAB_H 1 |
33 #define PHYSFS_HAVE_SYS_MNTTAB_H 1 |
30 #elif PHYSFS_PLATFORM_BSD && !defined(PHYSFS_HAVE_SYS_UCRED_H) |
34 #elif PHYSFS_PLATFORM_BSD && !defined(PHYSFS_HAVE_SYS_UCRED_H) |
249 /* Try to avoid using argv0 unless forced to. Try system-specific stuff. */ |
253 /* Try to avoid using argv0 unless forced to. Try system-specific stuff. */ |
250 |
254 |
251 #if PHYSFS_PLATFORM_FREEBSD |
255 #if PHYSFS_PLATFORM_FREEBSD |
252 { |
256 { |
253 char fullpath[PATH_MAX]; |
257 char fullpath[PATH_MAX]; |
254 size_t buflen = sizeof (fullpath); |
258 size_t buflen = sizeof (fullpath) - 1; |
255 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
259 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
256 if (sysctl(mib, 4, fullpath, &buflen, NULL, 0) != -1) |
260 if (sysctl(mib, 4, fullpath, &buflen, NULL, 0) != -1) { |
|
261 int pathlen = strlen(fullpath); |
|
262 fullpath[pathlen] = '/'; |
|
263 fullpath[pathlen + 1] = 0; |
257 retval = __PHYSFS_strdup(fullpath); |
264 retval = __PHYSFS_strdup(fullpath); |
|
265 } |
258 } |
266 } |
259 #elif PHYSFS_PLATFORM_SOLARIS |
267 #elif PHYSFS_PLATFORM_SOLARIS |
260 { |
268 { |
261 const char *path = getexecname(); |
269 const char *path = getexecname(); |
262 if ((path != NULL) && (path[0] == '/')) /* must be absolute path... */ |
270 if ((path != NULL) && (path[0] == '/')) /* must be absolute path... */ |