diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-16 13:11:09 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-16 13:11:09 -0400 |
commit | 88ff81d9def5efe69cbaf91aa41906177ba7dde9 (patch) | |
tree | cb9f149e438bcd1f18d8c1eb5d8be6b0a22f58a4 /testing/toxic/configdir.c | |
parent | c5af8f44a9d040a0bbe0442ec074d9fc8562dd32 (diff) |
Passed everything through astyle.
Diffstat (limited to 'testing/toxic/configdir.c')
-rw-r--r-- | testing/toxic/configdir.c | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/testing/toxic/configdir.c b/testing/toxic/configdir.c index 18e211ce..1a62e8ed 100644 --- a/testing/toxic/configdir.c +++ b/testing/toxic/configdir.c | |||
@@ -50,6 +50,7 @@ char *get_user_config_dir(void) | |||
50 | BOOL ok; | 50 | BOOL ok; |
51 | 51 | ||
52 | ok = SHGetSpecialFolderPathA(NULL, appdata, CSIDL_PROFILE, TRUE); | 52 | ok = SHGetSpecialFolderPathA(NULL, appdata, CSIDL_PROFILE, TRUE); |
53 | |||
53 | if (!ok) { | 54 | if (!ok) { |
54 | return NULL; | 55 | return NULL; |
55 | } | 56 | } |
@@ -72,13 +73,16 @@ char *get_user_config_dir(void) | |||
72 | int rc; | 73 | int rc; |
73 | 74 | ||
74 | rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf); | 75 | rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf); |
76 | |||
75 | if (rc == 0) { | 77 | if (rc == 0) { |
76 | home = pwd.pw_dir; | 78 | home = pwd.pw_dir; |
77 | } else { | 79 | } else { |
78 | home = getenv("HOME"); | 80 | home = getenv("HOME"); |
81 | |||
79 | if (home == NULL) { | 82 | if (home == NULL) { |
80 | return NULL; | 83 | return NULL; |
81 | } | 84 | } |
85 | |||
82 | /* env variables can be tainted */ | 86 | /* env variables can be tainted */ |
83 | snprintf(buf, sizeof(buf), "%s", home); | 87 | snprintf(buf, sizeof(buf), "%s", home); |
84 | home = buf; | 88 | home = buf; |
@@ -87,6 +91,7 @@ char *get_user_config_dir(void) | |||
87 | # if defined(__APPLE__) | 91 | # if defined(__APPLE__) |
88 | len = strlen(home) + strlen("/Library/Application Support") + 1; | 92 | len = strlen(home) + strlen("/Library/Application Support") + 1; |
89 | user_config_dir = malloc(len); | 93 | user_config_dir = malloc(len); |
94 | |||
90 | if (user_config_dir == NULL) { | 95 | if (user_config_dir == NULL) { |
91 | return NULL; | 96 | return NULL; |
92 | } | 97 | } |
@@ -95,6 +100,7 @@ char *get_user_config_dir(void) | |||
95 | # else /* __APPLE__ */ | 100 | # else /* __APPLE__ */ |
96 | len = strlen(home) + strlen("/.config") + 1; | 101 | len = strlen(home) + strlen("/.config") + 1; |
97 | user_config_dir = malloc(len); | 102 | user_config_dir = malloc(len); |
103 | |||
98 | if (user_config_dir == NULL) { | 104 | if (user_config_dir == NULL) { |
99 | return NULL; | 105 | return NULL; |
100 | } | 106 | } |
@@ -111,44 +117,45 @@ char *get_user_config_dir(void) | |||
111 | * Creates the config directory. | 117 | * Creates the config directory. |
112 | */ | 118 | */ |
113 | int create_user_config_dir(char *path) | 119 | int create_user_config_dir(char *path) |
114 | { | 120 | { |
115 | 121 | ||
116 | int mkdir_err; | 122 | int mkdir_err; |
117 | 123 | ||
118 | #ifdef WIN32 | 124 | #ifdef WIN32 |
119 | 125 | ||
120 | char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1); | 126 | char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1); |
121 | strcpy(fullpath, path); | 127 | strcpy(fullpath, path); |
122 | strcat(fullpath, CONFIGDIR); | 128 | strcat(fullpath, CONFIGDIR); |
123 | 129 | ||
124 | mkdir_err = _mkdir(fullpath); | 130 | mkdir_err = _mkdir(fullpath); |
125 | struct __stat64 buf; | 131 | struct __stat64 buf; |
126 | if (mkdir_err && (errno != EEXIST || _wstat64(fullpath, &buf) || !S_ISDIR(buf.st_mode))) { | ||
127 | free(fullpath); | ||
128 | return -1; | ||
129 | } | ||
130 | 132 | ||
131 | #else | 133 | if (mkdir_err && (errno != EEXIST || _wstat64(fullpath, &buf) || !S_ISDIR(buf.st_mode))) { |
134 | free(fullpath); | ||
135 | return -1; | ||
136 | } | ||
132 | 137 | ||
133 | mkdir_err = mkdir(path, 0700); | 138 | #else |
134 | struct stat buf; | ||
135 | 139 | ||
136 | if(mkdir_err && (errno != EEXIST || stat(path, &buf) || !S_ISDIR(buf.st_mode))) { | 140 | mkdir_err = mkdir(path, 0700); |
137 | return -1; | 141 | struct stat buf; |
138 | } | ||
139 | 142 | ||
140 | char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1); | 143 | if (mkdir_err && (errno != EEXIST || stat(path, &buf) || !S_ISDIR(buf.st_mode))) { |
141 | strcpy(fullpath, path); | 144 | return -1; |
142 | strcat(fullpath, CONFIGDIR); | 145 | } |
143 | 146 | ||
144 | mkdir_err = mkdir(fullpath, 0700); | 147 | char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1); |
148 | strcpy(fullpath, path); | ||
149 | strcat(fullpath, CONFIGDIR); | ||
150 | |||
151 | mkdir_err = mkdir(fullpath, 0700); | ||
152 | |||
153 | if (mkdir_err && (errno != EEXIST || stat(fullpath, &buf) || !S_ISDIR(buf.st_mode))) { | ||
154 | free(fullpath); | ||
155 | return -1; | ||
156 | } | ||
145 | 157 | ||
146 | if(mkdir_err && (errno != EEXIST || stat(fullpath, &buf) || !S_ISDIR(buf.st_mode))) { | 158 | #endif |
147 | free(fullpath); | 159 | free(fullpath); |
148 | return -1; | 160 | return 0; |
149 | } | ||
150 | |||
151 | #endif | ||
152 | free(fullpath); | ||
153 | return 0; | ||
154 | } | 161 | } |