Browse Source

Merge pull request #2097 from rogers0/PR/fix_hurd

Fix of PATH_MAX for GNU/Hurd
pull/2102/merge
Max Lv 6 years ago
committed by GitHub
parent
commit
0a8d194426
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 5 deletions
  1. 21
      src/utils.c

21
src/utils.c

@ -492,17 +492,28 @@ get_default_conf(void)
{
#ifndef __MINGW32__
static char sysconf[] = "/etc/shadowsocks-libev/config.json";
static char userconf[PATH_MAX] = { 0 };
static char *userconf = NULL;
static int buf_size = 0;
char *conf_home;
conf_home = getenv("XDG_CONFIG_HOME");
// Memory of userconf only gets allocated once, and will not be
// freed. It is used as static buffer.
if (!conf_home) {
strcpy(userconf, getenv("HOME"));
strcat(userconf, "/.config/shadowsocks-libev/config.json");
if (buf_size == 0) {
buf_size = 50 + strlen(getenv("HOME"));
userconf = malloc(buf_size);
}
snprintf(userconf, buf_size, "%s%s", getenv("HOME"),
"/.config/shadowsocks-libev/config.json");
} else {
strcpy(userconf, conf_home);
strcat(userconf, "/shadowsocks-libev/config.json");
if (buf_size == 0) {
buf_size = 50 + strlen(conf_home);
userconf = malloc(buf_size);
}
snprintf(userconf, buf_size, "%s%s", conf_home,
"/shadowsocks-libev/config.json");
}
// Check if the user-specific config exists.

Loading…
Cancel
Save