/*
* env.c -- small service routines
*
+ * Copyright 1998 by Eric S. Raymond
* For license terms, see the file COPYING in this directory.
*/
#ifdef HAVE_GETHOSTBYNAME
#include <netdb.h>
#endif /* HAVE_GETHOSTBYNAME */
+#include <sys/types.h>
+#include <time.h>
#include "fetchmail.h"
+#include "i18n.h"
+
extern char *getenv(); /* needed on sysV68 R3V7.1. */
extern char *program_name;
else
{
fprintf(stderr,
- "%s: can't find your name and home directory!\n",
+ _("%s: can't find your name and home directory!\n"),
program_name);
exit(PS_UNDEFINED);
}
if (gethostname(tmpbuf, sizeof(tmpbuf)))
{
- fprintf(stderr, "%s: can't determine your host!",
+ fprintf(stderr, _("%s: can't determine your host!"),
program_name);
exit(PS_DNS);
}
{
/* exit with error message */
fprintf(stderr,
- "gethostbyname failed for %s\n", tmpbuf);
+ _("gethostbyname failed for %s\n"), tmpbuf);
exit(PS_DNS);
}
return(xstrdup(hp->h_name));
return(xstrdup(tmpbuf));
}
+static char *tzoffset(time_t *now)
+/* calculate timezone offset */
+{
+ static char offset_string[6];
+ struct tm gmt, *lt;
+ int off;
+ char sign = '+';
+
+ gmt = *gmtime(now);
+ lt = localtime(now);
+ off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min;
+ if (lt->tm_year < gmt.tm_year)
+ off -= 24 * 60;
+ else if (lt->tm_year > gmt.tm_year)
+ off += 24 * 60;
+ else if (lt->tm_yday < gmt.tm_yday)
+ off -= 24 * 60;
+ else if (lt->tm_yday > gmt.tm_yday)
+ off += 24 * 60;
+ if (off < 0) {
+ sign = '-';
+ off = -off;
+ }
+ 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);
+ return (offset_string);
+}
+
+char *rfc822timestamp(void)
+/* return a timestamp in RFC822 form */
+{
+ time_t now;
+ static char buf[40];
+
+ time(&now);
+#ifdef HAVE_STRFTIME
+ /*
+ * Conform to RFC822. We generate a 4-digit year here, avoiding
+ * Y2K hassles. Max length of this timestamp in an English locale
+ * should be 29 chars. The only things that should vary by locale
+ * are the day and month abbreviations.
+ */
+ strftime(buf, sizeof(buf)-1,
+ "%a, %d %b %Y %H:%M:%S XXXXX (%Z)", localtime(&now));
+ strncpy(strstr(buf, "XXXXX"), tzoffset(&now), 5);
+#else
+ /*
+ * This is really just a portability fallback, as the
+ * date format ctime(3) emits is not RFC822
+ * conformant.
+ */
+ strcpy(buf, ctime(&now));
+ buf[strlen(buf)-1] = '\0'; /* remove trailing \n */
+#endif /* HAVE_STRFTIME */
+
+ return(buf);
+}
const char *showproto(int proto)
/* protocol index to protocol name mapping */