21 #include "../../SDL_internal.h" 23 #ifdef SDL_FILESYSTEM_UNIX 33 #include <sys/types.h> 37 #if defined(__FREEBSD__) || defined(__OPENBSD__) 38 #include <sys/sysctl.h> 47 #if !defined(__QNXNTO__) 49 readSymLink(
const char *
path)
65 rc = readlink(path, retval, len);
68 }
else if (rc < len) {
86 #if defined(__FREEBSD__) 87 char fullpath[PATH_MAX];
88 size_t buflen =
sizeof (fullpath);
89 const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
98 #if defined(__OPENBSD__) 101 const int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
102 if (sysctl(mib, 4,
NULL, &len,
NULL, 0) != -1) {
108 sysctl(mib, 4, retvalargs, &len,
NULL, 0);
111 realpath(retvalargs[0], retval);
116 #if defined(__SOLARIS__) 117 const char *path = getexecname();
118 if ((path !=
NULL) && (path[0] ==
'/')) {
128 if (!retval && (
access(
"/proc", F_OK) == 0)) {
132 #if defined(__FREEBSD__) 133 retval = readSymLink(
"/proc/curproc/file");
134 #elif defined(__NETBSD__) 135 retval = readSymLink(
"/proc/curproc/exe");
136 #elif defined(__QNXNTO__) 139 retval = readSymLink(
"/proc/self/exe");
140 if (retval ==
NULL) {
145 (
unsigned long long) getpid());
146 if ( (rc > 0) && (rc <
sizeof(
path)) ) {
147 retval = readSymLink(path);
156 if (retval !=
NULL) {
166 if (retval !=
NULL) {
168 char *ptr = (
char *)
SDL_realloc(retval, strlen(retval) + 1);
186 const char *envr =
SDL_getenv(
"XDG_DATA_HOME");
205 SDL_SetError(
"neither XDG_DATA_HOME nor HOME environment is set");
208 append =
"/.local/share/";
214 if (envr[len - 1] ==
'/')
225 SDL_snprintf(retval, len,
"%s%s%s/%s/", envr, append, org, app);
227 SDL_snprintf(retval, len,
"%s%s%s/", envr, append, app);
230 for (ptr = retval+1; *ptr; ptr++) {
233 if (mkdir(retval, 0700) != 0 && errno != EEXIST)
238 if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
240 SDL_SetError(
"Couldn't create directory '%s': '%s'", retval, strerror(errno));
#define SDL_InvalidParamError(param)
GLuint GLint GLboolean GLint GLenum access
#define SDL_OutOfMemory()
Include file for filesystem SDL API functions.
#define SDL_arraysize(array)
GLsizei const GLchar *const * path
char * SDL_GetBasePath(void)
Get the path where the application resides.
#define SDL_LoadFile(file, datasize)