23 #ifdef SDL_FILESYSTEM_UNIX
37 #include <sys/sysctl.h>
41 #include "SDL_stdinc.h"
45 readSymLink(
const char *
path)
61 rc = readlink(path, retval, len);
64 }
else if (rc < len) {
82 #if defined(__FREEBSD__)
84 size_t buflen =
sizeof (fullpath);
85 const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
93 #elif defined(__SOLARIS__)
94 const char *path = getexecname();
95 if ((path !=
NULL) && (path[0] ==
'/')) {
105 if (!retval && (
access(
"/proc", F_OK) == 0)) {
106 #if defined(__FREEBSD__)
107 retval = readSymLink(
"/proc/curproc/file");
108 #elif defined(__NETBSD__)
109 retval = readSymLink(
"/proc/curproc/exe");
111 retval = readSymLink(
"/proc/self/exe");
113 if (retval ==
NULL) {
118 (
unsigned long long) getpid());
119 if ( (rc > 0) && (rc <
sizeof(
path)) ) {
120 retval = readSymLink(path);
128 if (retval !=
NULL) {
138 if (retval !=
NULL) {
140 char *ptr = (
char *)
SDL_realloc(retval, strlen(retval) + 1);
158 const char *envr =
SDL_getenv(
"XDG_DATA_HOME");
169 SDL_SetError(
"neither XDG_DATA_HOME nor HOME environment is set");
172 append =
"/.local/share/";
178 if (envr[len - 1] ==
'/')
188 SDL_snprintf(retval, len,
"%s%s%s/", envr, append, app);
190 for (ptr = retval+1; *ptr; ptr++) {
193 if (mkdir(retval, 0700) != 0 && errno != EEXIST)
198 if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
200 SDL_SetError(
"Couldn't create directory '%s': ", retval, strerror(errno));
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size)
DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c)
DECLSPEC void SDLCALL SDL_free(void *mem)
DECLSPEC char *SDLCALL SDL_GetPrefPath(const char *org, const char *app)
Get the user-and-app-specific path where files can be written.
GLsizei const GLchar *const * path
DECLSPEC char *SDLCALL SDL_strdup(const char *str)
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
#define SDL_OutOfMemory()
#define SDL_arraysize(array)
Include file for filesystem SDL API functions.
DECLSPEC char *SDLCALL SDL_getenv(const char *name)
DECLSPEC char *SDLCALL SDL_GetBasePath(void)
Get the path where the application resides.