MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / getDotfilePath

Function getDotfilePath

src/redis-cli.c:169–190  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

167 * obtained for some error), or an SDS string that must be freed by
168 * the user. */
169static 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'))

Callers 2

cliLoadPreferencesFunction · 0.85
replFunction · 0.85

Calls 3

sdsnewFunction · 0.85
sdscatprintfFunction · 0.85
sdsemptyFunction · 0.85

Tested by

no test coverage detected