]> diplodocus.org Git - mdeliver/commitdiff
Include <limits.h>.
authorepg <>
Tue, 20 Aug 2002 05:46:34 +0000 (05:46 +0000)
committerepg <>
Tue, 20 Aug 2002 05:46:34 +0000 (05:46 +0000)
Define HOST_NAME_MAX if not set.  Use it instead of 64 for
gethostname(3).

Create new macro TMPNAMLEN for declaring maildir filename strings.

mdeliver.c

index d65214b47f92a83fefd013e1088e3e5b3e0168bf..5dd5239756bbb74da3f25f3744052ac323d907a9 100644 (file)
@@ -11,6 +11,7 @@
 #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
@@ -46,7 +60,7 @@ full_write(int fd, const char *buf, size_t nbytes)
 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;
@@ -121,7 +135,7 @@ deliver(char *maildir, char *newfn)
 int
 main(int argc, char *argv[])
 {
-    char newfn[80 + LEN_ULONG * 2];
+    char newfn[TMPNAMLEN];
     pid_t pid;
     FILE *errfile;
     char *fail;