#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
-#define LEN_ULONG 40 /* holds 2^128 - 1 in decimal, plus '\0' */
+#if !defined(HOST_NAME_MAX)
+#if defined MAXHOSTNAMELEN
+#define HOST_NAME_MAX MAXHOSTNAMELEN
+#else
+#define HOST_NAME_MAX 64
+#endif
+#endif
+
+/* holds 2^128 - 1 in decimal, plus '\0' */
+#define LEN_ULONG 40
+
+/* 1 for '\0', 4 for "tmp/", HOST_NAME_MAX for the hostname, and two
+ * LEN_ULONGs for time and pid. */
+#define TMPNAMLEN 1 + 4 + HOST_NAME_MAX + LEN_ULONG + LEN_ULONG
/* Write all of buf, even if write(2) is interrupted. */
static ssize_t
static void
deliver(char *maildir, char *newfn)
{
- char fn[80 + LEN_ULONG * 2], host[64];
+ char fn[TMPNAMLEN], host[HOST_NAME_MAX + 1];
char *buildfn; /* used to build up the fn */
time_t now;
struct tm *t;
int
main(int argc, char *argv[])
{
- char newfn[80 + LEN_ULONG * 2];
+ char newfn[TMPNAMLEN];
pid_t pid;
FILE *errfile;
char *fail;