Return the name of the dotfile for the specified 'dotfilename'. * Normally it just concatenates user $HOME to the file specified * in 'dotfilename'. However if the environment variable 'envoverride' * is set, its value is taken as the path. * * The function returns NULL (if the file is /dev/null or cannot be * obtained for some error), or an SDS string that must be freed by * the user. */
| 167 | * obtained for some error), or an SDS string that must be freed by |
| 168 | * the user. */ |
| 169 | static sds getDotfilePath(char *envoverride, char *dotfilename) { |
| 170 | char *path = NULL; |
| 171 | sds dotPath = NULL; |
| 172 | |
| 173 | /* Check the env for a dotfile override. */ |
| 174 | path = getenv(envoverride); |
| 175 | if (path != NULL && *path != '\0') { |
| 176 | if (!strcmp("/dev/null", path)) { |
| 177 | return NULL; |
| 178 | } |
| 179 | |
| 180 | /* If the env is set, return it. */ |
| 181 | dotPath = sdsnew(path); |
| 182 | } else { |
| 183 | char *home = getenv("HOME"); |
| 184 | if (home != NULL && *home != '\0') { |
| 185 | /* If no override is set use $HOME/<dotfilename>. */ |
| 186 | dotPath = sdscatprintf(sdsempty(), "%s/%s", home, dotfilename); |
| 187 | } |
| 188 | } |
| 189 | return dotPath; |
| 190 | } |
| 191 | |
| 192 | /* URL-style percent decoding. */ |
| 193 | #define isHexChar(c) (isdigit(c) || (c >= 'a' && c <= 'f')) |
no test coverage detected