mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
macos.c: update the default path retriaval
- added system_default_directory() - both system_default_directory() and system_default_filename() now use the helper system_default_path_append() - less safer compared to windows.c, assuming the OS is stricter on which environment variables exist! [Dirk Hohndel: switched filename to be dynamically allocated to avoid possible buffer overflow] Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
6cddf1d720
commit
ed98d3bc60
1 changed files with 42 additions and 10 deletions
52
macos.c
52
macos.c
|
@ -43,18 +43,50 @@ bool subsurface_ignore_font(const char *font)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *system_default_path_append(const char *append)
|
||||||
|
{
|
||||||
|
const char *home = getenv("HOME");
|
||||||
|
const char *path = "/Library/Application Support/Subsurface";
|
||||||
|
|
||||||
|
int len = strlen(home) + strlen(path) + 1;
|
||||||
|
if (append)
|
||||||
|
len += strlen(append) + 1;
|
||||||
|
|
||||||
|
char *buffer = (char *)malloc(len);
|
||||||
|
memset(buffer, 0, len);
|
||||||
|
strcat(buffer, home);
|
||||||
|
strcat(buffer, path);
|
||||||
|
if (append) {
|
||||||
|
strcat(buffer, "/");
|
||||||
|
strcat(buffer, append);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *system_default_directory(void)
|
||||||
|
{
|
||||||
|
static const char *path = NULL;
|
||||||
|
if (!path)
|
||||||
|
path = system_default_path_append(NULL);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
const char *system_default_filename(void)
|
const char *system_default_filename(void)
|
||||||
{
|
{
|
||||||
const char *home, *user;
|
static char *filename = NULL;
|
||||||
char *buffer;
|
if (!filename) {
|
||||||
int len;
|
const char *user = getenv("LOGNAME");
|
||||||
|
if (same_string(user, ""))
|
||||||
home = getenv("HOME");
|
user = "username";
|
||||||
user = getenv("LOGNAME");
|
filename = malloc(strlen(user) + 5);
|
||||||
len = strlen(home) + strlen(user) + 45;
|
strcat(filename, user);
|
||||||
buffer = malloc(len);
|
strcat(filename, ".xml");
|
||||||
snprintf(buffer, len, "%s/Library/Application Support/Subsurface/%s.xml", home, user);
|
}
|
||||||
return buffer;
|
static const char *path = NULL;
|
||||||
|
if (!path)
|
||||||
|
path = system_default_path_append(filename);
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue