[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 148/220: curl: use .curlrc (with a dot) on Windows
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 148/220: curl: use .curlrc (with a dot) on Windows as well |
Date: |
Thu, 12 Sep 2019 17:28:28 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit 862393243d16870347e56195e93dc47274e32601
Author: Daniel Stenberg <address@hidden>
AuthorDate: Fri Aug 16 11:31:29 2019 +0200
curl: use .curlrc (with a dot) on Windows as well
Fall-back to _curlrc if the dot-version is missing.
Co-Authored-By: Steve Holme
Closes #4230
---
docs/cmdline-opts/config.d | 2 +-
src/tool_parsecfg.c | 117 +++++++++++++++++++++++++--------------------
2 files changed, 67 insertions(+), 52 deletions(-)
diff --git a/docs/cmdline-opts/config.d b/docs/cmdline-opts/config.d
index ef9894b8e..df3d39220 100644
--- a/docs/cmdline-opts/config.d
+++ b/docs/cmdline-opts/config.d
@@ -40,7 +40,7 @@ Unix-like systems (which returns the home dir given the
current user in your
system). On Windows, it then checks for the APPDATA variable, or as a last
resort the '%USERPROFILE%\\Application Data'.
-2) On windows, if there is no _curlrc file in the home dir, it checks for one
+2) On windows, if there is no .curlrc file in the home dir, it checks for one
in the same dir the curl executable is placed. On Unix-like systems, it will
simply try to load .curlrc from the determined home dir.
diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c
index 8647cafed..9b32e54a0 100644
--- a/src/tool_parsecfg.c
+++ b/src/tool_parsecfg.c
@@ -34,8 +34,6 @@
#include "memdebug.h" /* keep this as LAST include */
-#define CURLRC DOT_CHAR "curlrc"
-
/* only acknowledge colon or equals as separators if the option was not
specified with an initial dash! */
#define ISSEP(x,dash) (!dash && (((x) == '=') || ((x) == ':')))
@@ -43,74 +41,90 @@
static const char *unslashquote(const char *line, char *param);
static char *my_get_line(FILE *fp);
+#ifdef WIN32
+static FILE *execpath(const char *filename)
+{
+ char filebuffer[512];
+ /* Get the filename of our executable. GetModuleFileName is already declared
+ * via inclusions done in setup header file. We assume that we are using
+ * the ASCII version here.
+ */
+ unsigned long len = GetModuleFileNameA(0, filebuffer, sizeof(filebuffer));
+ if(len > 0 && len < sizeof(filebuffer)) {
+ /* We got a valid filename - get the directory part */
+ char *lastdirchar = strrchr(filebuffer, '\\');
+ if(lastdirchar) {
+ size_t remaining;
+ *lastdirchar = 0;
+ /* If we have enough space, build the RC filename */
+ remaining = sizeof(filebuffer) - strlen(filebuffer);
+ if(strlen(filename) < remaining - 1) {
+ msnprintf(lastdirchar, remaining, "%s%s", DIR_CHAR, filename);
+ return fopen(filebuffer, FOPEN_READTEXT);
+ }
+ }
+ }
+
+ return NULL;
+}
+#endif
+
+
/* return 0 on everything-is-fine, and non-zero otherwise */
int parseconfig(const char *filename, struct GlobalConfig *global)
{
FILE *file = NULL;
- char filebuffer[512];
bool usedarg = FALSE;
int rc = 0;
struct OperationConfig *operation = global->first;
+ char *pathalloc = NULL;
if(!filename || !*filename) {
/* NULL or no file name attempts to load .curlrc from the homedir! */
-#ifndef __AMIGA__
char *home = homedir(); /* portable homedir finder */
- filename = CURLRC; /* sensible default */
+#ifndef WIN32
if(home) {
- if(strlen(home) < (sizeof(filebuffer) - strlen(CURLRC))) {
- msnprintf(filebuffer, sizeof(filebuffer),
- "%s%s%s", home, DIR_CHAR, CURLRC);
-
-#ifdef WIN32
- /* Check if the file exists - if not, try CURLRC in the same
- * directory as our executable
- */
- file = fopen(filebuffer, FOPEN_READTEXT);
- if(file != NULL) {
- filename = filebuffer;
- }
- else {
- /* Get the filename of our executable. GetModuleFileName is
- * already declared via inclusions done in setup header file.
- * We assume that we are using the ASCII version here.
- */
- unsigned long len = GetModuleFileNameA(0, filebuffer,
- sizeof(filebuffer));
- if(len > 0 && len < sizeof(filebuffer)) {
- /* We got a valid filename - get the directory part */
- char *lastdirchar = strrchr(filebuffer, '\\');
- if(lastdirchar) {
- size_t remaining;
- *lastdirchar = 0;
- /* If we have enough space, build the RC filename */
- remaining = sizeof(filebuffer) - strlen(filebuffer);
- if(strlen(CURLRC) < remaining - 1) {
- msnprintf(lastdirchar, remaining,
- "%s%s", DIR_CHAR, CURLRC);
- /* Don't bother checking if it exists - we do that later */
- filename = filebuffer;
- }
- }
- }
- }
-#else /* WIN32 */
- filename = filebuffer;
-#endif /* WIN32 */
+ pathalloc = curl_maprintf("%s%s.curlrc", home, DIR_CHAR);
+ if(!pathalloc) {
+ free(home);
+ return 1; /* out of memory */
}
- Curl_safefree(home); /* we've used it, now free it */
+ filename = pathalloc;
}
+#else /* Windows */
+ if(home) {
+ int i = 0;
+ char prefix = '.';
+ do {
+ /* check for .curlrc then _curlrc in the home dir */
+ pathalloc = curl_maprintf("%s%s%ccurlrc", home, DIR_CHAR, prefix);
+ if(!pathalloc) {
+ free(home);
+ return 1; /* out of memory */
+ }
-# else /* __AMIGA__ */
- /* On AmigaOS all the config files are into env:
- */
- filename = "ENV:" CURLRC;
-
+ /* Check if the file exists - if not, try _curlrc */
+ file = fopen(pathalloc, FOPEN_READTEXT);
+ if(file) {
+ filename = pathalloc;
+ break;
+ }
+ prefix = '_';
+ } while(++i < 2);
+ }
+ if(!filename) {
+ /* check for .curlrc then _curlrc in the dir of the executable */
+ file = execpath(".curlrc");
+ if(!file)
+ file = execpath("_curlrc");
+ }
#endif
+
+ Curl_safefree(home); /* we've used it, now free it */
}
- if(!file) { /* WIN32: no need to fopen() again */
+ if(!file && filename) { /* no need to fopen() again */
if(strcmp(filename, "-"))
file = fopen(filename, FOPEN_READTEXT);
else
@@ -271,6 +285,7 @@ int parseconfig(const char *filename, struct GlobalConfig
*global)
else
rc = 1; /* couldn't open the file */
+ free(pathalloc);
return rc;
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [GNUnet-SVN] [gnurl] 164/220: ngtcp2: sync with upstream API changes, (continued)
- [GNUnet-SVN] [gnurl] 164/220: ngtcp2: sync with upstream API changes, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 167/220: ngtcp2: add support for SSLKEYLOGFILE, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 143/220: ssh: add a generic Curl_ssh_version function for SSH backends, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 139/220: TODO/ROADMAP: remove "refuse downgrade redirects" and HTTP/3, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 146/220: ngtcp2: use ngtcp2_version() to get the run-time version, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 156/220: cleanup: remove DOT_CHAR completely, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 171/220: vauth: return CURLE_AUTH_ERROR on gss_init_sec_context() failure, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 173/220: RELEASE-NOTES: synced, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 142/220: base64: check for SSH, not specific SSH backends, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 147/220: netrc: make the code try ".netrc" on Windows as well, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 148/220: curl: use .curlrc (with a dot) on Windows as well,
gnunet <=
- [GNUnet-SVN] [gnurl] 163/220: scp: fix directory name length used in memcpy, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 176/220: HTTP3: switched openssl branch to use, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 172/220: build-openssl: fix build with Visual Studio 2019, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 170/220: KNOWN_BUGS: USE_UNIX_SOCKETS on Windows, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 174/220: http2: when marked for closure and wanted to close == OK, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 182/220: ngtcp2: on h3 stream close, call expire, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 177/220: travis: enable ngtcp2 builds again, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 185/220: RELEASE-NOTES: synced, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 160/220: defines: avoid underscore-prefixed defines, gnunet, 2019/09/12
- [GNUnet-SVN] [gnurl] 179/220: CURLOPT_HEADERFUNCTION.3: clarify, gnunet, 2019/09/12