← Commit list

2384162f6

Denys Vlasenko
Denys Vlasenko
2015-10-09
SUCCESS Duration: 253s

Subject

ash: simplify "you have mail" code

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

shell/ash.c+11 -14
@@ -10029,10 +10029,8 @@ setinputstring(char *string)
#if ENABLE_ASH_MAIL
-#define MAXMBOXES 10
-
-/* times of mailboxes */
-static time_t mailtime[MAXMBOXES];
+/* Hash of mtimes of mailboxes */
+static unsigned mailtime_hash;
/* Set if MAIL or MAILPATH is changed. */
static smallint mail_var_path_changed;
@@ -10048,13 +10046,14 @@ chkmail(void)
const char *mpath;
char *p;
char *q;
- time_t *mtp;
+ unsigned new_hash;
struct stackmark smark;
struct stat statb;
setstackmark(&smark);
mpath = mpathset() ? mpathval() : mailval();
- for (mtp = mailtime; mtp < mailtime + MAXMBOXES; mtp++) {
+ new_hash = 0;
+ for (;;) {
p = path_advance(&mpath, nullstr);
if (p == NULL)
break;
@@ -10068,16 +10067,14 @@ chkmail(void)
#endif
q[-1] = '\0'; /* delete trailing '/' */
if (stat(p, &statb) < 0) {
- *mtp = 0;
continue;
}
- if (!mail_var_path_changed && statb.st_mtime != *mtp) {
- fprintf(
- stderr, "%s\n",
- pathopt ? pathopt : "you have mail"
- );
- }
- *mtp = statb.st_mtime;
+ /* Very simplistic "hash": just a sum of all mtimes */
+ new_hash += (unsigned)statb.st_mtime;
+ }
+ if (!mail_var_path_changed && mailtime_hash != new_hash) {
+ mailtime_hash = new_hash;
+ out2str("you have mail\n");
}
mail_var_path_changed = 0;
popstackmark(&smark);