diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-09 15:52:03 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-09 15:52:03 +0200 |
commit | 2384162f6462f232a0d709e64f7d20bb3dbca503 (patch) | |
tree | af64a64fe51b8612f8870f8d295aed94b9e7d1f1 | |
parent | 4700fb5bead95d6457b943351b7dc6f49a09683e (diff) | |
download | busybox-w32-2384162f6462f232a0d709e64f7d20bb3dbca503.tar.gz busybox-w32-2384162f6462f232a0d709e64f7d20bb3dbca503.tar.bz2 busybox-w32-2384162f6462f232a0d709e64f7d20bb3dbca503.zip |
ash: simplify "you have mail" code
function old new delta
mailtime_hash - 4 +4
redirect 1282 1280 -2
mailtime 40 - -40
cmdloop 429 378 -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 4/-93) Total: -89 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/shell/ash.c b/shell/ash.c index 38ff4b62e..07e7f621a 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -10029,10 +10029,8 @@ setinputstring(char *string) | |||
10029 | 10029 | ||
10030 | #if ENABLE_ASH_MAIL | 10030 | #if ENABLE_ASH_MAIL |
10031 | 10031 | ||
10032 | #define MAXMBOXES 10 | 10032 | /* Hash of mtimes of mailboxes */ |
10033 | 10033 | static unsigned mailtime_hash; | |
10034 | /* times of mailboxes */ | ||
10035 | static time_t mailtime[MAXMBOXES]; | ||
10036 | /* Set if MAIL or MAILPATH is changed. */ | 10034 | /* Set if MAIL or MAILPATH is changed. */ |
10037 | static smallint mail_var_path_changed; | 10035 | static smallint mail_var_path_changed; |
10038 | 10036 | ||
@@ -10048,13 +10046,14 @@ chkmail(void) | |||
10048 | const char *mpath; | 10046 | const char *mpath; |
10049 | char *p; | 10047 | char *p; |
10050 | char *q; | 10048 | char *q; |
10051 | time_t *mtp; | 10049 | unsigned new_hash; |
10052 | struct stackmark smark; | 10050 | struct stackmark smark; |
10053 | struct stat statb; | 10051 | struct stat statb; |
10054 | 10052 | ||
10055 | setstackmark(&smark); | 10053 | setstackmark(&smark); |
10056 | mpath = mpathset() ? mpathval() : mailval(); | 10054 | mpath = mpathset() ? mpathval() : mailval(); |
10057 | for (mtp = mailtime; mtp < mailtime + MAXMBOXES; mtp++) { | 10055 | new_hash = 0; |
10056 | for (;;) { | ||
10058 | p = path_advance(&mpath, nullstr); | 10057 | p = path_advance(&mpath, nullstr); |
10059 | if (p == NULL) | 10058 | if (p == NULL) |
10060 | break; | 10059 | break; |
@@ -10068,16 +10067,14 @@ chkmail(void) | |||
10068 | #endif | 10067 | #endif |
10069 | q[-1] = '\0'; /* delete trailing '/' */ | 10068 | q[-1] = '\0'; /* delete trailing '/' */ |
10070 | if (stat(p, &statb) < 0) { | 10069 | if (stat(p, &statb) < 0) { |
10071 | *mtp = 0; | ||
10072 | continue; | 10070 | continue; |
10073 | } | 10071 | } |
10074 | if (!mail_var_path_changed && statb.st_mtime != *mtp) { | 10072 | /* Very simplistic "hash": just a sum of all mtimes */ |
10075 | fprintf( | 10073 | new_hash += (unsigned)statb.st_mtime; |
10076 | stderr, "%s\n", | 10074 | } |
10077 | pathopt ? pathopt : "you have mail" | 10075 | if (!mail_var_path_changed && mailtime_hash != new_hash) { |
10078 | ); | 10076 | mailtime_hash = new_hash; |
10079 | } | 10077 | out2str("you have mail\n"); |
10080 | *mtp = statb.st_mtime; | ||
10081 | } | 10078 | } |
10082 | mail_var_path_changed = 0; | 10079 | mail_var_path_changed = 0; |
10083 | popstackmark(&smark); | 10080 | popstackmark(&smark); |