Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/dash/mail.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 3182 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 /*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1997-2005
5 * Herbert Xu <herbert@gondor.apana.org.au>. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Kenneth Almquist.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 /*
36 * Routines to check for mail. (Perhaps make part of main.c?)
37 */
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <stdlib.h>
41
42 #include "shell.h"
43 #include "nodes.h"
44 #include "exec.h" /* defines padvance() */
45 #include "var.h"
46 #include "output.h"
47 #include "memalloc.h"
48 #include "error.h"
49 #include "mail.h"
50 #include "mystring.h"
51
52
53 #define MAXMBOXES 10
54
55 /* times of mailboxes */
56 static time_t mailtime[MAXMBOXES];
57 /* Set if MAIL or MAILPATH is changed. */
58 static int changed;
59
60
61
62 /*
63 * Print appropriate message(s) if mail has arrived. If changed is set,
64 * then the value of MAIL has changed, so we just update the values.
65 */
66
67 void
68 chkmail(void)
69 {
70 const char *mpath;
71 char *p;
72 char *q;
73 time_t *mtp;
74 struct stackmark smark;
75 struct stat64 statb;
76
77 setstackmark(&smark);
78 mpath = mpathset() ? mpathval() : mailval();
79 for (mtp = mailtime; mtp < mailtime + MAXMBOXES; mtp++) {
80 p = padvance(&mpath, nullstr);
81 if (p == NULL)
82 break;
83 if (*p == '\0')
84 continue;
85 for (q = p ; *q ; q++);
86 #ifdef DEBUG
87 if (q[-1] != '/')
88 abort();
89 #endif
90 q[-1] = '\0'; /* delete trailing '/' */
91 if (stat64(p, &statb) < 0) {
92 *mtp = 0;
93 continue;
94 }
95 if (!changed && statb.st_mtime != *mtp) {
96 outfmt(
97 &errout, snlfmt,
98 pathopt ? pathopt : "you have mail"
99 );
100 }
101 *mtp = statb.st_mtime;
102 }
103 changed = 0;
104 popstackmark(&smark);
105 }
106
107
108 void
109 changemail(const char *val)
110 {
111 changed++;
112 }