cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: ANNOUNCE: curl and libcurl 7.13.2

From: Paul Moore <pf_moore_at_yahoo.co.uk>
Date: Wed, 27 Apr 2005 12:05:03 +0000 (UTC)

Paul Moore <pf_moore@...> writes:

>
> Daniel Stenberg <daniel-curl@...> writes:
>
> > But I wouldn't mind getting "same dir", "CURL_HOME and a registry setting
> > supported for the default one. Anyone up to the task?
>
> If I get the time (no guarantees!) I'll look into this - it's a
> hobbyhorse of mine, so I've done similar things for other code.

It was actually pretty easy - the following diff covers adding a CURL_HOME
variable (the homedir.c change, affects all versions) and looking for CURLRC in
the same directory as the executable (the main.c change, only for WIN32).

I've compiled this on Windows with mingw32, with no SSL support, and done some
fairly basic testing. It seems to work OK. What do you think?

Paul.

PS Apologies if the diff gets mangled - I'm only able to post via a web
interface at the moment, with no support for attachments. If you want me to
repost it, please let me know and I'll do so.

diff -ur curl-7.13.2/src/homedir.c curl-7.13.2.new/src/homedir.c
--- curl-7.13.2/src/homedir.c 2004-10-06 08:50:18.000000000 +0100
+++ curl-7.13.2.new/src/homedir.c 2005-04-27 11:11:01.353745600 +0100
@@ -91,6 +91,10 @@
   if(home)
     return home;
 
+ home = GetEnv("CURL_HOME", FALSE);
+ if(home)
+ return home;
+
 #if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
  {
    struct passwd *pw = getpwuid(geteuid());
diff -ur curl-7.13.2/src/main.c curl-7.13.2.new/src/main.c
--- curl-7.13.2/src/main.c 2005-03-28 23:17:49.000000000 +0100
+++ curl-7.13.2.new/src/main.c 2005-04-27 12:03:08.109200800 +0100
@@ -2233,7 +2233,43 @@
         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
         filename = filebuffer;
+#endif
       }
       free(home); /* we've used it, now free it */
     }
Received on 2005-04-27