Skip to content

Commit

Permalink
squashme: get rid of CURL_DOTSCORE_ macros (findfile parameter)
Browse files Browse the repository at this point in the history
It's cleaner to strcmp .curlrc in the findfile function since that's the
only filename they applied to.
  • Loading branch information
jay committed Oct 17, 2023
1 parent 61d02f9 commit 84f3810
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
31 changes: 14 additions & 17 deletions src/tool_findfile.c
Expand Up @@ -98,41 +98,38 @@ 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
*
* On Windows if 'fname' is .curlrc then each location is checked for .curlrc
* and _curlrc for legacy reasons.
*
* When XDG locations are searched, if 'fname' has a leading dot and is just a
* filename and not a relative path, then the filename is first searched for
* with the dot stripped. For example, if 'fname' is .curlrc and the
* $XDG_CONFIG_HOME location is being searched, it happens in this order:
*
* $XDG_CONFIG_HOME/curlrc
* $XDG_CONFIG_HOME/.curlrc
* $XDG_CONFIG_HOME/_curlrc (if dotscore is true)
*
* The behavior of 'dotscore' is controlled by the macros below.
*
* CURL_DOTSCORE_ON: if 'fname' has a leading dot and is just a filename and
* not a relative path, and is not found in a location then try again with an
* underscore prefix. For example, if filename .curlrc is not found in a
* location then check for _curlrc in the same location before trying the next
* location for .curlrc.
*
* CURL_DOTSCORE_OFF: do not try an alternate underscore filename.
*
* CURL_DOTSCORE_DEFAULT: OS dependent, either ON or OFF.
* $XDG_CONFIG_HOME/_curlrc (only if 'fname' is .curlrc on Windows)
*/
char *findfile(const char *fname, bool dotscore)
char *findfile(const char *fname)
{
int i;
bool dotscore;
bool fname_is_relative_path;
bool xdg_main_found = FALSE;
DEBUGASSERT(fname && fname[0]);
DEBUGASSERT(!dotscore || (fname[0] == '.'));

if(!fname[0] || (dotscore && fname[0] != '.'))
if(!fname[0])
return NULL;

#ifdef WIN32
/* dotscore means also check for fname with a leading underscore: _curlrc */
dotscore = !strcmp(".curlrc", fname);
#else
dotscore = false;
#endif

fname_is_relative_path = !!strpbrk(fname, "\\/");

/* assume an fname like .ssh/foo with underscore checking is a mistake */
DEBUGASSERT(!dotscore || !fname_is_relative_path);

for(i = 0; conf_list[i].env; i++) {
Expand Down
14 changes: 1 addition & 13 deletions src/tool_findfile.h
Expand Up @@ -25,18 +25,6 @@
***************************************************************************/
#include "tool_setup.h"

/* These macros are for findfile() parameter 'dotscore' and documented above
* the function definition.
*/
#define CURL_DOTSCORE_ON TRUE /* look for underscore-prefixed name too */
#define CURL_DOTSCORE_OFF FALSE

#ifdef WIN32
#define CURL_DOTSCORE_DEFAULT CURL_DOTSCORE_ON
#else
#define CURL_DOTSCORE_DEFAULT CURL_DOTSCORE_OFF
#endif

char *findfile(const char *fname, bool dotscore);
char *findfile(const char *fname);

#endif /* HEADER_CURL_TOOL_HOMEDIR_H */
2 changes: 1 addition & 1 deletion src/tool_operate.c
Expand Up @@ -2006,7 +2006,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,

if((use_proto == proto_scp || use_proto == proto_sftp) &&
!config->insecure_ok) {
char *known = findfile(".ssh/known_hosts", CURL_DOTSCORE_OFF);
char *known = findfile(".ssh/known_hosts");
if(known) {
/* new in curl 7.19.6 */
result = res_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, known);
Expand Down
5 changes: 3 additions & 2 deletions src/tool_parsecfg.c
Expand Up @@ -88,8 +88,9 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
char *pathalloc = NULL;

if(!filename) {
/* NULL means load .curlrc from homedir! */
char *curlrc = findfile(".curlrc", CURL_DOTSCORE_DEFAULT);
/* NULL means load .curlrc from homedir.
On Windows a findfile check for .curlrc also checks for _curlrc */
char *curlrc = findfile(".curlrc");
if(curlrc) {
file = fopen(curlrc, FOPEN_READTEXT);
if(!file) {
Expand Down

0 comments on commit 84f3810

Please sign in to comment.