summaryrefslogtreecommitdiffstats
path: root/usr.bin/mail/fio.c
diff options
context:
space:
mode:
authormikeh <mikeh@FreeBSD.org>2001-12-18 20:52:09 +0000
committermikeh <mikeh@FreeBSD.org>2001-12-18 20:52:09 +0000
commite4034fe298af9398dae0cac602d8a28ec6e51489 (patch)
tree89731abafbceb13b0e7b78a6e281339c99fbfef9 /usr.bin/mail/fio.c
parent1750942f6f64d20cc8853d2d1a60a3daaeeb1110 (diff)
downloadFreeBSD-src-e4034fe298af9398dae0cac602d8a28ec6e51489.zip
FreeBSD-src-e4034fe298af9398dae0cac602d8a28ec6e51489.tar.gz
Sync with most of NetBSD's changes, including:
*) Sync with 4.4BSD-Lite2 *) Set usecs for utimes() *) Add 'inc' command and 'autoinc' option that check for new mail manually and automatically, respectively *) Use POSIX signal handling and tty semantics *) Handle long lines correctly when paging messages *) Add ability to explicitly search 'To:' line *) Various manpage cleanups *) Support overriding '~/.mailrc' with $MAILRC *) Support 'askbcc' and 'asksub' options *) Fix various bugs Reviewed by: ru (mail.1) Obtained from: NetBSD
Diffstat (limited to 'usr.bin/mail/fio.c')
-rw-r--r--usr.bin/mail/fio.c78
1 files changed, 54 insertions, 24 deletions
diff --git a/usr.bin/mail/fio.c b/usr.bin/mail/fio.c
index c9dcb94..0c78e3e 100644
--- a/usr.bin/mail/fio.c
+++ b/usr.bin/mail/fio.c
@@ -33,7 +33,7 @@
#ifndef lint
#if 0
-static char sccsid[] = "@(#)fio.c 8.1 (Berkeley) 6/6/93";
+static char sccsid[] = "@(#)fio.c 8.2 (Berkeley) 4/20/95";
#endif
static const char rcsid[] =
"$FreeBSD$";
@@ -60,16 +60,17 @@ extern int wait_status;
* Set up the input pointers while copying the mail file into /tmp.
*/
void
-setptr(ibuf)
+setptr(ibuf, offset)
FILE *ibuf;
+ off_t offset;
{
int c, count;
char *cp, *cp2;
struct message this;
FILE *mestmp;
- off_t offset;
int maybe, inhead;
char linebuf[LINESIZE], pathbuf[PATHSIZE];
+ int omsgCount;
/* Get temporary file. */
(void)snprintf(pathbuf, sizeof(pathbuf), "%s/mail.XXXXXXXXXX", tmpdir);
@@ -77,10 +78,23 @@ setptr(ibuf)
err(1, "can't open %s", pathbuf);
(void)rm(pathbuf);
- msgCount = 0;
+ if (offset == 0) {
+ msgCount = 0;
+ } else {
+ /* Seek into the file to get to the new messages */
+ (void)fseek(ibuf, offset, SEEK_SET);
+ /*
+ * We need to make "offset" a pointer to the end of
+ * the temp file that has the copy of the mail file.
+ * If any messages have been edited, this will be
+ * different from the offset into the mail file.
+ */
+ (void)fseek(otf, 0L, SEEK_END);
+ offset = ftell(otf);
+ }
+ omsgCount = msgCount;
maybe = 1;
inhead = 0;
- offset = 0;
this.m_flag = MUSED|MNEW;
this.m_size = 0;
this.m_lines = 0;
@@ -90,7 +104,7 @@ setptr(ibuf)
if (fgets(linebuf, sizeof(linebuf), ibuf) == NULL) {
if (append(&this, mestmp))
errx(1, "temporary file");
- makemessage(mestmp);
+ makemessage(mestmp, omsgCount);
return;
}
count = strlen(linebuf);
@@ -150,21 +164,25 @@ setptr(ibuf)
/*
* Drop the passed line onto the passed output buffer.
* If a write error occurs, return -1, else the count of
- * characters written, including the newline.
+ * characters written, including the newline if requested.
*/
int
-putline(obuf, linebuf)
+putline(obuf, linebuf, outlf)
FILE *obuf;
char *linebuf;
+ int outlf;
{
int c;
c = strlen(linebuf);
(void)fwrite(linebuf, sizeof(*linebuf), c, obuf);
- fprintf(obuf, "\n");
+ if (outlf) {
+ fprintf(obuf, "\n");
+ c++;
+ }
if (ferror(obuf))
return (-1);
- return (c + 1);
+ return (c);
}
/*
@@ -212,20 +230,27 @@ setinput(mp)
* a dynamically allocated message structure.
*/
void
-makemessage(f)
+makemessage(f, omsgCount)
FILE *f;
+ int omsgCount;
{
- int size = (msgCount + 1) * sizeof(struct message);
-
- if (message != 0)
- (void)free(message);
- if ((message = malloc((unsigned)size)) == NULL)
- err(1, "Out of memory");
- dot = message;
- size -= sizeof(struct message);
+ size_t size;
+ struct message *nmessage;
+
+ size = (msgCount + 1) * sizeof(struct message);
+ nmessage = (struct message *)realloc(message, size);
+ if (nmessage == NULL)
+ errx(1, "Insufficient memory for %d messages\n",
+ msgCount);
+ if (omsgCount == 0 || message == NULL)
+ dot = nmessage;
+ else
+ dot = nmessage + (dot - message);
+ message = nmessage;
+ size -= (omsgCount + 1) * sizeof(struct message);
(void)fflush(f);
(void)lseek(fileno(f), (off_t)sizeof(*message), 0);
- if (read(fileno(f), (char *)message, size) != size)
+ if (read(fileno(f), (char *)&message[omsgCount], size) != size)
errx(1, "Message temporary file corrupted");
message[msgCount].m_size = 0;
message[msgCount].m_lines = 0;
@@ -263,7 +288,7 @@ rm(name)
}
static int sigdepth; /* depth of holdsigs() */
-static int omask;
+static sigset_t nset, oset;
/*
* Hold signals SIGHUP, SIGINT, and SIGQUIT.
*/
@@ -271,8 +296,13 @@ void
holdsigs()
{
- if (sigdepth++ == 0)
- omask = sigblock(sigmask(SIGHUP)|sigmask(SIGINT)|sigmask(SIGQUIT));
+ if (sigdepth++ == 0) {
+ (void)sigemptyset(&nset);
+ (void)sigaddset(&nset, SIGHUP);
+ (void)sigaddset(&nset, SIGINT);
+ (void)sigaddset(&nset, SIGQUIT);
+ (void)sigprocmask(SIG_BLOCK, &nset, &oset);
+ }
}
/*
@@ -283,7 +313,7 @@ relsesigs()
{
if (--sigdepth == 0)
- (void)sigsetmask(omask);
+ (void)sigprocmask(SIG_SETMASK, &oset, NULL);
}
/*
OpenPOWER on IntegriCloud