aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2005-04-27 21:24:58 +0000
committerDaniel Stenberg <daniel@haxx.se>2005-04-27 21:24:58 +0000
commit78882e46429e05c2a258a5440f06644f588cc224 (patch)
treedd32b19b09da99335b70d589cafffbaf117474fd
parent8465a367a41dea71603984b6a6bc08e177ef8a8c (diff)
Paul Moore made curl check for the .curlrc file (_curlrc on windows) on two
more places. First, CURL_HOME is a new environment variable that is used instead of HOME if it is set, to point out where the default config file lives. If there's no config file in the dir pointed out by one of the environment variables, the Windows version will instead check the same directory the executable curl is located in.
-rw-r--r--CHANGES8
-rw-r--r--src/homedir.c8
-rw-r--r--src/main.c36
3 files changed, 51 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 762cf34e8..3a1e2c149 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,14 @@
Changelog
+Daniel (27 April 2005)
+- Paul Moore made curl check for the .curlrc file (_curlrc on windows) on two
+ more places. First, CURL_HOME is a new environment variable that is used
+ instead of HOME if it is set, to point out where the default config file
+ lives. If there's no config file in the dir pointed out by one of the
+ environment variables, the Windows version will instead check the same
+ directory the executable curl is located in.
+
Daniel (26 April 2005)
- Cory Nelson's work on nuking compiler warnings when building on x64 with
VS2005.
diff --git a/src/homedir.c b/src/homedir.c
index 69fbc467c..694b9bc79 100644
--- a/src/homedir.c
+++ b/src/homedir.c
@@ -87,7 +87,13 @@ char *GetEnv(const char *variable, char do_expand)
/* return the home directory of the current user as an allocated string */
char *homedir(void)
{
- char *home = GetEnv("HOME", FALSE);
+ char *home;
+
+ home = GetEnv("CURL_HOME", FALSE);
+ if(home)
+ return home;
+
+ home = GetEnv("HOME", FALSE);
if(home)
return home;
diff --git a/src/main.c b/src/main.c
index f96dd8b57..3df33be5e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2233,7 +2233,43 @@ static void parseconfig(const char *filename,
snprintf(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, "r");
+ if (file != NULL) {
+ fclose(file);
+ filename = filebuffer;
+ }
+ else {
+ /* Get the filename of our executable. GetModuleFileName is
+ * defined in windows.h, which is #included into libcurl.
+ * We assume that we are using the ASCII version here.
+ */
+ int n = GetModuleFileName(0, filebuffer, sizeof(filebuffer));
+ if (n > 0 && n < sizeof(filebuffer)) {
+ /* We got a valid filename - get the directory part */
+ char *lastdirchar = strrchr(filebuffer, '\\');
+ if (lastdirchar) {
+ int remaining;
+ *lastdirchar = 0;
+ /* If we have enough space, build the RC filename */
+ remaining = sizeof(filebuffer) - strlen(filebuffer);
+ if (strlen(CURLRC) < remaining - 1) {
+ snprintf(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 */
}
free(home); /* we've used it, now free it */
}