]> Pileus Git - ~andy/fetchmail/blobdiff - env.c
Override LC_ALL so that a parsable Date results.
[~andy/fetchmail] / env.c
diff --git a/env.c b/env.c
index 86531b96ee96742c79b6f821158cadd7a6d0bfa6..aaddb54d00f5e8e19613e794c7dda8cbd9d43e3e 100644 (file)
--- a/env.c
+++ b/env.c
 #include <netdb.h>
 #endif /* HAVE_GETHOSTBYNAME */
 #include  <sys/types.h>
-#include  <time.h>
 #include "fetchmail.h"
 
 #include "i18n.h"
 #if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
-#include <time.h>
 #include <locale.h>
 #endif
 
-extern char *getenv(); /* needed on sysV68 R3V7.1. */
-
-extern char *program_name;
+extern char *getenv(const char *);     /* needed on sysV68 R3V7.1. */
 
 void envquery(int argc, char **argv)
 /* set up basic stuff from the environment (including the rc file name) */
@@ -107,7 +103,8 @@ void envquery(int argc, char **argv)
     }
 
     /* compute user's home directory */
-    if (!(home = getenv("HOME")))
+    home = getenv("HOME_ETC");
+    if (!home && !(home = getenv("HOME")))
        home = pwp->pw_dir;
 
     /* compute fetchmail's home directory */
@@ -193,7 +190,8 @@ static char *tzoffset(time_t *now)
     }
     if (off >= 24 * 60)                        /* should be impossible */
        off = 23 * 60 + 59;             /* if not, insert silly value */
-    sprintf(offset_string, "%c%02d%02d", sign, off / 60, off % 60);
+    snprintf(offset_string, sizeof(offset_string),
+           "%c%02d%02d", sign, off / 60, off % 60);
     return (offset_string);
 }
 
@@ -213,12 +211,12 @@ char *rfc822timestamp(void)
      * weird multibyte i18n characters (such as kanji) from showing up
      * in your Received headers.
      */
-#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
+#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS)
     setlocale (LC_TIME, "C");
 #endif
     strftime(buf, sizeof(buf)-1, 
             "%a, %d %b %Y %H:%M:%S XXXXX (%Z)", localtime(&now));
-#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
+#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS)
     setlocale (LC_TIME, "");
 #endif
     strncpy(strstr(buf, "XXXXX"), tzoffset(&now), 5);
@@ -280,7 +278,7 @@ char *visbuf(const char *buf)
            *tp++ = '\\'; *tp++ = '\\';
            buf++;
        }
-       else if (isprint(*buf) || *buf == ' ')
+       else if (isprint((unsigned char)*buf) || *buf == ' ')
            *tp++ = *buf++;
        else if (*buf == '\n')
        {
@@ -304,8 +302,11 @@ char *visbuf(const char *buf)
        }
        else
        {
-           (void) sprintf(tp, "\\0x%02x", *buf++);
-           tp += strlen(tp);
+           const char hex[] = "0123456789abcdef";
+           *tp++ = '\\'; *tp++ = '0'; *tp++ = 'x';
+           *tp++ = hex[*buf >> 4];
+           *tp++ = hex[*buf & 0xf];
+           buf++;
        }
     }
     *tp++ = '\0';