Module Name: src Committed By: kre Date: Sun Jun 4 20:28:13 UTC 2017
Modified Files: src/bin/sh: mail.c Log Message: If we are going to keep the MAILPATH % hack, then at least do something rational. Since it isn't documented, what "rational" is is up for discussion, but what it did before was not it (it was nonsense...). To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/bin/sh/mail.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/mail.c diff -u src/bin/sh/mail.c:1.17 src/bin/sh/mail.c:1.18 --- src/bin/sh/mail.c:1.17 Sun Jun 4 20:27:14 2017 +++ src/bin/sh/mail.c Sun Jun 4 20:28:13 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: mail.c,v 1.17 2017/06/04 20:27:14 kre Exp $ */ +/* $NetBSD: mail.c,v 1.18 2017/06/04 20:28:13 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)mail.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: mail.c,v 1.17 2017/06/04 20:27:14 kre Exp $"); +__RCSID("$NetBSD: mail.c,v 1.18 2017/06/04 20:28:13 kre Exp $"); #endif #endif /* not lint */ @@ -47,6 +47,7 @@ __RCSID("$NetBSD: mail.c,v 1.17 2017/06/ #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> +#include <string.h> #include "shell.h" #include "exec.h" /* defines padvance() */ @@ -61,7 +62,7 @@ __RCSID("$NetBSD: mail.c,v 1.17 2017/06/ STATIC int nmboxes; /* number of mailboxes */ -STATIC time_t mailtime[MAXMBOXES]; /* times of mailboxes */ +STATIC off_t mailsize[MAXMBOXES]; /* sizes of mailboxes */ @@ -94,7 +95,8 @@ chkmail(int silent) stunalloc(p); if (*p == '\0') continue; - for (q = p ; *q ; q++); + for (q = p ; *q ; q++) + ; if (q[-1] != '/') abort(); q[-1] = '\0'; /* delete trailing '/' */ @@ -109,11 +111,32 @@ chkmail(int silent) #else /* this is what it should do */ if (stat(p, &statb) < 0) statb.st_size = 0; - if (statb.st_size > mailtime[i] && ! silent) { - out2str(pathopt ? pathopt : "you have mail"); + if (statb.st_size > mailsize[i] && ! silent) { + const char *pp; + + if ((pp = pathopt) != NULL) { + int len = 0; + + while (*pp && *pp != ':') + len++, pp++; + if (len == 0) { + CHECKSTRSPACE(16, p); + strcat(p, ": file changed"); + } else { + while (stackblocksize() <= len) + growstackblock(); + p = stackblock(); + memcpy(p, pathopt, len); + p[len] = '\0'; + } + pp = p; + } else + pp = "you have mail"; + + out2str(pp); out2c('\n'); } - mailtime[i] = statb.st_size; + mailsize[i] = statb.st_size; #endif } nmboxes = i;