diff options
-rw-r--r-- | testing/toxic/configdir.c | 36 | ||||
-rw-r--r-- | testing/toxic/configdir.h | 2 | ||||
-rw-r--r-- | testing/toxic/main.c | 1 |
3 files changed, 15 insertions, 24 deletions
diff --git a/testing/toxic/configdir.c b/testing/toxic/configdir.c index 7d11d020..d91d0804 100644 --- a/testing/toxic/configdir.c +++ b/testing/toxic/configdir.c | |||
@@ -56,10 +56,8 @@ char *get_user_config_dir(void) | |||
56 | ) | 56 | ) |
57 | if (!result) return NULL; | 57 | if (!result) return NULL; |
58 | 58 | ||
59 | user_config_dir = malloc(strlen(appdata) + 1); | 59 | user_config_dir = strdup(appdata); |
60 | if (user_config_dir) { | 60 | |
61 | strcpy(user_config_dir, appdata); | ||
62 | } | ||
63 | return user_config_dir; | 61 | return user_config_dir; |
64 | 62 | ||
65 | #elif defined __APPLE__ | 63 | #elif defined __APPLE__ |
@@ -78,10 +76,7 @@ char *get_user_config_dir(void) | |||
78 | #else | 76 | #else |
79 | 77 | ||
80 | if (getenv("XDG_CONFIG_HOME")) { | 78 | if (getenv("XDG_CONFIG_HOME")) { |
81 | user_config_dir = malloc(strlen(getenv("XDG_CONFIG_HOME")) + 1); | 79 | user_config_dir = strdup(getenv("XDG_CONFIG_HOME")); |
82 | if (user_config_dir) { | ||
83 | strcpy(user_config_dir, getenv("XDG_CONFIG_HOME")); | ||
84 | } | ||
85 | } else { | 80 | } else { |
86 | user_config_dir = malloc(strlen(getenv("HOME")) + strlen("/.config") + 1); | 81 | user_config_dir = malloc(strlen(getenv("HOME")) + strlen("/.config") + 1); |
87 | if (user_config_dir) { | 82 | if (user_config_dir) { |
@@ -109,12 +104,10 @@ int create_user_config_dir(char *path) | |||
109 | strcat(fullpath, CONFIGDIR); | 104 | strcat(fullpath, CONFIGDIR); |
110 | 105 | ||
111 | mkdir_err = _mkdir(fullpath); | 106 | mkdir_err = _mkdir(fullpath); |
112 | 107 | struct __stat64 buf; | |
113 | if (mkdir_err) { | 108 | if (mkdir_err && (errno != EEXIST || _wstat64(fullpath, &buf) || !S_ISDIR(buf.st_mode))) { |
114 | if(errno != EEXIST) return -1; | 109 | free(fullpath); |
115 | struct _stat buf; | 110 | return -1; |
116 | if(_wstat64(fullpath, &buf)) return -1; | ||
117 | if(!S_ISDIR(buf.st_mode)) return -1; | ||
118 | } | 111 | } |
119 | 112 | ||
120 | #else | 113 | #else |
@@ -122,10 +115,8 @@ int create_user_config_dir(char *path) | |||
122 | mkdir_err = mkdir(path, 0700); | 115 | mkdir_err = mkdir(path, 0700); |
123 | struct stat buf; | 116 | struct stat buf; |
124 | 117 | ||
125 | if(mkdir_err) { | 118 | if(mkdir_err && (errno != EEXIST || stat(path, &buf) || !S_ISDIR(buf.st_mode))) { |
126 | if(errno != EEXIST) return -1; | 119 | return -1; |
127 | if(stat(path, &buf)) return -1; | ||
128 | if(!S_ISDIR(buf.st_mode)) return -1; | ||
129 | } | 120 | } |
130 | 121 | ||
131 | char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1); | 122 | char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1); |
@@ -134,13 +125,12 @@ int create_user_config_dir(char *path) | |||
134 | 125 | ||
135 | mkdir_err = mkdir(fullpath, 0700); | 126 | mkdir_err = mkdir(fullpath, 0700); |
136 | 127 | ||
137 | if(mkdir_err) { | 128 | if(mkdir_err && (errno != EEXIST || stat(fullpath, &buf) || !S_ISDIR(buf.st_mode))) { |
138 | if(errno != EEXIST) return -1; | 129 | free(fullpath); |
139 | if(stat(fullpath, &buf)) return -1; | 130 | return -1; |
140 | if(!S_ISDIR(buf.st_mode)) return -1; | ||
141 | } | 131 | } |
142 | 132 | ||
143 | #endif | 133 | #endif |
144 | 134 | ||
145 | return 0; | 135 | return 0; |
146 | } \ No newline at end of file | 136 | } |
diff --git a/testing/toxic/configdir.h b/testing/toxic/configdir.h index d9837d77..fad949cf 100644 --- a/testing/toxic/configdir.h +++ b/testing/toxic/configdir.h | |||
@@ -30,4 +30,4 @@ | |||
30 | 30 | ||
31 | char *get_user_config_dir(void); | 31 | char *get_user_config_dir(void); |
32 | 32 | ||
33 | int create_user_config_dir(char *path); \ No newline at end of file | 33 | int create_user_config_dir(char *path); |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index cb0d9e19..13577cc7 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -370,6 +370,7 @@ int main(int argc, char *argv[]) | |||
370 | init_term(); | 370 | init_term(); |
371 | init_tox(); | 371 | init_tox(); |
372 | load_data(filename); | 372 | load_data(filename); |
373 | free(filename); | ||
373 | init_windows(); | 374 | init_windows(); |
374 | init_window_status(); | 375 | init_window_status(); |
375 | 376 | ||