From: Fabian Keil <fk@fabiankeil.de>
Date: Sun, 10 Jun 2007 14:59:59 +0000 (+0000)
Subject: Change replacement timegm() to better match our style, plug a small
X-Git-Tag: v_3_0_7~218
X-Git-Url: http://www.privoxy.org/gitweb/%22https:/developer-manual/man-page/@default-cgi@/static/@default-cgi@send-stylesheet?a=commitdiff_plain;h=fcd8a95a1c065e4bd471b9ef9df94082b35cc33f;p=privoxy.git

Change replacement timegm() to better match our style, plug a small
but guaranteed memory leak and fix "time zone breathing" on mingw32.
---

diff --git a/miscutil.c b/miscutil.c
index 12e9ba49..174b10c2 100644
--- a/miscutil.c
+++ b/miscutil.c
@@ -1,4 +1,4 @@
-const char miscutil_rcs[] = "$Id: miscutil.c,v 1.48 2007/04/09 17:48:51 fabiankeil Exp $";
+const char miscutil_rcs[] = "$Id: miscutil.c,v 1.49 2007/05/11 11:48:15 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/miscutil.c,v $
@@ -44,6 +44,13 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.48 2007/04/09 17:48:51 fabianke
  *
  * Revisions   :
  *    $Log: miscutil.c,v $
+ *    Revision 1.49  2007/05/11 11:48:15  fabiankeil
+ *    - Delete strsav() which was replaced
+ *      by string_append() years ago.
+ *    - Add a strlcat() look-alike.
+ *    - Use strlcat() and strlcpy() in those parts
+ *      of the code that are run on unixes.
+ *
  *    Revision 1.48  2007/04/09 17:48:51  fabiankeil
  *    Check for HAVE_SNPRINTF instead of __OS2__
  *    before including the portable snprintf() code.
@@ -1125,9 +1132,15 @@ size_t privoxy_strlcat(char *destination, const char *source, const size_t size)
  *
  * Function    :  timegm
  *
- * Description :  libc replacement function for the inverse of gmtime()
+ * Description :  libc replacement function for the inverse of gmtime().
  *                Copyright (C) 2004 Free Software Foundation, Inc.
- *                Code copied from GnuPG with minor style changes.
+ *
+ *                Code originally copied from GnuPG, modifications done
+ *                for Privoxy: style changed, minor memory leak plugged,
+ *                last putenv() call adjusted to work on mingw32.
+ *
+ *                XXX: It's very unlikely to happen, but if the malloc()
+ *                call fails the time zone will be permanently set to UTC.
  *
  * Parameters  :
  *          1  :  tm: Broken-down time struct.
@@ -1140,20 +1153,21 @@ time_t timegm(struct tm *tm)
    time_t answer;
    char *zone;
 
-   zone=getenv("TZ");
+   zone = getenv("TZ");
    putenv("TZ=UTC");
    tzset();
-   answer=mktime(tm);
-   if(zone)
+   answer = mktime(tm);
+   if (zone)
    {
       char *old_zone;
 
-      old_zone=malloc(3+strlen(zone)+1);
-      if(old_zone)
+      old_zone = malloc(3 + strlen(zone) + 1);
+      if (old_zone)
       {
-         strcpy(old_zone,"TZ=");
-         strcat(old_zone,zone);
+         strcpy(old_zone, "TZ=");
+         strcat(old_zone, zone);
          putenv(old_zone);
+         free(old_zone);
       }
    }
    else
@@ -1161,10 +1175,11 @@ time_t timegm(struct tm *tm)
 #ifdef HAVE_UNSETENV
       unsetenv("TZ");
 #else
-      putenv("TZ");
+      putenv("TZ=");
 #endif
    }
    tzset();
+
    return answer;
 }
 #endif /* !defined(HAVE_TIMEGM) && defined(HAVE_TZSET) && defined(HAVE_PUTENV) */