MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_GetBasePath

Function SDL_GetBasePath

deps/SDL2/src/filesystem/unix/SDL_sysfilesystem.c:81–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79#endif
80
81char *
82SDL_GetBasePath(void)
83{
84 char *retval = NULL;
85
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 };
90 if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
91 retval = SDL_strdup(fullpath);
92 if (!retval) {
93 SDL_OutOfMemory();
94 return NULL;
95 }
96 }
97#endif
98#if defined(__OPENBSD__)
99 char **retvalargs;
100 size_t len;
101 const int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
102 if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
103 retvalargs = SDL_malloc(len);
104 if (!retvalargs) {
105 SDL_OutOfMemory();
106 return NULL;
107 }
108 sysctl(mib, 4, retvalargs, &len, NULL, 0);
109 retval = SDL_malloc(PATH_MAX + 1);
110 if (retval)
111 realpath(retvalargs[0], retval);
112
113 SDL_free(retvalargs);
114 }
115#endif
116#if defined(__SOLARIS__)
117 const char *path = getexecname();
118 if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
119 retval = SDL_strdup(path);
120 if (!retval) {
121 SDL_OutOfMemory();
122 return NULL;
123 }
124 }
125#endif
126
127 /* is a Linux-style /proc filesystem available? */
128 if (!retval && (access("/proc", F_OK) == 0)) {
129 /* !!! FIXME: after 2.0.6 ships, let's delete this code and just
130 use the /proc/%llu version. There's no reason to have
131 two copies of this plus all the #ifdefs. --ryan. */
132#if defined(__FREEBSD__)
133 retval = readSymLink("/proc/curproc/file");
134#elif defined(__NETBSD__)
135 retval = readSymLink("/proc/curproc/exe");
136#elif defined(__QNXNTO__)
137 retval = SDL_LoadFile("/proc/self/exefile", NULL);
138#else

Callers 1

mainFunction · 0.50

Calls 8

SDL_strdupFunction · 0.85
SDL_mallocFunction · 0.85
SDL_freeFunction · 0.85
readSymLinkFunction · 0.85
SDL_LoadFileFunction · 0.85
SDL_snprintfFunction · 0.85
SDL_strrchrFunction · 0.85
SDL_reallocFunction · 0.85

Tested by 1

mainFunction · 0.40