]> granicus.if.org Git - curl/commitdiff
Paul Moore made curl check for the .curlrc file (_curlrc on windows) on two
authorDaniel Stenberg <daniel@haxx.se>
Wed, 27 Apr 2005 21:24:58 +0000 (21:24 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 27 Apr 2005 21:24:58 +0000 (21:24 +0000)
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.

CHANGES
src/homedir.c
src/main.c

diff --git a/CHANGES b/CHANGES
index 762cf34e8056c8df3763c6b50309b1fa903fb207..3a1e2c149fd14b086c77267061798f114b531a9b 100644 (file)
--- 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.
index 69fbc467c530c75fb456f9b13bddfbd8facddc42..694b9bc79ed249373dd0e6a1114e81336d65ba7b 100644 (file)
@@ -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;
 
index f96dd8b5767df7d016ed0b315b474e3e24fd118a..3df33be5e1eb5ee89952fbdbed17e060f0186b2a 100644 (file)
@@ -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 */
     }