* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
struct finder {
const char *env;
const char *append;
+ bool withoutdot;
};
+/* The order of the variables below is important, as the index number is used
+ in the findfile() function */
static const struct finder list[] = {
- { "CURL_HOME", NULL },
- { "XDG_CONFIG_HOME", NULL },
- { "HOME", NULL },
+ { "CURL_HOME", NULL, FALSE },
+ { "XDG_CONFIG_HOME", NULL, FALSE }, /* index == 1, used in the code */
+ { "HOME", NULL, FALSE },
#ifdef WIN32
- { "USERPROFILE", NULL },
- { "APPDATA", NULL },
- { "USERPROFILE", "\\Application Data"},
+ { "USERPROFILE", NULL, FALSE },
+ { "APPDATA", NULL, FALSE },
+ { "USERPROFILE", "\\Application Data", FALSE},
#endif
- { NULL, NULL }
+ /* these are for .curlrc if XDG_CONFIG_HOME is not defined */
+ { "CURL_HOME", "/.config", TRUE },
+ { "HOME", "/.config", TRUE },
+
+ { NULL, NULL, FALSE }
};
static char *checkhome(const char *home, const char *fname, bool dotscore)
* the given file to be accessed there, then it is a match.
* 2. Non-windows: try getpwuid
*/
-char *findfile(const char *fname, bool dotscore)
+char *findfile(const char *fname, int dotscore)
{
int i;
+ bool xdg = FALSE;
DEBUGASSERT(fname && fname[0]);
- DEBUGASSERT(!dotscore || (fname[0] == '.'));
+ DEBUGASSERT((dotscore != 1) || (fname[0] == '.'));
if(!fname[0])
return NULL;
char *home = curl_getenv(list[i].env);
if(home) {
char *path;
+ const char *filename = fname;
+ if(i == 1 /* XDG_CONFIG_HOME */)
+ xdg = TRUE;
if(!home[0]) {
curl_free(home);
continue;
return NULL;
home = c;
}
- path = checkhome(home, fname, dotscore);
+ if(list[i].withoutdot) {
+ if(!dotscore || xdg)
+ /* this is not looking for .curlrc, or the XDG_CONFIG_HOME was
+ defined so we skip the extended check */
+ continue;
+ filename++; /* move past the leading dot */
+ dotscore = 0; /* disable it for this check */
+ }
+ path = checkhome(home, filename, dotscore ? dotscore - 1 : 0);
curl_free(home);
if(path)
return path;
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
***************************************************************************/
#include "tool_setup.h"
-char *findfile(const char *fname, bool dotscore);
+#ifdef WIN32
+#define CURLRC_DOTSCORE 2 /* look for underscore-prefixed name too */
+#else
+#define CURLRC_DOTSCORE 1 /* regular .curlrc check */
+#endif
+
+char *findfile(const char *fname, int dotscore);
#endif /* HEADER_CURL_TOOL_HOMEDIR_H */
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
int rc = 0;
struct OperationConfig *operation = global->last;
char *pathalloc = NULL;
-#ifdef WIN32
-#define DOTSCORE TRUE /* look for underscore-prefixed name too */
-#else
-#define DOTSCORE FALSE
-#endif
if(!filename) {
/* NULL means load .curlrc from homedir! */
- char *curlrc = findfile(".curlrc", DOTSCORE);
+ char *curlrc = findfile(".curlrc", CURLRC_DOTSCORE);
if(curlrc) {
file = fopen(curlrc, FOPEN_READTEXT);
if(!file) {