diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-07-13 21:21:19 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-07-13 21:21:19 +0000 |
commit | 2b3297f5b1693e36cc22413dbb7778992297f602 (patch) | |
tree | 1174dc315d74b189eb843566a157df312e1044a0 /usr.bin | |
parent | ea02c5005fcf76b2b6e8b3c847d6134492640cea (diff) |
Merge in NetBSD and 4.4BSD-lite2 changes as well as some of my own.
- handle long lines safely (from NetBSD)
- use puts/fputs and putchar/putc when it makes sense
- use err/errx and warn/warnx when it makes sense
- make return() and sizeof() style consisten
- some more buffer safety
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mail/aux.c | 78 | ||||
-rw-r--r-- | usr.bin/mail/cmd1.c | 68 | ||||
-rw-r--r-- | usr.bin/mail/cmd2.c | 76 | ||||
-rw-r--r-- | usr.bin/mail/cmd3.c | 92 | ||||
-rw-r--r-- | usr.bin/mail/cmdtab.c | 9 | ||||
-rw-r--r-- | usr.bin/mail/collect.c | 94 | ||||
-rw-r--r-- | usr.bin/mail/def.h | 19 | ||||
-rw-r--r-- | usr.bin/mail/dotlock.c | 22 | ||||
-rw-r--r-- | usr.bin/mail/edit.c | 30 | ||||
-rw-r--r-- | usr.bin/mail/extern.h | 20 | ||||
-rw-r--r-- | usr.bin/mail/fio.c | 189 | ||||
-rw-r--r-- | usr.bin/mail/getname.c | 12 | ||||
-rw-r--r-- | usr.bin/mail/head.c | 55 | ||||
-rw-r--r-- | usr.bin/mail/lex.c | 145 | ||||
-rw-r--r-- | usr.bin/mail/list.c | 109 | ||||
-rw-r--r-- | usr.bin/mail/mail.1 | 35 | ||||
-rw-r--r-- | usr.bin/mail/main.c | 44 | ||||
-rw-r--r-- | usr.bin/mail/names.c | 62 | ||||
-rw-r--r-- | usr.bin/mail/popen.c | 84 | ||||
-rw-r--r-- | usr.bin/mail/quit.c | 138 | ||||
-rw-r--r-- | usr.bin/mail/send.c | 82 | ||||
-rw-r--r-- | usr.bin/mail/strings.c | 8 | ||||
-rw-r--r-- | usr.bin/mail/temp.c | 12 | ||||
-rw-r--r-- | usr.bin/mail/tty.c | 33 | ||||
-rw-r--r-- | usr.bin/mail/v7.local.c | 16 | ||||
-rw-r--r-- | usr.bin/mail/vars.c | 12 |
26 files changed, 866 insertions, 678 deletions
diff --git a/usr.bin/mail/aux.c b/usr.bin/mail/aux.c index f6d2cfa2f13..6d691e58f95 100644 --- a/usr.bin/mail/aux.c +++ b/usr.bin/mail/aux.c @@ -1,5 +1,5 @@ -/* $OpenBSD: aux.c,v 1.4 1997/05/30 08:51:32 deraadt Exp $ */ -/* $NetBSD: aux.c,v 1.4 1996/06/08 19:48:10 christos Exp $ */ +/* $OpenBSD: aux.c,v 1.5 1997/07/13 21:21:08 millert Exp $ */ +/* $NetBSD: aux.c,v 1.5 1997/05/13 06:15:52 mikel Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)aux.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: aux.c,v 1.4 1997/05/30 08:51:32 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: aux.c,v 1.5 1997/07/13 21:21:08 millert Exp $"; #endif #endif /* not lint */ @@ -64,7 +64,7 @@ savestr(str) if ((new = salloc(size)) != NOSTR) bcopy(str, new, size); - return new; + return(new); } /* @@ -85,7 +85,7 @@ save2str(str, old) } bcopy(str, new + oldsize, newsize); } - return new; + return(new); } /* @@ -115,7 +115,7 @@ panic(fmt, va_alist) (void)fprintf(stderr, "panic: "); vfprintf(stderr, fmt, ap); va_end(ap); - (void)fprintf(stderr, "\n"); + (void)putc('\n', stderr); fflush(stderr); abort(); } @@ -161,7 +161,7 @@ argcount(argv) for (ap = argv; *ap++ != NOSTR;) ; - return ap - argv - 1; + return(ap - argv - 1); } /* @@ -181,16 +181,16 @@ hfield(field, mp) ibuf = setinput(mp); if ((lc = mp->m_lines - 1) < 0) - return NOSTR; + return(NOSTR); if (readline(ibuf, linebuf, LINESIZE) < 0) - return NOSTR; + return(NOSTR); while (lc > 0) { if ((lc = gethfield(ibuf, linebuf, lc, &colon)) < 0) - return oldhfield; + return(oldhfield); if ((hfield = ishfield(linebuf, colon, field)) != NULL) oldhfield = save2str(hfield, oldhfield); } - return oldhfield; + return(oldhfield); } /* @@ -212,9 +212,9 @@ gethfield(f, linebuf, rem, colon) for (;;) { if (--rem < 0) - return -1; + return(-1); if ((c = readline(f, linebuf, LINESIZE)) <= 0) - return -1; + return(-1); for (cp = linebuf; isprint(*cp) && *cp != ' ' && *cp != ':'; cp++) ; @@ -248,7 +248,7 @@ gethfield(f, linebuf, rem, colon) cp += c; } *cp = 0; - return rem; + return(rem); } /* NOTREACHED */ } @@ -268,12 +268,12 @@ ishfield(linebuf, colon, field) *cp = 0; if (strcasecmp(linebuf, field) != 0) { *cp = ':'; - return 0; + return(0); } *cp = ':'; for (cp++; *cp == ' ' || *cp == '\t'; cp++) ; - return cp; + return(cp); } /* @@ -321,12 +321,12 @@ source(v) if ((cp = expand(*arglist)) == NOSTR) return(1); if ((fi = Fopen(cp, "r")) == NULL) { - perror(cp); + warn(cp); return(1); } if (ssp >= NOFILE - 1) { - printf("Too much \"sourcing\" going on.\n"); - Fclose(fi); + puts("Too much \"sourcing\" going on."); + (void)Fclose(fi); return(1); } sstack[ssp].s_file = input; @@ -348,13 +348,13 @@ int unstack() { if (ssp <= 0) { - printf("\"Source\" stack over-pop.\n"); + puts("\"Source\" stack over-pop."); sourcing = 0; return(1); } - Fclose(input); + (void)Fclose(input); if (cond != CANY) - printf("Unmatched \"if\"\n"); + puts("Unmatched \"if\""); ssp--; cond = sstack[ssp].s_cond; loading = sstack[ssp].s_loading; @@ -447,7 +447,7 @@ skip_comment(cp) break; } } - return cp; + return(cp); } /* @@ -574,9 +574,9 @@ name1(mp, reptype) int first = 1; if ((cp = hfield("from", mp)) != NOSTR) - return cp; + return(cp); if (reptype == 0 && (cp = hfield("sender", mp)) != NOSTR) - return cp; + return(cp); ibuf = setinput(mp); namebuf[0] = '\0'; if (readline(ibuf, linebuf, LINESIZE) < 0) @@ -606,10 +606,12 @@ newname: break; cp++; if (first) { - strcpy(namebuf, cp); + cp2 = namebuf; first = 0; } else - strcpy(strrchr(namebuf, '!')+1, cp); + cp2 = strrchr(namebuf, '!') + 1; + strncpy(cp2, cp, sizeof(namebuf) - (cp2 - namebuf) - 2); + namebuf[sizeof(namebuf) - 2] = '\0'; strcat(namebuf, "!"); goto newname; } @@ -645,8 +647,8 @@ anyof(s1, s2) while (*s1) if (strchr(s2, *s1++)) - return 1; - return 0; + return(1); + return(0); } /* @@ -658,8 +660,8 @@ raise(c) { if (islower(c)) - return toupper(c); - return c; + return(toupper(c)); + return(c); } /* @@ -672,7 +674,7 @@ copy(s1, s2) while ((*s2++ = *s1++) != '\0') ; - return s2 - 1; + return(s2 - 1); } /* @@ -683,19 +685,19 @@ isign(field, ignore) char *field; struct ignoretab ignore[2]; { - char realfld[BUFSIZ]; + char realfld[LINESIZE]; if (ignore == ignoreall) - return 1; + return(1); /* * Lower-case the string, so that "Status" and "status" * will hash to the same place. */ istrcpy(realfld, field); if (ignore[1].i_count > 0) - return (!member(realfld, ignore + 1)); + return(!member(realfld, ignore + 1)); else - return (member(realfld, ignore)); + return(member(realfld, ignore)); } int @@ -708,6 +710,6 @@ member(realfield, table) for (igp = table->i_head[hash(realfield)]; igp != 0; igp = igp->i_link) if (*igp->i_field == *realfield && equal(igp->i_field, realfield)) - return (1); - return (0); + return(1); + return(0); } diff --git a/usr.bin/mail/cmd1.c b/usr.bin/mail/cmd1.c index 1409eaa6d99..a6a88df4f1c 100644 --- a/usr.bin/mail/cmd1.c +++ b/usr.bin/mail/cmd1.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmd1.c,v 1.5 1997/05/30 08:51:34 deraadt Exp $ */ -/* $NetBSD: cmd1.c,v 1.5 1996/06/08 19:48:11 christos Exp $ */ +/* $OpenBSD: cmd1.c,v 1.6 1997/07/13 21:21:08 millert Exp $ */ +/* $NetBSD: cmd1.c,v 1.9 1997/07/09 05:29:48 mikel Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)cmd1.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)cmd1.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: cmd1.c,v 1.5 1997/05/30 08:51:34 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmd1.c,v 1.6 1997/07/13 21:21:08 millert Exp $"; #endif #endif /* not lint */ @@ -91,7 +91,7 @@ headers(v) printhead(mesg); } if (flag == 0) { - printf("No more mail.\n"); + puts("No more mail."); return(1); } return(0); @@ -116,7 +116,7 @@ scroll(v) case '+': s++; if (s * size > msgCount) { - printf("On last screenful of messages\n"); + puts("On last screenful of messages"); return(0); } screen = s; @@ -124,7 +124,7 @@ scroll(v) case '-': if (--s < 0) { - printf("On first screenful of messages\n"); + puts("On first screenful of messages"); return(0); } screen = s; @@ -147,8 +147,8 @@ screensize() char *cp; if ((cp = value("screen")) != NOSTR && (s = atoi(cp)) > 0) - return s; - return screenheight - 4; + return(s); + return(screenheight - 4); } /* @@ -204,7 +204,7 @@ printhead(mesg) if (mp->m_flag & MBOX) dispc = 'M'; parse(headline, &hl, pbuf); - sprintf(wcount, "%3d/%-5d", mp->m_lines, mp->m_size); + snprintf(wcount, sizeof(wcount), "%3d/%-5d", mp->m_lines, mp->m_size); subjlen = screenwidth - 50 - strlen(wcount); name = value("show-rcpt") != NOSTR ? skin(hfield("to", mp)) : nameof(mp, 0); @@ -239,17 +239,17 @@ pcmdlist(v) register const struct cmd *cp; register int cc; - printf("Commands are:\n"); + puts("Commands are:"); for (cc = 0, cp = cmdtab; cp->c_name != NULL; cp++) { cc += strlen(cp->c_name) + 2; if (cc > 72) { - printf("\n"); + putchar('\n'); cc = strlen(cp->c_name) + 2; } if ((cp+1)->c_name != NOSTR) printf("%s, ", cp->c_name); else - printf("%s\n", cp->c_name); + puts(cp->c_name); } return(0); } @@ -262,7 +262,7 @@ more(v) void *v; { int *msgvec = v; - return (type1(msgvec, 1, 1)); + return(type1(msgvec, 1, 1)); } /* @@ -274,7 +274,7 @@ More(v) { int *msgvec = v; - return (type1(msgvec, 0, 1)); + return(type1(msgvec, 0, 1)); } /* @@ -337,7 +337,7 @@ type1(msgvec, doign, page) cp = _PATH_MORE; obuf = Popen(cp, "w"); if (obuf == NULL) { - perror(cp); + warn(cp); obuf = stdout; } else signal(SIGPIPE, brokpipe); @@ -357,7 +357,7 @@ close_pipe: * Ignore SIGPIPE so it can't cause a duplicate close. */ signal(SIGPIPE, SIG_IGN); - Pclose(obuf); + (void)Pclose(obuf); signal(SIGPIPE, SIG_DFL); } return(0); @@ -407,7 +407,7 @@ top(v) ibuf = setinput(mp); c = mp->m_lines; if (!lineb) - printf("\n"); + putchar('\n'); for (lines = 0; lines < c && lines <= topl; lines++) { if (readline(ibuf, linebuf, LINESIZE) < 0) break; @@ -465,12 +465,36 @@ folders(v) char dirname[PATHSIZE]; char *cmd; - if (getfold(dirname, sizeof dirname) < 0) { - printf("No value set for \"folder\"\n"); - return 1; + if (getfold(dirname, sizeof(dirname)) < 0) { + puts("No value set for \"folder\""); + return(1); } if ((cmd = value("LISTER")) == NOSTR) cmd = "ls"; (void) run_command(cmd, 0, -1, -1, dirname, NOSTR, NOSTR); - return 0; + return(0); +} + +/* + * Update the mail file with any new messages that have + * come in since we started reading mail. + */ +int +inc(v) + void *v; +{ + int nmsg, mdot; + + nmsg = incfile(); + + if (nmsg == 0) { + puts("No new mail."); + } else if (nmsg > 0) { + mdot = newfileinfo(msgCount - nmsg); + dot = &message[mdot - 1]; + } else { + puts("\"inc\" command failed..."); + } + + return(0); } diff --git a/usr.bin/mail/cmd2.c b/usr.bin/mail/cmd2.c index 3c71588f03d..31b9a3f42db 100644 --- a/usr.bin/mail/cmd2.c +++ b/usr.bin/mail/cmd2.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmd2.c,v 1.2 1996/06/11 12:53:33 deraadt Exp $ */ -/* $NetBSD: cmd2.c,v 1.5 1996/06/08 19:48:13 christos Exp $ */ +/* $OpenBSD: cmd2.c,v 1.3 1997/07/13 21:21:09 millert Exp $ */ +/* $NetBSD: cmd2.c,v 1.7 1997/05/17 19:55:10 pk Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: cmd2.c,v 1.2 1996/06/11 12:53:33 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmd2.c,v 1.3 1997/07/13 21:21:09 millert Exp $"; #endif #endif /* not lint */ @@ -70,7 +70,7 @@ next(v) if (*msgvec != NULL) { /* - * If some messages were supplied, find the + * If some messages were supplied, find the * first applicable one following dot using * wrap around. */ @@ -99,7 +99,7 @@ next(v) if (*ip2 == NULL) ip2 = msgvec; } while (ip2 != ip); - printf("No messages applicable\n"); + puts("No messages applicable"); return(1); } @@ -120,7 +120,7 @@ next(v) if ((mp->m_flag & (MDELETED|MSAVED)) == 0) break; if (mp >= &message[msgCount]) { - printf("At EOF\n"); + puts("At EOF"); return(0); } dot = mp; @@ -144,7 +144,7 @@ save(v) { char *str = v; - return save1(str, 1, "save", saveignore); + return(save1(str, 1, "save", saveignore)); } /* @@ -156,7 +156,7 @@ copycmd(v) { char *str = v; - return save1(str, 0, "copy", saveignore); + return(save1(str, 0, "copy", saveignore)); } /* @@ -176,7 +176,7 @@ save1(str, mark, cmd, ignore) int f, *msgvec; FILE *obuf; - msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec); + msgvec = (int *) salloc((msgCount + 2) * sizeof(*msgvec)); if ((file = snarf(str, &f)) == NOSTR) return(1); if (!f) { @@ -198,7 +198,7 @@ save1(str, mark, cmd, ignore) else disp = "[New file]"; if ((obuf = Fopen(file, "a")) == NULL) { - perror(NOSTR); + warn(NOSTR); return(1); } for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { @@ -206,7 +206,7 @@ save1(str, mark, cmd, ignore) touch(mp); if (send(mp, obuf, ignore, NOSTR) < 0) { perror(file); - Fclose(obuf); + (void)Fclose(obuf); return(1); } if (mark) @@ -215,7 +215,7 @@ save1(str, mark, cmd, ignore) fflush(obuf); if (ferror(obuf)) perror(file); - Fclose(obuf); + (void)Fclose(obuf); printf("%s\n", disp); return(0); } @@ -230,7 +230,7 @@ swrite(v) { char *str = v; - return save1(str, 1, "write", ignoreall); + return(save1(str, 1, "write", ignoreall)); } /* @@ -267,7 +267,7 @@ snarf(linebuf, flag) while (cp > linebuf && !isspace(*cp)) cp--; if (*cp == '\0') { - printf("No file specified.\n"); + puts("No file specified."); return(NOSTR); } if (isspace(*cp)) @@ -286,7 +286,7 @@ delete(v) { int *msgvec = v; delm(msgvec); - return 0; + return(0); } /* @@ -308,9 +308,9 @@ deltype(v) list[1] = NULL; return(type(list)); } - printf("At EOF\n"); + puts("At EOF"); } else - printf("No more messages\n"); + puts("No more messages"); return(0); } @@ -372,7 +372,7 @@ undeletecmd(v) dot = mp; mp->m_flag &= ~MDELETED; } - return 0; + return(0); } /* @@ -393,14 +393,14 @@ core(v) abort(); _exit(1); } - printf("Okie dokie"); + fputs("Okie dokie", stdout); fflush(stdout); wait_child(pid); if (wait_status.w_coredump) - printf(" -- Core dumped.\n"); + puts(" -- Core dumped."); else - printf(" -- Can't dump core.\n"); - return 0; + puts(" -- Can't dump core."); + return(0); } /* @@ -418,7 +418,7 @@ clobber(v) else times = (atoi(argv[0]) + 511) / 512; clob1(times); - return 0; + return(0); } /* @@ -448,7 +448,7 @@ retfield(v) { char **list = v; - return ignore1(list, ignore + 1, "retained"); + return(ignore1(list, ignore + 1, "retained")); } /* @@ -461,7 +461,7 @@ igfield(v) { char **list = v; - return ignore1(list, ignore, "ignored"); + return(ignore1(list, ignore, "ignored")); } int @@ -470,7 +470,7 @@ saveretfield(v) { char **list = v; - return ignore1(list, saveignore + 1, "retained"); + return(ignore1(list, saveignore + 1, "retained")); } int @@ -479,7 +479,7 @@ saveigfield(v) { char **list = v; - return ignore1(list, saveignore, "ignored"); + return(ignore1(list, saveignore, "ignored")); } int @@ -488,27 +488,27 @@ ignore1(list, tab, which) struct ignoretab *tab; char *which; { - char field[BUFSIZ]; + char field[LINESIZE]; register int h; register struct ignore *igp; char **ap; if (*list == NOSTR) - return igshow(tab, which); + return(igshow(tab, which)); for (ap = list; *ap != 0; ap++) { istrcpy(field, *ap); if (member(field, tab)) continue; h = hash(field); - igp = (struct ignore *) calloc(1, sizeof (struct ignore)); + igp = (struct ignore *) calloc(1, sizeof(struct ignore)); igp->i_field = calloc((unsigned) strlen(field) + 1, - sizeof (char)); + sizeof(char)); strcpy(igp->i_field, field); igp->i_link = tab->i_head[h]; tab->i_head[h] = igp; tab->i_count++; } - return 0; + return(0); } /* @@ -525,18 +525,18 @@ igshow(tab, which) if (tab->i_count == 0) { printf("No fields currently being %s.\n", which); - return 0; + return(0); } - ring = (char **) salloc((tab->i_count + 1) * sizeof (char *)); + ring = (char **) salloc((tab->i_count + 1) * sizeof(char *)); ap = ring; for (h = 0; h < HSHSIZE; h++) for (igp = tab->i_head[h]; igp != 0; igp = igp->i_link) *ap++ = igp->i_field; *ap = 0; - qsort(ring, tab->i_count, sizeof (char *), igcomp); + qsort(ring, tab->i_count, sizeof(char *), igcomp); for (ap = ring; *ap != 0; ap++) - printf("%s\n", *ap); - return 0; + puts(*ap); + return(0); } /* @@ -546,5 +546,5 @@ static int igcomp(l, r) const void *l, *r; { - return (strcmp(*(char **)l, *(char **)r)); + return(strcmp(*(char **)l, *(char **)r)); } diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c index 197fa5605dd..3818dee9c5a 100644 --- a/usr.bin/mail/cmd3.c +++ b/usr.bin/mail/cmd3.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmd3.c,v 1.4 1997/05/30 08:51:35 deraadt Exp $ */ -/* $NetBSD: cmd3.c,v 1.5 1996/06/08 19:48:14 christos Exp $ */ +/* $OpenBSD: cmd3.c,v 1.5 1997/07/13 21:21:09 millert Exp $ */ +/* $NetBSD: cmd3.c,v 1.8 1997/07/09 05:29:49 mikel Exp $ */ /* * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)cmd3.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)cmd3.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: cmd3.c,v 1.4 1997/05/30 08:51:35 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmd3.c,v 1.5 1997/07/13 21:21:09 millert Exp $"; #endif #endif /* not lint */ @@ -67,13 +67,13 @@ shell(v) (void) strcpy(cmd, str); if (bangexp(cmd) < 0) - return 1; + return(1); if ((shell = value("SHELL")) == NOSTR) shell = _PATH_CSHELL; (void) run_command(shell, 0, -1, -1, "-c", cmd, NOSTR); (void) signal(SIGINT, sigint); - printf("!\n"); - return 0; + puts("!"); + return(0); } /* @@ -92,7 +92,7 @@ dosh(v) (void) run_command(shell, 0, -1, -1, NOSTR, NOSTR, NOSTR); (void) signal(SIGINT, sigint); putchar('\n'); - return 0; + return(0); } /* @@ -118,7 +118,7 @@ bangexp(str) if (*cp == '!') { if (n < strlen(lastbang)) { overf: - printf("Command buffer overflow\n"); + puts("Command buffer overflow"); return(-1); } changed++; @@ -145,8 +145,8 @@ overf: fflush(stdout); } strcpy(str, bangbuf); - strncpy(lastbang, bangbuf, 128); - lastbang[128-1] = 0; + strncpy(lastbang, bangbuf, sizeof(lastbang) - 1); + lastbang[sizeof(lastbang) - 1] = '\0'; return(0); } @@ -162,12 +162,12 @@ help(v) register FILE *f; if ((f = Fopen(_PATH_HELP, "r")) == NULL) { - perror(_PATH_HELP); + warn(_PATH_HELP); return(1); } while ((c = getc(f)) != EOF) putchar(c); - Fclose(f); + (void)Fclose(f); return(0); } @@ -187,10 +187,10 @@ schdir(v) if ((cp = expand(*arglist)) == NOSTR) return(1); if (chdir(cp) < 0) { - perror(cp); + warn(cp); return(1); } - return 0; + return(0); } int @@ -199,9 +199,9 @@ respond(v) { int *msgvec = v; if (value("Replyall") == NOSTR) - return (_respond(msgvec)); + return(_respond(msgvec)); else - return (_Respond(msgvec)); + return(_Respond(msgvec)); } /* @@ -219,7 +219,7 @@ _respond(msgvec) struct header head; if (msgvec[1] != 0) { - printf("Sorry, can't reply to multiple messages at once\n"); + puts("Sorry, can't reply to multiple messages at once"); return(1); } mp = &message[msgvec[0] - 1]; @@ -246,7 +246,7 @@ _respond(msgvec) np = cat(np, extract(rcv, GTO)); else if (np == NIL) { if (replyto != NOSTR) - printf("Empty reply-to field -- replying to author\n"); + puts("Empty reply-to field -- replying to author"); np = extract(rcv, GTO); } head.h_to = np; @@ -279,15 +279,15 @@ reedit(subj) char *newsubj; if (subj == NOSTR) - return NOSTR; + return(NOSTR); if ((subj[0] == 'r' || subj[0] == 'R') && (subj[1] == 'e' || subj[1] == 'E') && subj[2] == ':') - return subj; + return(subj); newsubj = salloc(strlen(subj) + 5); strcpy(newsubj, "Re: "); strcpy(newsubj + 4, subj); - return newsubj; + return(newsubj); } /* @@ -303,7 +303,7 @@ preserve(v) register int *ip, mesg; if (edit) { - printf("Cannot \"preserve\" in edit mode\n"); + puts("Cannot \"preserve\" in edit mode"); return(1); } for (ip = msgvec; *ip != NULL; ip++) { @@ -385,7 +385,7 @@ set(v) for (h = 0, s = 1; h < HSHSIZE; h++) for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) s++; - ap = (char **) salloc(s * sizeof *ap); + ap = (char **) salloc(s * sizeof(*ap)); for (h = 0, p = ap; h < HSHSIZE; h++) for (vp = variables[h]; vp != NOVAR; vp = vp->v_link) *p++ = vp->v_name; @@ -407,7 +407,7 @@ set(v) else cp++; if (equal(varbuf, "")) { - printf("Non-null variable name required\n"); + puts("Non-null variable name required"); errs++; continue; } @@ -473,7 +473,7 @@ group(v) for (h = 0, s = 1; h < HSHSIZE; h++) for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) s++; - ap = (char **) salloc(s * sizeof *ap); + ap = (char **) salloc(s * sizeof(*ap)); for (h = 0, p = ap; h < HSHSIZE; h++) for (gh = groups[h]; gh != NOGRP; gh = gh->g_link) *p++ = gh->g_name; @@ -490,7 +490,7 @@ group(v) gname = *argv; h = hash(gname); if ((gh = findgroup(gname)) == NOGRP) { - gh = (struct grouphead *) calloc(sizeof *gh, 1); + gh = (struct grouphead *) calloc(sizeof(*gh), 1); gh->g_name = vcopy(gname); gh->g_list = NOGE; gh->g_link = groups[h]; @@ -504,7 +504,7 @@ group(v) */ for (ap = argv+1; *ap != NOSTR; ap++) { - gp = (struct group *) calloc(sizeof *gp, 1); + gp = (struct group *) calloc(sizeof(*gp), 1); gp->ge_name = vcopy(*ap); gp->ge_link = gh->g_list; gh->g_list = gp; @@ -549,7 +549,7 @@ int null(v) void *v; { - return 0; + return(0); } /* @@ -563,13 +563,13 @@ file(v) char **argv = v; if (argv[0] == NOSTR) { - newfileinfo(); - return 0; + newfileinfo(0); + return(0); } if (setfile(*argv) < 0) - return 1; + return(1); announce(); - return 0; + return(0); } /* @@ -588,11 +588,11 @@ echo(v) if ((cp = expand(cp)) != NOSTR) { if (ap != argv) putchar(' '); - printf("%s", cp); + fputs(cp, stdout); } } putchar('\n'); - return 0; + return(0); } int @@ -601,9 +601,9 @@ Respond(v) { int *msgvec = v; if (value("Replyall") == NOSTR) - return (_Respond(msgvec)); + return(_Respond(msgvec)); else - return (_respond(msgvec)); + return(_respond(msgvec)); } /* @@ -630,7 +630,7 @@ _Respond(msgvec) head.h_to = cat(head.h_to, extract(cp, GTO)); } if (head.h_to == NIL) - return 0; + return(0); mp = &message[msgvec[0] - 1]; if ((head.h_subject = hfield("subject", mp)) == NOSTR) head.h_subject = hfield("subj", mp); @@ -639,7 +639,7 @@ _Respond(msgvec) head.h_bcc = NIL; head.h_smopts = NIL; mail1(&head, 1); - return 0; + return(0); } /* @@ -654,7 +654,7 @@ ifcmd(v) register char *cp; if (cond != CANY) { - printf("Illegal nested \"if\"\n"); + puts("Illegal nested \"if\""); return(1); } cond = CANY; @@ -686,7 +686,7 @@ elsecmd(v) switch (cond) { case CANY: - printf("\"Else\" without matching \"if\"\n"); + puts("\"Else\" without matching \"if\""); return(1); case CSEND: @@ -698,7 +698,7 @@ elsecmd(v) break; default: - printf("Mail's idea of conditions is screwed up\n"); + puts("mail's idea of conditions is screwed up"); cond = CANY; break; } @@ -714,7 +714,7 @@ endifcmd(v) { if (cond == CANY) { - printf("\"Endif\" without matching \"if\"\n"); + puts("\"Endif\" without matching \"if\""); return(1); } cond = CANY; @@ -738,14 +738,14 @@ alternates(v) return(0); for (ap = altnames; *ap; ap++) printf("%s ", *ap); - printf("\n"); + putchar('\n'); return(0); } if (altnames != 0) free((char *) altnames); - altnames = (char **) calloc((unsigned) c, sizeof (char *)); + altnames = (char **) calloc((unsigned) c, sizeof(char *)); for (ap = namelist, ap2 = altnames; *ap; ap++, ap2++) { - cp = (char *) calloc((unsigned) strlen(*ap) + 1, sizeof (char)); + cp = (char *) calloc((unsigned) strlen(*ap) + 1, sizeof(char)); strcpy(cp, *ap); *ap2 = cp; } diff --git a/usr.bin/mail/cmdtab.c b/usr.bin/mail/cmdtab.c index f35947e5a75..f6e28960ec4 100644 --- a/usr.bin/mail/cmdtab.c +++ b/usr.bin/mail/cmdtab.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmdtab.c,v 1.3 1996/06/11 12:53:35 deraadt Exp $ */ -/* $NetBSD: cmdtab.c,v 1.6 1996/06/08 19:48:15 christos Exp $ */ +/* $OpenBSD: cmdtab.c,v 1.4 1997/07/13 21:21:10 millert Exp $ */ +/* $NetBSD: cmdtab.c,v 1.7 1996/12/28 07:10:59 tls Exp $ */ /* * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)cmdtab.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.3 1996/06/11 12:53:35 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.4 1997/07/13 21:21:10 millert Exp $"; #endif #endif /* not lint */ @@ -120,5 +120,6 @@ const struct cmd cmdtab[] = { { "core", core, M|NOLIST, 0, 0 }, { "#", null, M|NOLIST, 0, 0 }, { "clobber", clobber, M|RAWLIST, 0, 1 }, + { "inc", inc, T|NOLIST, 0, 0 }, { 0, 0, 0, 0, 0 } }; diff --git a/usr.bin/mail/collect.c b/usr.bin/mail/collect.c index 8498e43da86..f6bfe3cf5c0 100644 --- a/usr.bin/mail/collect.c +++ b/usr.bin/mail/collect.c @@ -1,5 +1,5 @@ -/* $OpenBSD: collect.c,v 1.5 1997/04/13 20:32:06 deraadt Exp $ */ -/* $NetBSD: collect.c,v 1.6 1996/06/08 19:48:16 christos Exp $ */ +/* $OpenBSD: collect.c,v 1.6 1997/07/13 21:21:10 millert Exp $ */ +/* $NetBSD: collect.c,v 1.9 1997/07/09 05:25:45 mikel Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94"; #else -static char rcsid[] = "$OpenBSD: collect.c,v 1.5 1997/04/13 20:32:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: collect.c,v 1.6 1997/07/13 21:21:10 millert Exp $"; #endif #endif /* not lint */ @@ -87,11 +87,14 @@ collect(hp, printheaders) extern char *tempMail; char getsub; int omask; + int longline, lastlong, rc; /* Can deal with lines > LINESIZE */ + #if __GNUC__ /* Avoid longjmp clobbering */ (void) &escape; (void) &eofcount; (void) &getsub; + (void) &longline; #endif collf = NULL; @@ -115,7 +118,7 @@ collect(hp, printheaders) noreset++; if ((collf = Fopen(tempMail, "w+")) == NULL) { - perror(tempMail); + warn(tempMail); goto err; } unlink(tempMail); @@ -140,6 +143,8 @@ collect(hp, printheaders) escape = ESCAPE; eofcount = 0; hadintr = 0; + lastlong = 0; + longline = 0; if (!setjmp(colljmp)) { if (getsub) @@ -153,11 +158,11 @@ collect(hp, printheaders) cont: if (hadintr) { fflush(stdout); - fprintf(stderr, - "\n(Interrupt -- one more to kill letter)\n"); + fputs("\n(Interrupt -- one more to kill letter)\n", + stderr); } else { if (isatty(0)) { - printf("(continue)\n"); + puts("(continue)"); fflush(stdout); } } @@ -169,19 +174,22 @@ cont: if (c < 0) { if (value("interactive") != NOSTR && value("ignoreeof") != NOSTR && ++eofcount < 25) { - printf("Use \".\" to terminate letter\n"); + puts("Use \".\" to terminate letter"); continue; } break; } + lastlong = longline; + longline = (c == LINESIZE - 1); eofcount = 0; hadintr = 0; if (linebuf[0] == '.' && linebuf[1] == '\0' && - value("interactive") != NOSTR && + value("interactive") != NOSTR && !lastlong && (value("dot") != NOSTR || value("ignoreeof") != NOSTR)) break; - if (linebuf[0] != escape || value("interactive") == NOSTR) { - if (putline(collf, linebuf) < 0) + if (linebuf[0] != escape || value("interactive") == NOSTR || + lastlong) { + if (putline(collf, linebuf, !longline) < 0) goto err; continue; } @@ -193,12 +201,12 @@ cont: * Otherwise, it's an error. */ if (c == escape) { - if (putline(collf, &linebuf[1]) < 0) + if (putline(collf, &linebuf[1], !longline) < 0) goto err; else break; } - printf("Unknown tilde escape.\n"); + puts("Unknown tilde escape."); break; case 'C': /* @@ -280,7 +288,7 @@ cont: while (isspace(*cp)) cp++; if (*cp == '\0') { - printf("Interpolate what file?\n"); + puts("Interpolate what file?"); break; } cp = expand(cp); @@ -291,22 +299,24 @@ cont: break; } if ((fbuf = Fopen(cp, "r")) == NULL) { - perror(cp); + warn(cp); break; } printf("\"%s\" ", cp); fflush(stdout); lc = 0; cc = 0; - while (readline(fbuf, linebuf, LINESIZE) >= 0) { - lc++; - if ((t = putline(collf, linebuf)) < 0) { - Fclose(fbuf); + while ((rc = readline(fbuf, linebuf, LINESIZE)) >= 0) { + if (rc != LINESIZE - 1) + lc++; + if ((t = putline(collf, linebuf, + rc != LINESIZE-1)) < 0) { + (void)Fclose(fbuf); goto err; } cc += t; } - Fclose(fbuf); + (void)Fclose(fbuf); printf("%d/%d\n", lc, cc); break; case 'w': @@ -317,7 +327,7 @@ cont: while (*cp == ' ' || *cp == '\t') cp++; if (*cp == '\0') { - fprintf(stderr, "Write what file!?\n"); + fputs("Write what file!?\n", stderr); break; } if ((cp = expand(cp)) == NOSTR) @@ -340,12 +350,12 @@ cont: goto cont; case '?': if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) { - perror(_PATH_TILDE); + warn(_PATH_TILDE); break; } while ((t = getc(fbuf)) != EOF) (void) putchar(t); - Fclose(fbuf); + (void)Fclose(fbuf); break; case 'p': /* @@ -353,7 +363,7 @@ cont: * message without altering anything. */ rewind(collf); - printf("-------\nMessage contains:\n"); + puts("-------\nMessage contains:"); puthead(hp, stdout, GTO|GSUBJECT|GCC|GBCC|GNL); while ((t = getc(collf)) != EOF) (void) putchar(t); @@ -381,7 +391,7 @@ cont: goto out; err: if (collf != NULL) { - Fclose(collf); + (void)Fclose(collf); collf = NULL; } out: @@ -395,7 +405,7 @@ out: signal(SIGTTOU, savettou); signal(SIGTTIN, savettin); sigsetmask(omask); - return collf; + return(collf); } /* @@ -420,11 +430,11 @@ exwrite(name, fp, f) if (stat(name, &junk) >= 0 && (junk.st_mode & S_IFMT) == S_IFREG) { if (!f) fprintf(stderr, "%s: ", name); - fprintf(stderr, "File exists\n"); + fputs("File exists\n", stderr); return(-1); } if ((of = Fopen(name, "w")) == NULL) { - perror(NOSTR); + warn(NOSTR); return(-1); } lc = 0; @@ -435,12 +445,12 @@ exwrite(name, fp, f) lc++; (void) putc(c, of); if (ferror(of)) { - perror(name); - Fclose(of); + warn(name); + (void)Fclose(of); return(-1); } } - Fclose(of); + (void)Fclose(of); printf("%d/%ld\n", lc, cc); fflush(stdout); return(0); @@ -461,7 +471,7 @@ mesedit(fp, c) if (nf != NULL) { fseek(nf, 0L, 2); collf = nf; - Fclose(fp); + (void)Fclose(fp); } (void) signal(SIGINT, sigint); } @@ -483,7 +493,7 @@ mespipe(fp, cmd) char *shell; if ((nf = Fopen(tempEdit, "w+")) == NULL) { - perror(tempEdit); + warn(tempEdit); goto out; } (void) unlink(tempEdit); @@ -495,12 +505,12 @@ mespipe(fp, cmd) shell = _PATH_CSHELL; if (run_command(shell, 0, fileno(fp), fileno(nf), "-c", cmd, NOSTR) < 0) { - (void) Fclose(nf); + (void)Fclose(nf); goto out; } if (fsize(nf) == 0) { fprintf(stderr, "No bytes from \"%s\" !?\n", cmd); - (void) Fclose(nf); + (void)Fclose(nf); goto out; } /* @@ -508,7 +518,7 @@ mespipe(fp, cmd) */ (void) fseek(nf, 0L, 2); collf = nf; - (void) Fclose(fp); + (void)Fclose(fp); out: (void) signal(SIGINT, sigint); } @@ -532,7 +542,7 @@ forward(ms, fp, f) struct ignoretab *ig; char *tabst; - msgvec = (int *) salloc((msgCount+1) * sizeof *msgvec); + msgvec = (int *) salloc((msgCount+1) * sizeof(*msgvec)); if (msgvec == (int *) NOSTR) return(0); if (getmsglist(ms, msgvec, 0) < 0) @@ -540,7 +550,7 @@ forward(ms, fp, f) if (*msgvec == 0) { *msgvec = first(0, MMNORM); if (*msgvec == NULL) { - printf("No appropriate messages\n"); + puts("No appropriate messages"); return(0); } msgvec[1] = NULL; @@ -550,18 +560,18 @@ forward(ms, fp, f) else if ((tabst = value("indentprefix")) == NOSTR) tabst = "\t"; ig = isupper(f) ? NULL : ignore; - printf("Interpolating:"); + fputs("Interpolating:", stdout); for (; *msgvec != 0; msgvec++) { struct message *mp = message + *msgvec - 1; touch(mp); printf(" %d", *msgvec); if (send(mp, fp, ig, tabst) < 0) { - perror(tempMail); + warn(tempMail); return(-1); } } - printf("\n"); + putchar('\n'); return(0); } @@ -649,6 +659,6 @@ savedeadletter(fp) return; while ((c = getc(fp)) != EOF) (void) putc(c, dbuf); - Fclose(dbuf); + (void)Fclose(dbuf); rewind(fp); } diff --git a/usr.bin/mail/def.h b/usr.bin/mail/def.h index 88132e5b7f7..5b1b0672d22 100644 --- a/usr.bin/mail/def.h +++ b/usr.bin/mail/def.h @@ -1,5 +1,5 @@ -/* $OpenBSD: def.h,v 1.4 1997/03/29 03:01:45 millert Exp $ */ -/* $NetBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $ */ +/* $OpenBSD: def.h,v 1.5 1997/07/13 21:21:10 millert Exp $ */ +/* $NetBSD: def.h,v 1.9 1996/12/28 07:11:00 tls Exp $ */ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. All rights reserved. @@ -32,8 +32,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)def.h 8.2 (Berkeley) 3/21/94 - * $NetBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $ + * @(#)def.h 8.4 (Berkeley) 4/20/95 + * $OpenBSD: def.h,v 1.5 1997/07/13 21:21:10 millert Exp $ */ /* @@ -46,13 +46,14 @@ #include <sys/stat.h> #include <sys/time.h> +#include <ctype.h> +#include <err.h> #include <signal.h> -#include <termios.h> -#include <unistd.h> -#include <stdlib.h> #include <stdio.h> -#include <ctype.h> +#include <stdlib.h> #include <string.h> +#include <termios.h> +#include <unistd.h> #include "pathnames.h" #define APPEND /* New mail goes to end of mailbox */ @@ -71,8 +72,8 @@ struct message { short m_flag; /* flags, see below */ - int m_block; /* block number of this message */ int m_offset; /* offset in block of message */ + int m_block; /* block number of this message */ int m_size; /* Bytes in the message */ int m_lines; /* Lines in the message */ }; diff --git a/usr.bin/mail/dotlock.c b/usr.bin/mail/dotlock.c index a16bf531ed1..713b201bf54 100644 --- a/usr.bin/mail/dotlock.c +++ b/usr.bin/mail/dotlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dotlock.c,v 1.1 1996/06/11 12:53:37 deraadt Exp $ */ +/* $OpenBSD: dotlock.c,v 1.2 1997/07/13 21:21:11 millert Exp $ */ /* $NetBSD: dotlock.c,v 1.1 1996/06/08 19:48:19 christos Exp $ */ /* @@ -31,7 +31,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: dotlock.c,v 1.1 1996/06/11 12:53:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: dotlock.c,v 1.2 1997/07/13 21:21:11 millert Exp $"; #endif #include <sys/types.h> @@ -90,7 +90,7 @@ create_exclusive(fname) else ptr++; - (void) snprintf(path, sizeof(path), "%.*s.%s.%x", + (void) snprintf(path, sizeof(path), "%.*s.%s.%x", ptr - fname, fname, hostname, cookie); /* @@ -99,13 +99,13 @@ create_exclusive(fname) for (ntries = 0; ntries < 5; ntries++) { fd = open(path, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_SYNC, 0); if (fd != -1) { - (void) close(fd); + (void)close(fd); break; } else if (errno == EEXIST) continue; else - return -1; + return(-1); } /* @@ -129,15 +129,15 @@ create_exclusive(fname) */ if (st.st_nlink != 2) { errno = EEXIST; - return -1; + return(-1); } - return 0; + return(0); bad: serrno = errno; (void) unlink(path); errno = serrno; - return -1; + return(-1); } int @@ -166,13 +166,13 @@ dot_lock(fname, pollinterval, fp, msg) (void) sigprocmask(SIG_BLOCK, &nset, &oset); if (create_exclusive(path) != -1) { (void) sigprocmask(SIG_SETMASK, &oset, NULL); - return 0; + return(0); } else (void) sigprocmask(SIG_SETMASK, &oset, NULL); if (errno != EEXIST) - return -1; + return(-1); if (fp && msg) (void) fputs(msg, fp); @@ -180,7 +180,7 @@ dot_lock(fname, pollinterval, fp, msg) if (pollinterval) { if (pollinterval == -1) { errno = EEXIST; - return -1; + return(-1); } sleep(pollinterval); } diff --git a/usr.bin/mail/edit.c b/usr.bin/mail/edit.c index 60dbc3d8d47..808f4528071 100644 --- a/usr.bin/mail/edit.c +++ b/usr.bin/mail/edit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.2 1996/06/11 12:53:38 deraadt Exp $ */ +/* $OpenBSD: edit.c,v 1.3 1997/07/13 21:21:11 millert Exp $ */ /* $NetBSD: edit.c,v 1.5 1996/06/08 19:48:20 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)edit.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: edit.c,v 1.2 1996/06/11 12:53:38 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: edit.c,v 1.3 1997/07/13 21:21:11 millert Exp $"; #endif #endif /* not lint */ @@ -61,7 +61,7 @@ editor(v) { int *msgvec = v; - return edit1(msgvec, 'e'); + return(edit1(msgvec, 'e')); } /* @@ -73,7 +73,7 @@ visual(v) { int *msgvec = v; - return edit1(msgvec, 'v'); + return(edit1(msgvec, 'v')); } /* @@ -103,7 +103,7 @@ edit1(msgvec, type) char *p; printf("Edit message %d [ynq]? ", msgvec[i]); - if (fgets(buf, sizeof buf, stdin) == 0) + if (fgets(buf, sizeof(buf), stdin) == 0) break; for (p = buf; *p == ' ' || *p == '\t'; p++) ; @@ -132,12 +132,12 @@ edit1(msgvec, type) break; } if (ferror(otf)) - perror("/tmp"); - (void) Fclose(fp); + warn("/tmp"); + (void)Fclose(fp); } (void) signal(SIGINT, sigint); } - return 0; + return(0); } /* @@ -160,11 +160,11 @@ run_editor(fp, size, type, readonly) extern char *tempEdit; if ((t = creat(tempEdit, readonly ? 0400 : 0600)) < 0) { - perror(tempEdit); + warn(tempEdit); goto out; } if ((nf = Fdopen(t, "w")) == NULL) { - perror(tempEdit); + warn(tempEdit); (void) unlink(tempEdit); goto out; } @@ -181,13 +181,13 @@ run_editor(fp, size, type, readonly) modtime = statb.st_mtime; if (ferror(nf)) { (void) Fclose(nf); - perror(tempEdit); + warn(tempEdit); (void) unlink(tempEdit); nf = NULL; goto out; } if (Fclose(nf) < 0) { - perror(tempEdit); + warn(tempEdit); (void) unlink(tempEdit); nf = NULL; goto out; @@ -208,7 +208,7 @@ run_editor(fp, size, type, readonly) goto out; } if (stat(tempEdit, &statb) < 0) { - perror(tempEdit); + warn(tempEdit); goto out; } if (modtime == statb.st_mtime) { @@ -219,11 +219,11 @@ run_editor(fp, size, type, readonly) * Now switch to new file. */ if ((nf = Fopen(tempEdit, "a+")) == NULL) { - perror(tempEdit); + warn(tempEdit); (void) unlink(tempEdit); goto out; } (void) unlink(tempEdit); out: - return nf; + return(nf); } diff --git a/usr.bin/mail/extern.h b/usr.bin/mail/extern.h index 841a915d714..852f74be5a4 100644 --- a/usr.bin/mail/extern.h +++ b/usr.bin/mail/extern.h @@ -1,5 +1,5 @@ -/* $OpenBSD: extern.h,v 1.5 1997/05/30 08:51:37 deraadt Exp $ */ -/* $NetBSD: extern.h,v 1.4 1996/06/08 19:48:21 christos Exp $ */ +/* $OpenBSD: extern.h,v 1.6 1997/07/13 21:21:12 millert Exp $ */ +/* $NetBSD: extern.h,v 1.7 1997/07/09 05:22:00 mikel Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -33,8 +33,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)extern.h 8.1 (Berkeley) 6/6/93 - * $NetBSD: extern.h,v 1.4 1996/06/08 19:48:21 christos Exp $ + * @(#)extern.h 8.2 (Berkeley) 4/20/95 + * $OpenBSD: extern.h,v 1.6 1997/07/13 21:21:12 millert Exp $ */ struct name; @@ -158,6 +158,8 @@ struct ignoretab; int ignore1 __P((char *[], struct ignoretab *, char *)); int igshow __P((struct ignoretab *, char *)); void intr __P((int)); +int inc __P((void *)); +int incfile __P((void)); int isdate __P((char [])); int isdir __P((char [])); int isfileaddr __P((char *)); @@ -173,7 +175,7 @@ struct var * int mail __P((struct name *, struct name *, struct name *, struct name *, char *)); void mail1 __P((struct header *, int)); -void makemessage __P((FILE *)); +void makemessage __P((FILE *, int)); void mark __P((int)); int markall __P((char [], int)); int matchsender __P((char *, int)); @@ -185,7 +187,7 @@ void mespipe __P((FILE *, char [])); int messize __P((void *)); int metamess __P((int, int)); int more __P((void *)); -int newfileinfo __P((void)); +int newfileinfo __P((int)); int next __P((void *)); int null __P((void *)); void panic __P((const char *, ...)) @@ -200,7 +202,7 @@ void prettyprint __P((struct name *)); void printgroup __P((char [])); void printhead __P((int)); int puthead __P((struct header *, FILE *, int)); -int putline __P((FILE *, char *)); +int putline __P((FILE *, char *, int)); int pversion __P((void *)); void quit __P((void)); int quitcmd __P((void *)); @@ -230,7 +232,7 @@ int sendmail __P((void *)); int set __P((void *)); int setfile __P((char *)); void setmsize __P((int)); -void setptr __P((FILE *)); +void setptr __P((FILE *, off_t)); void setscreensize __P((void)); int shell __P((void *)); void sigchild __P((int)); @@ -264,3 +266,5 @@ int visual __P((void *)); int wait_child __P((int)); int wait_command __P((int)); int writeback __P((FILE *)); + +extern char *__progname; diff --git a/usr.bin/mail/fio.c b/usr.bin/mail/fio.c index acb0d414d56..9fd45a9c4cf 100644 --- a/usr.bin/mail/fio.c +++ b/usr.bin/mail/fio.c @@ -1,5 +1,5 @@ -/* $OpenBSD: fio.c,v 1.5 1997/05/30 08:51:39 deraadt Exp $ */ -/* $NetBSD: fio.c,v 1.5 1996/06/08 19:48:22 christos Exp $ */ +/* $OpenBSD: fio.c,v 1.6 1997/07/13 21:21:12 millert Exp $ */ +/* $NetBSD: fio.c,v 1.8 1997/07/07 22:57:55 phil Exp $ */ /* * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #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"; #else -static char rcsid[] = "$OpenBSD: fio.c,v 1.5 1997/05/30 08:51:39 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: fio.c,v 1.6 1997/07/13 21:21:12 millert Exp $"; #endif #endif /* not lint */ @@ -61,58 +61,63 @@ static char rcsid[] = "$OpenBSD: fio.c,v 1.5 1997/05/30 08:51:39 deraadt Exp $"; * Set up the input pointers while copying the mail file into /tmp. */ void -setptr(ibuf) +setptr(ibuf, offset) register FILE *ibuf; + off_t offset; { extern char *tmpdir; register int c, count; register 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); - if ((c = mkstemp(pathbuf)) == -1 || - (mestmp = Fdopen(c, "r+")) == NULL) { - (void)fprintf(stderr, "mail: can't open %s\n", pathbuf); - exit(1); - } + (void)snprintf(pathbuf, sizeof(pathbuf), "%s/mail.XXXXXXXXXX", tmpdir); + if ((c = mkstemp(pathbuf)) == -1 || (mestmp = Fdopen(c, "r+")) == NULL) + err(1, "can't open %s", pathbuf); (void)unlink(pathbuf); - msgCount = 0; + if (offset == 0) { + msgCount = 0; + } else { + /* Seek into the file to get to the new messages */ + (void) fseek(ibuf, offset, 0); + /* + * 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; this.m_block = 0; this.m_offset = 0; for (;;) { - if (fgets(linebuf, LINESIZE, ibuf) == NULL) { - if (append(&this, mestmp)) { - perror("temporary file"); - exit(1); - } - makemessage(mestmp); + if (fgets(linebuf, sizeof(linebuf), ibuf) == NULL) { + if (append(&this, mestmp)) + err(1, "temporary file"); + makemessage(mestmp, omsgCount); return; } count = strlen(linebuf); - (void) fwrite(linebuf, sizeof *linebuf, count, otf); - if (ferror(otf)) { - perror("/tmp"); - exit(1); - } - linebuf[count - 1] = 0; + (void) fwrite(linebuf, sizeof(*linebuf), count, otf); + if (ferror(otf)) + err(1, "/tmp"); + linebuf[count - 1] = '\0'; if (maybe && linebuf[0] == 'F' && ishead(linebuf)) { msgCount++; - if (append(&this, mestmp)) { - perror("temporary file"); - exit(1); - } + if (append(&this, mestmp)) + err(1, "temporary file"); this.m_flag = MUSED|MNEW; this.m_size = 0; this.m_lines = 0; @@ -150,21 +155,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; { register int c; c = strlen(linebuf); - (void) fwrite(linebuf, sizeof *linebuf, c, obuf); - (void) putc('\n', obuf); + (void) fwrite(linebuf, sizeof(*linebuf), c, obuf); + if (outlf) { + (void) putc('\n', obuf); + c++; + } if (ferror(obuf)) - return (-1); - return (c + 1); + return(-1); + return(c); } /* @@ -182,11 +191,12 @@ readline(ibuf, linebuf, linesize) clearerr(ibuf); if (fgets(linebuf, linesize, ibuf) == NULL) - return -1; + return(-1); + n = strlen(linebuf); if (n > 0 && linebuf[n - 1] == '\n') linebuf[--n] = '\0'; - return n; + return(n); } /* @@ -200,10 +210,10 @@ setinput(mp) fflush(otf); if (fseek(itf, (long)positionof(mp->m_block, mp->m_offset), 0) < 0) { - perror("fseek"); + warn("fseek"); panic("temporary file seek"); } - return (itf); + return(itf); } /* @@ -211,24 +221,31 @@ setinput(mp) * a dynamically allocated message structure. */ void -makemessage(f) +makemessage(f, omsgCount) FILE *f; + int omsgCount; { - register size = (msgCount + 1) * sizeof (struct message); - - if (message != 0) - free((char *) message); - if ((message = (struct message *) malloc((unsigned) size)) == 0) - panic("Insufficient memory for %d messages", msgCount); - dot = message; - size -= sizeof (struct message); + register size = (msgCount + 1) * sizeof(struct message); + + if (omsgCount) { + message = (struct message *)realloc(message, (unsigned) size); + if (message == 0) + panic("Insufficient memory for %d messages\n", msgCount); + } else { + if (message != 0) + free((char *) message); + if ((message = (struct message *) malloc((unsigned) size)) == 0) + panic("Insufficient memory for %d messages", msgCount); + dot = message; + } + size -= (omsgCount + 1) * sizeof(struct message); fflush(f); - (void) lseek(fileno(f), (off_t)sizeof *message, 0); - if (read(fileno(f), (char *) message, size) != size) + (void) lseek(fileno(f), (off_t)sizeof(*message), 0); + if (read(fileno(f), (void *) &message[omsgCount], size) != size) panic("Message temporary file corrupted"); message[msgCount].m_size = 0; message[msgCount].m_lines = 0; - Fclose(f); + (void)Fclose(f); } /* @@ -240,7 +257,7 @@ append(mp, f) struct message *mp; FILE *f; { - return fwrite((char *) mp, sizeof *mp, 1, f) != 1; + return(fwrite((char *) mp, sizeof(*mp), 1, f) != 1); } /* @@ -301,8 +318,8 @@ fsize(iob) struct stat sbuf; if (fstat(fileno(iob), &sbuf) < 0) - return 0; - return sbuf.st_size; + return(0); + return(sbuf.st_size); } /* @@ -336,73 +353,73 @@ expand(name) */ switch (*name) { case '%': - findmail(name[1] ? name + 1 : myname, xname, sizeof xname); - return savestr(xname); + findmail(name[1] ? name + 1 : myname, xname, sizeof(xname)); + return(savestr(xname)); case '#': if (name[1] != 0) break; if (prevfile[0] == 0) { - printf("No previous file\n"); - return NOSTR; + puts("No previous file"); + return(NOSTR); } - return savestr(prevfile); + return(savestr(prevfile)); case '&': if (name[1] == 0 && (name = value("MBOX")) == NOSTR) name = "~/mbox"; /* fall through */ } - if (name[0] == '+' && getfold(cmdbuf, sizeof cmdbuf) >= 0) { - snprintf(xname, sizeof xname, "%s/%s", cmdbuf, name + 1); + if (name[0] == '+' && getfold(cmdbuf, sizeof(cmdbuf)) >= 0) { + snprintf(xname, sizeof(xname), "%s/%s", cmdbuf, name + 1); name = savestr(xname); } /* catch the most common shell meta character */ if (name[0] == '~' && (name[1] == '/' || name[1] == '\0')) { - snprintf(xname, sizeof xname, "%s%s", homedir, name + 1); + snprintf(xname, sizeof(xname), "%s%s", homedir, name + 1); name = savestr(xname); } if (!anyof(name, "~{[*?$`'\"\\")) - return name; + return(name); if (pipe(pivec) < 0) { - perror("pipe"); - return name; + warn("pipe"); + return(name); } - snprintf(cmdbuf, sizeof cmdbuf, "echo %s", name); + snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name); if ((shell = value("SHELL")) == NOSTR) shell = _PATH_CSHELL; pid = start_command(shell, 0, -1, pivec[1], "-c", cmdbuf, NOSTR); if (pid < 0) { - close(pivec[0]); - close(pivec[1]); - return NOSTR; + (void)close(pivec[0]); + (void)close(pivec[1]); + return(NOSTR); } - close(pivec[1]); - l = read(pivec[0], xname, BUFSIZ); - close(pivec[0]); + (void)close(pivec[1]); + l = read(pivec[0], xname, PATHSIZE); + (void)close(pivec[0]); if (wait_child(pid) < 0 && wait_status.w_termsig != SIGPIPE) { fprintf(stderr, "\"%s\": Expansion failed.\n", name); - return NOSTR; + return(NOSTR); } if (l < 0) { - perror("read"); - return NOSTR; + warn("read"); + return(NOSTR); } if (l == 0) { fprintf(stderr, "\"%s\": No match.\n", name); - return NOSTR; + return(NOSTR); } - if (l == BUFSIZ) { + if (l == PATHSIZE) { fprintf(stderr, "\"%s\": Expansion buffer overflow.\n", name); - return NOSTR; + return(NOSTR); } - xname[l] = 0; + xname[l] = '\0'; for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--) ; cp[1] = '\0'; if (strchr(xname, ' ') && stat(xname, &sbuf) < 0) { fprintf(stderr, "\"%s\": Ambiguous.\n", name); - return NOSTR; + return(NOSTR); } - return savestr(xname); + return(savestr(xname)); } /* @@ -416,13 +433,13 @@ getfold(name, namelen) char *folder; if ((folder = value("folder")) == NOSTR) - return (-1); + return(-1); if (*folder == '/') { strncpy(name, folder, namelen-1); name[namelen-1] = '\0'; } else snprintf(name, namelen, "%s/%s", homedir, folder); - return (0); + return(0); } /* @@ -438,8 +455,8 @@ getdeadletter() else if (*cp != '/') { char buf[PATHSIZE]; - (void) snprintf(buf, sizeof buf, "~/%s", cp); + (void) snprintf(buf, sizeof(buf), "~/%s", cp); cp = expand(buf); } - return cp; + return(cp); } diff --git a/usr.bin/mail/getname.c b/usr.bin/mail/getname.c index 5f62d42ba62..3d432deed84 100644 --- a/usr.bin/mail/getname.c +++ b/usr.bin/mail/getname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getname.c,v 1.2 1996/06/11 12:53:40 deraadt Exp $ */ +/* $OpenBSD: getname.c,v 1.3 1997/07/13 21:21:13 millert Exp $ */ /* $NetBSD: getname.c,v 1.4 1996/06/08 19:48:23 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)getname.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: getname.c,v 1.2 1996/06/11 12:53:40 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: getname.c,v 1.3 1997/07/13 21:21:13 millert Exp $"; #endif #endif /* not lint */ @@ -58,8 +58,8 @@ getname(uid) struct passwd *pw; if ((pw = getpwuid(uid)) == NULL) - return NOSTR; - return pw->pw_name; + return(NOSTR); + return(pw->pw_name); } /* @@ -73,6 +73,6 @@ getuserid(name) struct passwd *pw; if ((pw = getpwnam(name)) == NULL) - return -1; - return pw->pw_uid; + return(-1); + return(pw->pw_uid); } diff --git a/usr.bin/mail/head.c b/usr.bin/mail/head.c index c151fb087a3..1478b63ff4c 100644 --- a/usr.bin/mail/head.c +++ b/usr.bin/mail/head.c @@ -1,5 +1,5 @@ -/* $OpenBSD: head.c,v 1.2 1996/06/11 12:53:42 deraadt Exp $ */ -/* $NetBSD: head.c,v 1.5 1996/06/08 19:48:26 christos Exp $ */ +/* $OpenBSD: head.c,v 1.3 1997/07/13 21:21:13 millert Exp $ */ +/* $NetBSD: head.c,v 1.6 1996/12/28 07:11:03 tls Exp $ */ /* * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)head.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)head.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: head.c,v 1.2 1996/06/11 12:53:42 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: head.c,v 1.3 1997/07/13 21:21:13 millert Exp $"; #endif #endif /* not lint */ @@ -67,20 +67,20 @@ ishead(linebuf) cp = linebuf; if (*cp++ != 'F' || *cp++ != 'r' || *cp++ != 'o' || *cp++ != 'm' || *cp++ != ' ') - return (0); + return(0); parse(linebuf, &hl, parbuf); if (hl.l_from == NOSTR || hl.l_date == NOSTR) { fail(linebuf, "No from or date field"); - return (0); + return(0); } if (!isdate(hl.l_date)) { fail(linebuf, "Date field not legal date"); - return (0); + return(0); } /* * I guess we got it! */ - return (1); + return(1); } /*ARGSUSED*/ @@ -149,7 +149,7 @@ copyin(src, space) while ((*cp++ = *src++) != '\0') ; *space = cp; - return (top); + return(top); } /* @@ -170,18 +170,21 @@ copyin(src, space) * 'N' A new line */ char ctype[] = "Aaa Aaa O0 00:00:00 0000"; -char ctype_without_secs[] = "Aaa Aaa O0 00:00 0000"; char tmztype[] = "Aaa Aaa O0 00:00:00 AAA 0000"; -char tmztype_without_secs[] = "Aaa Aaa O0 00:00 AAA 0000"; +/* + * Yuck. If the mail file is created by Sys V (Solaris), + * there are no seconds in the time... + */ +char SysV_ctype[] = "Aaa Aaa O0 00:00 0000"; +char SysV_tmztype[] = "Aaa Aaa O0 00:00 AAA 0000"; int isdate(date) char date[]; { - return cmatch(date, ctype_without_secs) || - cmatch(date, tmztype_without_secs) || - cmatch(date, ctype) || cmatch(date, tmztype); + return(cmatch(date, ctype) || cmatch(date, tmztype) + || cmatch(date, SysV_tmztype) || cmatch(date, SysV_ctype)); } /* @@ -197,37 +200,37 @@ cmatch(cp, tp) switch (*tp++) { case 'a': if (!islower(*cp++)) - return 0; + return(0); break; case 'A': if (!isupper(*cp++)) - return 0; + return(0); break; case ' ': if (*cp++ != ' ') - return 0; + return(0); break; case '0': if (!isdigit(*cp++)) - return 0; + return(0); break; case 'O': if (*cp != ' ' && !isdigit(*cp)) - return 0; + return(0); cp++; break; case ':': if (*cp++ != ':') - return 0; + return(0); break; case 'N': if (*cp++ != '\n') - return 0; + return(0); break; } if (*cp || *tp) - return 0; - return (1); + return(0); + return(1); } /* @@ -243,7 +246,7 @@ nextword(wp, wbuf) if (wp == NOSTR) { *wbuf = 0; - return (NOSTR); + return(NOSTR); } while ((c = *wp++) && c != ' ' && c != '\t') { *wbuf++ = c; @@ -260,6 +263,6 @@ nextword(wp, wbuf) for (; c == ' ' || c == '\t'; c = *wp++) ; if (c == 0) - return (NOSTR); - return (wp - 1); + return(NOSTR); + return(wp - 1); } diff --git a/usr.bin/mail/lex.c b/usr.bin/mail/lex.c index 26b8513c25c..bcd3fb91613 100644 --- a/usr.bin/mail/lex.c +++ b/usr.bin/mail/lex.c @@ -1,5 +1,5 @@ -/* $OpenBSD: lex.c,v 1.5 1997/05/30 08:51:40 deraadt Exp $ */ -/* $NetBSD: lex.c,v 1.7 1996/06/08 19:48:28 christos Exp $ */ +/* $OpenBSD: lex.c,v 1.6 1997/07/13 21:21:13 millert Exp $ */ +/* $NetBSD: lex.c,v 1.10 1997/05/17 19:55:13 pk Exp $ */ /* * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)lex.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)lex.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: lex.c,v 1.5 1997/05/30 08:51:40 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: lex.c,v 1.6 1997/07/13 21:21:13 millert Exp $"; #endif #endif /* not lint */ @@ -75,36 +75,36 @@ setfile(name) extern int errno; if ((name = expand(name)) == NOSTR) - return -1; + return(-1); if ((ibuf = Fopen(name, "r")) == NULL) { if (!isedit && errno == ENOENT) goto nomail; - perror(name); + warn(name); return(-1); } if (fstat(fileno(ibuf), &stb) < 0) { - perror("fstat"); - Fclose(ibuf); - return (-1); + warn("fstat"); + (void)Fclose(ibuf); + return(-1); } switch (stb.st_mode & S_IFMT) { case S_IFDIR: - Fclose(ibuf); + (void)Fclose(ibuf); errno = EISDIR; - perror(name); - return (-1); + warn(name); + return(-1); case S_IFREG: break; default: - Fclose(ibuf); + (void)Fclose(ibuf); errno = EINVAL; - perror(name); - return (-1); + warn(name); + return(-1); } /* @@ -127,10 +127,10 @@ setfile(name) if ((i = open(name, 1)) < 0) readonly++; else - close(i); + (void)close(i); if (shudclob) { - fclose(itf); - fclose(otf); + (void)fclose(itf); + (void)fclose(otf); } shudclob = 1; edit = isedit; @@ -138,30 +138,63 @@ setfile(name) if (name != mailname) strcpy(mailname, name); mailsize = fsize(ibuf); - if ((otf = fopen(tempMesg, "w")) == NULL) { - perror(tempMesg); - exit(1); - } + if ((otf = fopen(tempMesg, "w")) == NULL) + err(1, tempMesg); (void) fcntl(fileno(otf), F_SETFD, 1); - if ((itf = fopen(tempMesg, "r")) == NULL) { - perror(tempMesg); - exit(1); - } + if ((itf = fopen(tempMesg, "r")) == NULL) + err(1, tempMesg); (void) fcntl(fileno(itf), F_SETFD, 1); rm(tempMesg); - setptr(ibuf); + setptr(ibuf, 0); setmsize(msgCount); - Fclose(ibuf); + /* + * New mail may have arrived while we were reading + * the mail file, so reset mailsize to be where + * we really are in the file... + */ + mailsize = ftell(ibuf); + (void)Fclose(ibuf); relsesigs(); sawcom = 0; if (!edit && msgCount == 0) { nomail: fprintf(stderr, "No mail for %s\n", who); - return -1; + return(-1); } return(0); } +/* + * Incorporate any new mail that has arrived since we first + * started reading mail. + */ +int +incfile() +{ + int newsize; + int omsgCount = msgCount; + FILE *ibuf; + + ibuf = Fopen(mailname, "r"); + if (ibuf == NULL) + return(-1); + holdsigs(); + newsize = fsize(ibuf); + if (newsize == 0) + return(-1); /* mail box is now empty??? */ + if (newsize < mailsize) + return(-1); /* mail box has shrunk??? */ + if (newsize == mailsize) + return(0); /* no new mail */ + setptr(ibuf, mailsize); + setmsize(msgCount); + mailsize = ftell(ibuf); + (void)Fclose(ibuf); + relsesigs(); + return(msgCount - omsgCount); +} + + int *msgvec; int reset_on_stop; /* do a reset() if stopped */ @@ -196,6 +229,8 @@ commands() * string space, and flush the output. */ if (!sourcing && value("interactive") != NOSTR) { + if ((value("autoinc") != NOSTR) && (incfile() > 0)) + puts("New mail has arrived."); reset_on_stop = 1; printf(prompt); } @@ -231,7 +266,7 @@ commands() if (value("interactive") != NOSTR && value("ignoreeof") != NOSTR && ++eofloop < 25) { - printf("Use \"quit\" to quit.\n"); + puts("Use \"quit\" to quit."); continue; } break; @@ -275,7 +310,7 @@ execute(linebuf, contxt) ; if (*cp == '!') { if (sourcing) { - printf("Can't \"!\" while sourcing\n"); + puts("Can't \"!\" while sourcing"); goto out; } shell(cp+1); @@ -344,7 +379,7 @@ execute(linebuf, contxt) * legal message. */ if (msgvec == 0) { - printf("Illegal use of \"message list\"\n"); + puts("Illegal use of \"message list\""); break; } if ((c = getmsglist(cp, msgvec, com->c_msgflag)) < 0) @@ -355,7 +390,7 @@ execute(linebuf, contxt) msgvec[1] = NULL; } if (*msgvec == NULL) { - printf("No applicable messages\n"); + puts("No applicable messages"); break; } e = (*com->c_func)(msgvec); @@ -367,7 +402,7 @@ execute(linebuf, contxt) * if none exist. */ if (msgvec == 0) { - printf("Illegal use of \"message list\"\n"); + puts("Illegal use of \"message list\""); break; } if (getmsglist(cp, msgvec, com->c_msgflag) < 0) @@ -390,7 +425,7 @@ execute(linebuf, contxt) * A vector of strings, in shell style. */ if ((c = getrawlist(cp, arglist, - sizeof arglist / sizeof *arglist)) < 0) + sizeof(arglist) / sizeof(*arglist))) < 0) break; if (c < com->c_minargs) { printf("%s requires at least %d arg(s)\n", @@ -424,12 +459,12 @@ out: */ if (e) { if (e < 0) - return 1; + return(1); if (loading) - return 1; + return(1); if (sourcing) unstack(); - return 0; + return(0); } if (com == NULL) return(0); @@ -455,7 +490,7 @@ setmsize(sz) if (msgvec != 0) free((char *) msgvec); - msgvec = (int *) calloc((unsigned) (sz + 1), sizeof *msgvec); + msgvec = (int *) calloc((unsigned) (sz + 1), sizeof(*msgvec)); } /* @@ -520,10 +555,10 @@ intr(s) close_all_files(); if (image >= 0) { - close(image); + (void)close(image); image = -1; } - fprintf(stderr, "Interrupt\n"); + fputs("Interrupt\n", stderr); reset(0); } @@ -571,7 +606,7 @@ announce() { int vec[2], mdot; - mdot = newfileinfo(); + mdot = newfileinfo(0); vec[0] = mdot; vec[1] = 0; dot = &message[mdot - 1]; @@ -587,23 +622,24 @@ announce() * Return a likely place to set dot. */ int -newfileinfo() +newfileinfo(omsgCount) + int omsgCount; { register struct message *mp; register int u, n, mdot, d, s; - char fname[PATHSIZE+1], zname[PATHSIZE+1], *ename; + char fname[PATHSIZE], zname[PATHSIZE], *ename; - for (mp = &message[0]; mp < &message[msgCount]; mp++) + for (mp = &message[omsgCount]; mp < &message[msgCount]; mp++) if (mp->m_flag & MNEW) break; if (mp >= &message[msgCount]) - for (mp = &message[0]; mp < &message[msgCount]; mp++) + for (mp = &message[omsgCount]; mp < &message[msgCount]; mp++) if ((mp->m_flag & MREAD) == 0) break; if (mp < &message[msgCount]) mdot = mp - &message[0] + 1; else - mdot = 1; + mdot = omsgCount + 1; s = d = 0; for (mp = &message[0], n = 0, u = 0; mp < &message[msgCount]; mp++) { if (mp->m_flag & MNEW) @@ -616,16 +652,17 @@ newfileinfo() s++; } ename = mailname; - if (getfold(fname, sizeof fname) >= 0) { - strcat(fname, "/"); + if (getfold(fname, sizeof(fname)) >= 0) { + strncat(fname, "/", sizeof(fname) - strlen(fname) - 1); if (strncmp(fname, mailname, strlen(fname)) == 0) { - snprintf(zname, sizeof zname, "+%s", mailname + strlen(fname)); + snprintf(zname, sizeof(zname), "+%s", + mailname + strlen(fname)); ename = zname; } } printf("\"%s\": ", ename); if (msgCount == 1) - printf("1 message"); + fputs("1 message", stdout); else printf("%d messages", msgCount); if (n > 0) @@ -637,8 +674,8 @@ newfileinfo() if (s > 0) printf(" %d saved", s); if (readonly) - printf(" [Read only]"); - printf("\n"); + fputs(" [Read only]", stdout); + putchar('\n'); return(mdot); } @@ -676,5 +713,5 @@ load(name) loading = 0; sourcing = 0; input = oldin; - Fclose(in); + (void)Fclose(in); } diff --git a/usr.bin/mail/list.c b/usr.bin/mail/list.c index c4a2813e4a1..898bab95761 100644 --- a/usr.bin/mail/list.c +++ b/usr.bin/mail/list.c @@ -1,5 +1,5 @@ -/* $OpenBSD: list.c,v 1.4 1997/05/30 08:51:42 deraadt Exp $ */ -/* $NetBSD: list.c,v 1.4 1996/06/08 19:48:30 christos Exp $ */ +/* $OpenBSD: list.c,v 1.5 1997/07/13 21:21:14 millert Exp $ */ +/* $NetBSD: list.c,v 1.7 1997/07/09 05:23:36 mikel Exp $ */ /* * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)list.c 8.2 (Berkeley) 4/19/94"; +static char sccsid[] = "@(#)list.c 8.4 (Berkeley) 5/1/95"; #else -static char rcsid[] = "$OpenBSD: list.c,v 1.4 1997/05/30 08:51:42 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: list.c,v 1.5 1997/07/13 21:21:14 millert Exp $"; #endif #endif /* not lint */ @@ -68,7 +68,7 @@ getmsglist(buf, vector, flags) if (msgCount == 0) { *vector = 0; - return 0; + return(0); } if (markall(buf, flags) < 0) return(-1); @@ -145,7 +145,7 @@ markall(buf, f) case TNUMBER: number: if (star) { - printf("No numbers mixed with *\n"); + puts("No numbers mixed with *"); return(-1); } mc++; @@ -172,14 +172,14 @@ number: case TPLUS: if (beg != 0) { - printf("Non-numeric second argument\n"); + puts("Non-numeric second argument"); return(-1); } i = valdot; do { i++; if (i > msgCount) { - printf("Referencing beyond EOF\n"); + puts("Referencing beyond EOF"); return(-1); } } while ((message[i - 1].m_flag & MDELETED) != f); @@ -192,7 +192,7 @@ number: do { i--; if (i <= 0) { - printf("Referencing before 1\n"); + puts("Referencing before 1"); return(-1); } } while ((message[i - 1].m_flag & MDELETED) != f); @@ -202,7 +202,7 @@ number: case TSTRING: if (beg != 0) { - printf("Non-numeric second argument\n"); + puts("Non-numeric second argument"); return(-1); } other++; @@ -229,14 +229,14 @@ number: case TSTAR: if (other) { - printf("Can't mix \"*\" with anything\n"); + puts("Can't mix \"*\" with anything"); return(-1); } star++; break; case TERROR: - return -1; + return(-1); } tok = scan(&bufp); } @@ -250,7 +250,7 @@ number: mc++; } if (mc == 0) { - printf("No applicable messages.\n"); + puts("No applicable messages."); return(-1); } return(0); @@ -306,7 +306,7 @@ number: namelist[0]); for (np = &namelist[1]; *np != NOSTR; np++) printf(", %s", *np); - printf("}\n"); + puts("}"); return(-1); } } @@ -334,11 +334,11 @@ number: if (mp >= &message[msgCount]) { register struct coltab *colp; - printf("No messages satisfy"); + fputs("No messages satisfy", stdout); for (colp = &coltab[0]; colp->co_char; colp++) if (colp->co_bit & colmod) printf(" :%c", colp->co_char); - printf("\n"); + putchar('\n'); return(-1); } } @@ -408,8 +408,7 @@ getrawlist(line, argv, argc) if (*cp == '\0') break; if (argn >= argc - 1) { - printf( - "Too many elements in the list; excess discarded.\n"); + puts("Too many elements in the list; excess discarded."); break; } cp2 = linebuf; @@ -480,7 +479,7 @@ getrawlist(line, argv, argc) argv[argn++] = savestr(linebuf); } argv[argn] = NOSTR; - return argn; + return(argn); } /* @@ -597,7 +596,7 @@ scan(sp) } if (quotec && c == 0) { fprintf(stderr, "Missing %c\n", quotec); - return TERROR; + return(TERROR); } *sp = --cp; *cp2 = '\0'; @@ -639,16 +638,16 @@ first(f, m) register struct message *mp; if (msgCount == 0) - return 0; + return(0); f &= MDELETED; m &= MDELETED; for (mp = dot; mp < &message[msgCount]; mp++) if ((mp->m_flag & m) == f) - return mp - message + 1; + return(mp - message + 1); for (mp = dot-1; mp >= &message[0]; mp--) if ((mp->m_flag & m) == f) - return mp - message + 1; - return 0; + return(mp - message + 1); + return(0); } /* @@ -663,7 +662,7 @@ matchsender(str, mesg) register char *cp, *cp2, *backup; if (!*str) /* null string matches nothing instead of everything */ - return 0; + return(0); backup = cp2 = nameof(&message[mesg - 1], 0); cp = str; while (*cp2) { @@ -678,6 +677,47 @@ matchsender(str, mesg) } /* + * See if the passed name received the passed message number. Return true + * if so. + */ + +static char *to_fields[] = { "to", "cc", "bcc", NULL }; + +int +matchto(str, mesg) + char *str; +{ + register struct message *mp; + register char *cp, *cp2, *backup, **to; + + str++; + + if (*str == 0) /* null string matches nothing instead of everything */ + return(0); + + mp = &message[mesg-1]; + + for (to = to_fields; *to; to++) { + cp = str; + cp2 = hfield(*to, mp); + if (cp2 != NOSTR) { + backup = cp2; + while (*cp2) { + if (*cp == 0) + return(1); + if (raise(*cp++) != raise(*cp2++)) { + cp2 = ++backup; + cp = str; + } + } + if (*cp == 0) + return(1); + } + } + return(0); +} + +/* * See if the given string matches inside the subject field of the * given message. For the purpose of the scan, we ignore case differences. * If it does, return true. The string search argument is assumed to @@ -695,13 +735,12 @@ matchsubj(str, mesg) register char *cp, *cp2, *backup; str++; - if (strlen(str) == 0) + if (*str == '\0') str = lastscan; else { - strncpy(lastscan, str, sizeof lastscan-1); - lastscan[sizeof lastscan-1] = '\0'; + strncpy(lastscan, str, sizeof(lastscan) - 1); + lastscan[sizeof(lastscan) - 1] = '\0'; } - mp = &message[mesg-1]; /* @@ -709,8 +748,12 @@ matchsubj(str, mesg) */ if (value("searchheaders") && (cp = strchr(str, ':'))) { + /* Check for special case "/To:" */ + if (raise(str[0]) == 'T' && raise(str[1]) == 'O' && + str[2] == ':') + return(matchto(cp, mesg)); *cp++ = '\0'; - cp2 = hfield(str, mp); + cp2 = hfield(*str ? str : "subject", mp); cp[-1] = ':'; str = cp; } else { @@ -780,7 +823,7 @@ metamess(meta, f) for (mp = &message[0]; mp < &message[msgCount]; mp++) if ((mp->m_flag & MDELETED) == f) return(mp - &message[0] + 1); - printf("No applicable messages\n"); + puts("No applicable messages"); return(-1); case '$': @@ -790,11 +833,11 @@ metamess(meta, f) for (mp = &message[msgCount-1]; mp >= &message[0]; mp--) if ((mp->m_flag & MDELETED) == f) return(mp - &message[0] + 1); - printf("No applicable messages\n"); + puts("No applicable messages"); return(-1); case '.': - /* + /* * Current message. */ m = dot - &message[0] + 1; diff --git a/usr.bin/mail/mail.1 b/usr.bin/mail/mail.1 index b0d259c1356..9880e7598b2 100644 --- a/usr.bin/mail/mail.1 +++ b/usr.bin/mail/mail.1 @@ -1,4 +1,5 @@ -.\" $OpenBSD: mail.1,v 1.4 1997/01/13 20:36:23 deraadt Exp $ +.\" $OpenBSD: mail.1,v 1.5 1997/07/13 21:21:14 millert Exp $ +.\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -30,9 +31,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)mail.1 8.2 (Berkeley) 12/30/93 +.\" @(#)mail.1 8.8 (Berkeley) 4/28/95 .\" -.Dd December 30, 1993 +.Dd April 28, 1995 .Dt MAIL 1 .Os BSD 4 .Sh NAME @@ -447,6 +448,7 @@ argument is given, the previous 18\-message group is printed. .It Ic help A synonym for .Ic \&? +.ne li .It Ic hold .Pf ( Ic ho , also @@ -472,6 +474,13 @@ and .Ic Print commands can be used to print a message in its entirety, including ignored fields. +.It Ic inc +Incorporate any new messages that have arrived while mail +is being read. +The new messages are added to the end of the message list, +and the current message is reset to be the first new mail message. +This does not renumber the existing message list, nor does +does it cause any changes made so far to be saved. If .Ic ignore is executed with no arguments, it lists the current set of @@ -588,6 +597,7 @@ saving a message by .Ic save or when automatically saving to .Ar mbox . +.pl +1 .It Ic saveretain .Ic Saveretain is to @@ -715,6 +725,7 @@ Message headers currently being ignored (by the or .Ic retain command) are not included. +.ne li .It Ic \&~F Ns Ar messages Identical to .Ic \&~f , @@ -806,11 +817,18 @@ Causes to prompt you for the subject of each message you send. If you respond with simply a newline, no subject field will be sent. +.ne li .It Ar askcc Causes you to be prompted for additional carbon copy recipients at the end of each message. Responding with a newline indicates your satisfaction with the current list. +.It Ar autoinc +Causes new mail to be automatically incorporated when it arrives. +Setting this is similar to issuing the +.Ic inc +command at each prompt, except that the current message is not +reset when new mail arrives. .It Ar askbcc Causes you to be prompted for additional blind carbon copy recipients at the end of each message. @@ -891,6 +909,13 @@ Suppresses the printing of the version when first invoked. If this option is set, then a message-list specifier in the form ``/x:y'' will expand to all messages containing the substring ``y'' in the header field ``x''. The string search is case insensitive. +If ``x'' is ommitted, it will default to the ``Subject'' header field. +The form ``/to:y'' is a special case, and will expand +to all messages containing the substring ``y'' in the ``To'', ``Cc'' +or ``Bcc'' header fields. +The check for "to" is case sensitive, so that +``/To:y'' can be used to limit the search for ``y'' to just +the ``To:'' field. .It Ar verbose Setting the option .Ar verbose @@ -939,6 +964,7 @@ Pathname of the text editor to use in the command and .Ic \&~v escape. +.ne li .It Va crt The valued option .Va crt @@ -1001,6 +1027,9 @@ Post office. User's old mail. .It ~/.mailrc File giving initial mail commands. +This can be overridden by setting the +.Ev MAILRC +environment variable. .It Pa /tmp/R* Temporary files. .It Pa /usr/share/misc/mail.*help diff --git a/usr.bin/mail/main.c b/usr.bin/mail/main.c index 063ecfa3873..bb867161101 100644 --- a/usr.bin/mail/main.c +++ b/usr.bin/mail/main.c @@ -1,5 +1,5 @@ -/* $OpenBSD: main.c,v 1.4 1997/01/15 23:42:50 millert Exp $ */ -/* $NetBSD: main.c,v 1.5 1996/06/08 19:48:31 christos Exp $ */ +/* $OpenBSD: main.c,v 1.5 1997/07/13 21:21:15 millert Exp $ */ +/* $NetBSD: main.c,v 1.7 1997/05/13 06:15:57 mikel Exp $ */ /* * Copyright (c) 1980, 1993 @@ -42,9 +42,9 @@ static char copyright[] = #ifndef lint #if 0 -static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.4 1997/01/15 23:42:50 millert Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.5 1997/07/13 21:21:15 millert Exp $"; #endif #endif /* not lint */ @@ -72,6 +72,7 @@ main(argc, argv) char *ef; char nosrc = 0; sig_t prevint; + char *rc; /* * Set up a reasonable environment. @@ -103,11 +104,9 @@ main(argc, argv) * articles have been read/deleted for netnews. */ Tflag = optarg; - if ((i = creat(Tflag, 0600)) < 0) { - perror(Tflag); - exit(1); - } - close(i); + if ((i = creat(Tflag, 0600)) < 0) + err(1, Tflag); + (void)close(i); break; case 'u': /* @@ -185,12 +184,11 @@ main(argc, argv) bcc = cat(bcc, nalloc(optarg, GBCC)); break; case '?': - fputs("\ -Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ + fprintf(stderr, "\ +Usage: %s [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ [- sendmail-options ...]\n\ - mail [-iInNv] -f [name]\n\ - mail [-iInNv] [-u user]\n", - stderr); + %s [-iInNv] -f [name]\n\ + %s [-iInNv] [-u user]\n", __progname, __progname, __progname); exit(1); } } @@ -201,14 +199,10 @@ Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ /* * Check for inconsistent arguments. */ - if (to == NIL && (subject != NOSTR || cc != NIL || bcc != NIL)) { - fputs("You must specify direct recipients with -s, -c, or -b.\n", stderr); - exit(1); - } - if (ef != NOSTR && to != NIL) { - fprintf(stderr, "Cannot give -f and people to send to.\n"); - exit(1); - } + if (to == NIL && (subject != NOSTR || cc != NIL || bcc != NIL)) + errx(1, "You must specify direct recipients with -s, -c, or -b"); + if (ef != NOSTR && to != NIL) + errx(1, "Cannot give -f and people to send to"); tinit(); setscreensize(); input = stdin; @@ -220,7 +214,9 @@ Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ * Expand returns a savestr, but load only uses the file name * for fopen, so it's safe to do this. */ - load(expand("~/.mailrc")); + if ((rc = getenv("MAILRC")) == 0) + rc = "~/.mailrc"; + load(expand(rc)); if (!rcvmode) { mail(to, cc, bcc, smopts, subject); /* @@ -266,7 +262,7 @@ hdrstop(signo) { fflush(stdout); - fprintf(stderr, "\nInterrupt\n"); + fputs("\nInterrupt\n", stderr); longjmp(hdrjmp, 1); } diff --git a/usr.bin/mail/names.c b/usr.bin/mail/names.c index 5378dfd6698..94c0e8f4bcb 100644 --- a/usr.bin/mail/names.c +++ b/usr.bin/mail/names.c @@ -1,4 +1,4 @@ -/* $OpenBSD: names.c,v 1.3 1997/01/17 07:12:50 millert Exp $ */ +/* $OpenBSD: names.c,v 1.4 1997/07/13 21:21:15 millert Exp $ */ /* $NetBSD: names.c,v 1.5 1996/06/08 19:48:32 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)names.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: names.c,v 1.3 1997/01/17 07:12:50 millert Exp $"; +static char rcsid[] = "$OpenBSD: names.c,v 1.4 1997/07/13 21:21:15 millert Exp $"; #endif #endif /* not lint */ @@ -64,7 +64,7 @@ nalloc(str, ntype) { register struct name *np; - np = (struct name *) salloc(sizeof *np); + np = (struct name *) salloc(sizeof(*np)); np->n_flink = NIL; np->n_blink = NIL; np->n_type = ntype; @@ -104,7 +104,7 @@ extract(line, ntype) char nbuf[BUFSIZ]; if (line == NOSTR || *line == '\0') - return NIL; + return(NIL); top = NIL; np = NIL; cp = line; @@ -117,7 +117,7 @@ extract(line, ntype) t->n_blink = np; np = t; } - return top; + return(top); } /* @@ -139,7 +139,7 @@ detract(np, ntype) ntype &= ~GCOMMA; s = 0; if (debug && comma) - fprintf(stderr, "detract asked to insert commas\n"); + fputs("detract asked to insert commas\n", stderr); for (p = np; p != NIL; p = p->n_flink) { if (ntype && (p->n_type & GMASK) != ntype) continue; @@ -179,7 +179,7 @@ yankword(ap, wbuf) cp = ap; for (;;) { if (*cp == '\0') - return NOSTR; + return(NOSTR); if (*cp == '(') { register int nesting = 0; @@ -207,7 +207,7 @@ yankword(ap, wbuf) for (cp2 = wbuf; *cp && !strchr(" \t,(", *cp); *cp2++ = *cp++) ; *cp2 = '\0'; - return cp; + return(cp); } /* @@ -254,16 +254,16 @@ outof(names, fo, hp) if (image < 0) { if ((fout = Fopen(tempEdit, "a")) == NULL) { - perror(tempEdit); + warn(tempEdit); senderr++; goto cant; } image = open(tempEdit, 2); (void) unlink(tempEdit); if (image < 0) { - perror(tempEdit); + warn(tempEdit); senderr++; - (void) Fclose(fout); + (void)Fclose(fout); goto cant; } (void) fcntl(image, F_SETFD, 1); @@ -275,8 +275,8 @@ outof(names, fo, hp) (void) putc('\n', fout); (void) fflush(fout); if (ferror(fout)) - perror(tempEdit); - (void) Fclose(fout); + warn(tempEdit); + (void)Fclose(fout); } /* @@ -313,28 +313,30 @@ outof(names, fo, hp) } else { int f; if ((fout = Fopen(fname, "a")) == NULL) { - perror(fname); + warn(fname); senderr++; goto cant; } if ((f = dup(image)) < 0) { - perror("dup"); + warn("dup"); fin = NULL; } else fin = Fdopen(f, "r"); if (fin == NULL) { - fprintf(stderr, "Can't reopen image\n"); - (void) Fclose(fout); + fputs("Can't reopen image\n", stderr); + (void)Fclose(fout); senderr++; goto cant; } rewind(fin); while ((c = getc(fin)) != EOF) (void) putc(c, fout); - if (ferror(fout)) - senderr++, perror(fname); - (void) Fclose(fout); - (void) Fclose(fin); + if (ferror(fout)) { + senderr++; + warn(fname); + } + (void)Fclose(fout); + (void)Fclose(fin); } cant: /* @@ -346,7 +348,7 @@ cant: np = np->n_flink; } if (image >= 0) { - (void) close(image); + (void)close(image); image = -1; } return(top); @@ -364,14 +366,14 @@ isfileaddr(name) register char *cp; if (*name == '+') - return 1; + return(1); for (cp = name; *cp; cp++) { if (*cp == '!' || *cp == '%' || *cp == '@') - return 0; + return(0); if (*cp == '/') - return 1; + return(1); } - return 0; + return(0); } /* @@ -508,7 +510,7 @@ unpack(np) verbose = value("verbose") != NOSTR; if (verbose) extra++; - top = (char **) salloc((t + extra) * sizeof *top); + top = (char **) salloc((t + extra) * sizeof(*top)); ap = top; *ap++ = "send-mail"; *ap++ = "-i"; @@ -651,7 +653,7 @@ count(np) for (c = 0; np != NIL; np = np->n_flink) if ((np->n_type & GDEL) == 0) c++; - return c; + return(c); } /* @@ -680,7 +682,7 @@ delname(np, name) p->n_blink->n_flink = p->n_flink; p->n_flink->n_blink = p->n_blink; } - return np; + return(np); } /* @@ -700,6 +702,6 @@ prettyprint(name) fprintf(stderr, "%s(%d) ", np->n_name, np->n_type); np = np->n_flink; } - fprintf(stderr, "\n"); + putc('\n', stderr); } */ diff --git a/usr.bin/mail/popen.c b/usr.bin/mail/popen.c index 1c0226fbbbe..30194940932 100644 --- a/usr.bin/mail/popen.c +++ b/usr.bin/mail/popen.c @@ -1,5 +1,5 @@ -/* $OpenBSD: popen.c,v 1.5 1997/05/30 08:51:43 deraadt Exp $ */ -/* $NetBSD: popen.c,v 1.4 1996/06/08 19:48:35 christos Exp $ */ +/* $OpenBSD: popen.c,v 1.6 1997/07/13 21:21:15 millert Exp $ */ +/* $NetBSD: popen.c,v 1.6 1997/05/13 06:48:42 mikel Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: popen.c,v 1.5 1997/05/30 08:51:43 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: popen.c,v 1.6 1997/07/13 21:21:15 millert Exp $"; #endif #endif /* not lint */ @@ -81,7 +81,7 @@ Fopen(file, mode) register_file(fp, 0, 0); (void) fcntl(fileno(fp), F_SETFD, 1); } - return fp; + return(fp); } FILE * @@ -95,7 +95,7 @@ Fdopen(fd, mode) register_file(fp, 0, 0); (void) fcntl(fileno(fp), F_SETFD, 1); } - return fp; + return(fp); } int @@ -103,7 +103,7 @@ Fclose(fp) FILE *fp; { unregister_file(fp); - return fclose(fp); + return(fclose(fp)); } FILE * @@ -118,7 +118,7 @@ Popen(cmd, mode) FILE *fp; if (pipe(p) < 0) - return NULL; + return(NULL); (void) fcntl(p[READ], F_SETFD, 1); (void) fcntl(p[WRITE], F_SETFD, 1); if (*mode == 'r') { @@ -132,14 +132,14 @@ Popen(cmd, mode) } sigemptyset(&nset); if ((pid = start_command(cmd, &nset, fd0, fd1, NOSTR, NOSTR, NOSTR)) < 0) { - close(p[READ]); - close(p[WRITE]); - return NULL; + (void)close(p[READ]); + (void)close(p[WRITE]); + return(NULL); } - (void) close(hisside); + (void)close(hisside); if ((fp = fdopen(myside, mode)) != NULL) register_file(fp, 1, pid); - return fp; + return(fp); } int @@ -151,14 +151,14 @@ Pclose(ptr) i = file_pid(ptr); unregister_file(ptr); - (void) fclose(ptr); + (void)fclose(ptr); sigemptyset(&nset); sigaddset(&nset, SIGINT); sigaddset(&nset, SIGHUP); sigprocmask(SIG_BLOCK, &nset, &oset); i = wait_child(i); sigprocmask(SIG_SETMASK, &oset, NULL); - return i; + return(i); } void @@ -167,9 +167,9 @@ close_all_files() while (fp_head) if (fp_head->pipe) - (void) Pclose(fp_head->fp); + (void)Pclose(fp_head->fp); else - (void) Fclose(fp_head->fp); + (void)Fclose(fp_head->fp); } void @@ -179,7 +179,7 @@ register_file(fp, pipe, pid) { struct fp *fpp; - if ((fpp = (struct fp *) malloc(sizeof *fpp)) == NULL) + if ((fpp = (struct fp *) malloc(sizeof(*fpp))) == NULL) panic("Out of memory"); fpp->fp = fp; fpp->pipe = pipe; @@ -211,7 +211,7 @@ file_pid(fp) for (p = fp_head; p; p = p->link) if (p->fp == fp) - return (p->pid); + return(p->pid); panic("Invalid file pointer"); /*NOTREACHED*/ } @@ -234,8 +234,8 @@ run_command(cmd, mask, infd, outfd, a0, a1, a2) int pid; if ((pid = start_command(cmd, mask, infd, outfd, a0, a1, a2)) < 0) - return -1; - return wait_command(pid); + return(-1); + return(wait_command(pid)); } /*VARARGS4*/ @@ -249,12 +249,12 @@ start_command(cmd, mask, infd, outfd, a0, a1, a2) int pid; if ((pid = vfork()) < 0) { - perror("fork"); - return -1; + warn("fork"); + return(-1); } if (pid == 0) { char *argv[100]; - int i = getrawlist(cmd, argv, sizeof argv / sizeof *argv); + int i = getrawlist(cmd, argv, sizeof(argv)/ sizeof(*argv)); if ((argv[i++] = a0) != NOSTR && (argv[i++] = a1) != NOSTR && @@ -262,10 +262,10 @@ start_command(cmd, mask, infd, outfd, a0, a1, a2) argv[i] = NOSTR; prepare_child(mask, infd, outfd); execvp(argv[0], argv); - perror(argv[0]); + warn(argv[0]); _exit(1); } - return pid; + return(pid); } void @@ -284,13 +284,15 @@ prepare_child(nset, infd, outfd) dup2(infd, 0); if (outfd >= 0) dup2(outfd, 1); - if (nset) { + if (nset == NULL) + return; + if (nset != NULL) { for (i = 1; i < NSIG; i++) if (sigismember(nset, i)) (void) signal(i, SIG_IGN); - if (!sigismember(nset, SIGINT)) - (void) signal(SIGINT, SIG_DFL); } + if (nset == NULL || !sigismember(nset, SIGINT)) + (void) signal(SIGINT, SIG_DFL); sigfillset(&fset); (void) sigprocmask(SIG_UNBLOCK, &fset, NULL); } @@ -301,10 +303,10 @@ wait_command(pid) { if (wait_child(pid) < 0) { - printf("Fatal error in process.\n"); - return -1; + puts("Fatal error in process."); + return(-1); } - return 0; + return(0); } static struct child * @@ -317,12 +319,12 @@ findchild(pid) cpp = &(*cpp)->link) ; if (*cpp == NULL) { - *cpp = (struct child *) malloc(sizeof (struct child)); + *cpp = (struct child *) malloc(sizeof(struct child)); (*cpp)->pid = pid; (*cpp)->done = (*cpp)->free = 0; (*cpp)->link = NULL; } - return *cpp; + return(*cpp); } static void @@ -377,7 +379,7 @@ wait_child(pid) wait_status = cp->status; delchild(cp); sigprocmask(SIG_SETMASK, &oset, NULL); - return wait_status.w_status ? -1 : 0; + return(wait_status.w_status ? -1 : 0); } /* @@ -415,12 +417,12 @@ handle_spool_locks(action) if (action == 0) { /* Clear the lock */ if (lockfp == NULL) { - fprintf(stderr, - "handle_spool_locks: no spool lock to remove.\n"); - return (-1); + fputs("handle_spool_locks: no spool lock to remove.\n", + stderr); + return(-1); } (void)kill(lock_pid, SIGTERM); - Pclose(lockfp); + (void)Pclose(lockfp); lockfp = NULL; } else if (action == 1) { /* Create the lock */ @@ -430,7 +432,7 @@ handle_spool_locks(action) if ((lockfp = Popen(cmd, "r")) == NULL || getc(lockfp) != '1') { lockfp = NULL; free(cmd); - return (0); + return(0); } lock_pid = fp_head->pid; /* new entries added at head */ @@ -438,10 +440,10 @@ handle_spool_locks(action) } else { fprintf(stderr, "handle_spool_locks: unknown action %d\n", action); - return (-1); + return(-1); } - return (1); + return(1); } int diff --git a/usr.bin/mail/quit.c b/usr.bin/mail/quit.c index 104101c1f47..f4d3e51ba5f 100644 --- a/usr.bin/mail/quit.c +++ b/usr.bin/mail/quit.c @@ -1,5 +1,5 @@ -/* $OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $ */ -/* $NetBSD: quit.c,v 1.5 1996/06/08 19:48:37 christos Exp $ */ +/* $OpenBSD: quit.c,v 1.4 1997/07/13 21:21:16 millert Exp $ */ +/* $NetBSD: quit.c,v 1.6 1996/12/28 07:11:07 tls Exp $ */ /* * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)quit.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $"; +static char rcsid[] = "$OpenBSD: quit.c,v 1.4 1997/07/13 21:21:16 millert Exp $"; #endif #endif /* not lint */ @@ -64,8 +64,8 @@ quitcmd(v) * Otherwise, return -1 to abort command loop. */ if (sourcing) - return 1; - return -1; + return(1); + return(-1); } /* @@ -113,17 +113,17 @@ quit() if (fbuf == NULL) goto newmail; if (flock(fileno(fbuf), LOCK_EX) == -1) { - perror("Unable to lock mailbox"); - Fclose(fbuf); + warn("Unable to lock mailbox"); + (void)Fclose(fbuf); return; } if (!spool_lock()) { - Fclose(fbuf); + (void)Fclose(fbuf); return; /* mail.local printed error for us */ } rbuf = NULL; if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) { - printf("New mail has arrived.\n"); + puts("New mail has arrived."); rbuf = Fopen(tempResid, "w"); if (rbuf == NULL || fbuf == NULL) goto newmail; @@ -140,7 +140,7 @@ quit() (void) putc(c, rbuf); } #endif - Fclose(rbuf); + (void)Fclose(rbuf); if ((rbuf = Fopen(tempResid, "r")) == NULL) goto newmail; rm(tempResid); @@ -188,18 +188,18 @@ quit() } } if (Tflag != NOSTR) - Fclose(readstat); + (void)Fclose(readstat); if (p == msgCount && !modify && !anystat) { printf("Held %d message%s in %s\n", p, p == 1 ? "" : "s", mailname); - Fclose(fbuf); + (void)Fclose(fbuf); spool_unlock(); return; } if (c == 0) { if (p != 0) { writeback(rbuf); - Fclose(fbuf); + (void)Fclose(fbuf); spool_unlock(); return; } @@ -217,16 +217,16 @@ quit() mcount = c; if (value("append") == NOSTR) { if ((obuf = Fopen(tempQuit, "w")) == NULL) { - perror(tempQuit); - Fclose(fbuf); + warn(tempQuit); + (void)Fclose(fbuf); spool_unlock(); return; } if ((ibuf = Fopen(tempQuit, "r")) == NULL) { - perror(tempQuit); + warn(tempQuit); rm(tempQuit); - Fclose(obuf); - Fclose(fbuf); + (void)Fclose(obuf); + (void)Fclose(fbuf); spool_unlock(); return; } @@ -234,30 +234,30 @@ quit() if ((abuf = Fopen(mbox, "r")) != NULL) { while ((c = getc(abuf)) != EOF) (void) putc(c, obuf); - Fclose(abuf); + (void)Fclose(abuf); } if (ferror(obuf)) { - perror(tempQuit); - Fclose(ibuf); - Fclose(obuf); - Fclose(fbuf); + warn(tempQuit); + (void)Fclose(ibuf); + (void)Fclose(obuf); + (void)Fclose(fbuf); spool_unlock(); return; } - Fclose(obuf); - close(creat(mbox, 0600)); + (void)Fclose(obuf); + (void)close(creat(mbox, 0600)); if ((obuf = Fopen(mbox, "r+")) == NULL) { - perror(mbox); - Fclose(ibuf); - Fclose(fbuf); + warn(mbox); + (void)Fclose(ibuf); + (void)Fclose(fbuf); spool_unlock(); return; } } else { if ((obuf = Fopen(mbox, "a")) == NULL) { - perror(mbox); - Fclose(fbuf); + warn(mbox); + (void)Fclose(fbuf); spool_unlock(); return; } @@ -266,10 +266,10 @@ quit() for (mp = &message[0]; mp < &message[msgCount]; mp++) if (mp->m_flag & MBOX) if (send(mp, obuf, saveignore, NOSTR) < 0) { - perror(mbox); - Fclose(ibuf); - Fclose(obuf); - Fclose(fbuf); + warn(mbox); + (void)Fclose(ibuf); + (void)Fclose(obuf); + (void)Fclose(fbuf); spool_unlock(); return; } @@ -289,20 +289,20 @@ quit() break; c = getc(ibuf); } - Fclose(ibuf); + (void)Fclose(ibuf); fflush(obuf); } trunc(obuf); if (ferror(obuf)) { - perror(mbox); - Fclose(obuf); - Fclose(fbuf); + warn(mbox); + (void)Fclose(obuf); + (void)Fclose(fbuf); spool_unlock(); return; } - Fclose(obuf); + (void)Fclose(obuf); if (mcount == 1) - printf("Saved 1 message in mbox\n"); + puts("Saved 1 message in mbox"); else printf("Saved %d messages in mbox\n", mcount); @@ -313,7 +313,7 @@ quit() if (p != 0) { writeback(rbuf); - Fclose(fbuf); + (void)Fclose(fbuf); spool_unlock(); return; } @@ -330,23 +330,23 @@ cream: goto newmail; while ((c = getc(rbuf)) != EOF) (void) putc(c, abuf); - Fclose(rbuf); + (void)Fclose(rbuf); trunc(abuf); - Fclose(abuf); + (void)Fclose(abuf); alter(mailname); - Fclose(fbuf); + (void)Fclose(fbuf); spool_unlock(); return; } demail(); - Fclose(fbuf); + (void)Fclose(fbuf); spool_unlock(); return; newmail: - printf("Thou hast new mail.\n"); + puts("Thou hast new mail."); if (fbuf != NULL) { - Fclose(fbuf); + (void)Fclose(fbuf); spool_unlock(); } } @@ -367,7 +367,7 @@ writeback(res) p = 0; if ((obuf = Fopen(mailname, "r+")) == NULL) { - perror(mailname); + warn(mailname); return(-1); } #ifndef APPEND @@ -379,8 +379,8 @@ writeback(res) if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) { p++; if (send(mp, obuf, (struct ignoretab *)0, NOSTR) < 0) { - perror(mailname); - Fclose(obuf); + warn(mailname); + (void)Fclose(obuf); return(-1); } } @@ -392,13 +392,13 @@ writeback(res) fflush(obuf); trunc(obuf); if (ferror(obuf)) { - perror(mailname); - Fclose(obuf); + warn(mailname); + (void)Fclose(obuf); return(-1); } if (res != NULL) - Fclose(res); - Fclose(obuf); + (void)Fclose(res); + (void)Fclose(obuf); alter(mailname); if (p == 1) printf("Held 1 message in %s\n", mailname); @@ -443,7 +443,7 @@ edstop() } } if (Tflag != NOSTR) - Fclose(readstat); + (void)Fclose(readstat); if (!gotcha || Tflag != NOSTR) goto done; ibuf = NULL; @@ -454,13 +454,13 @@ edstop() "mboxXXXXXXXXXX"); if ((fd = mkstemp(tempname)) == -1 || (obuf = Fdopen(fd, "w")) == NULL) { - perror(tempname); + warn(tempname); relsesigs(); reset(0); } if ((ibuf = Fopen(mailname, "r")) == NULL) { - perror(mailname); - Fclose(obuf); + warn(mailname); + (void)Fclose(obuf); rm(tempname); relsesigs(); reset(0); @@ -468,10 +468,10 @@ edstop() fseek(ibuf, (long)mailsize, 0); while ((c = getc(ibuf)) != EOF) (void) putc(c, obuf); - Fclose(ibuf); - Fclose(obuf); + (void)Fclose(ibuf); + (void)Fclose(obuf); if ((ibuf = Fopen(tempname, "r")) == NULL) { - perror(tempname); + warn(tempname); rm(tempname); relsesigs(); reset(0); @@ -481,7 +481,7 @@ edstop() printf("\"%s\" ", mailname); fflush(stdout); if ((obuf = Fopen(mailname, "r+")) == NULL) { - perror(mailname); + warn(mailname); relsesigs(); reset(0); } @@ -492,7 +492,7 @@ edstop() continue; c++; if (send(mp, obuf, (struct ignoretab *) NULL, NOSTR) < 0) { - perror(mailname); + warn(mailname); relsesigs(); reset(0); } @@ -501,20 +501,20 @@ edstop() if (ibuf != NULL) { while ((c = getc(ibuf)) != EOF) (void) putc(c, obuf); - Fclose(ibuf); + (void)Fclose(ibuf); } fflush(obuf); if (ferror(obuf)) { - perror(mailname); + warn(mailname); relsesigs(); reset(0); } - Fclose(obuf); + (void)Fclose(obuf); if (gotcha) { rm(mailname); - printf("removed\n"); + puts("removed"); } else - printf("complete\n"); + puts("complete"); fflush(stdout); done: diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index e4a1d6bf5c8..72ad046f065 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: send.c,v 1.2 1996/06/11 12:53:50 deraadt Exp $ */ +/* $OpenBSD: send.c,v 1.3 1997/07/13 21:21:16 millert Exp $ */ /* $NetBSD: send.c,v 1.6 1996/06/08 19:48:39 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)send.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: send.c,v 1.2 1996/06/11 12:53:50 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: send.c,v 1.3 1997/07/13 21:21:16 millert Exp $"; #endif #endif /* not lint */ @@ -94,11 +94,11 @@ send(mp, obuf, doign, prefix) * Process headers first */ while (count > 0 && ishead) { - if (fgets(line, LINESIZE, ibuf) == NULL) + if (fgets(line, sizeof(line), ibuf) == NULL) break; count -= length = strlen(line); if (firstline) { - /* + /* * First line is the From line, so no headers * there to worry about */ @@ -183,11 +183,11 @@ send(mp, obuf, doign, prefix) if (length > 1) fputs(prefix, obuf); else - (void) fwrite(prefix, sizeof *prefix, + (void) fwrite(prefix, sizeof(*prefix), prefixlen, obuf); - (void) fwrite(line, sizeof *line, length, obuf); + (void) fwrite(line, sizeof(*line), length, obuf); if (ferror(obuf)) - return -1; + return(-1); } } /* @@ -197,7 +197,7 @@ send(mp, obuf, doign, prefix) count--; /* skip final blank line */ if (prefix != NOSTR) while (count > 0) { - if (fgets(line, LINESIZE, ibuf) == NULL) { + if (fgets(line, sizeof(line), ibuf) == NULL) { c = 0; break; } @@ -209,26 +209,26 @@ send(mp, obuf, doign, prefix) if (c > 1) fputs(prefix, obuf); else - (void) fwrite(prefix, sizeof *prefix, + (void) fwrite(prefix, sizeof(*prefix), prefixlen, obuf); - (void) fwrite(line, sizeof *line, c, obuf); + (void) fwrite(line, sizeof(*line), c, obuf); if (ferror(obuf)) - return -1; + return(-1); } else while (count > 0) { c = count < LINESIZE ? count : LINESIZE; - if ((c = fread(line, sizeof *line, c, ibuf)) <= 0) + if ((c = fread(line, sizeof(*line), c, ibuf)) <= 0) break; count -= c; - if (fwrite(line, sizeof *line, c, obuf) != c) - return -1; + if (fwrite(line, sizeof(*line), c, obuf) != c) + return(-1); } if (doign == ignoreall && c > 0 && line[c - 1] != '\n') /* no final blank line */ if ((c = getc(ibuf)) != EOF && putc(c, obuf) == EOF) - return -1; - return 0; + return(-1); + return(0); } /* @@ -322,14 +322,14 @@ mail1(hp, printheaders) if (value("askbcc") != NOSTR) grabh(hp, GBCC); } else { - printf("EOT\n"); + puts("EOT"); (void) fflush(stdout); } if (fsize(mtf) == 0) if (hp->h_subject == NOSTR) - printf("No message, no subject; hope that's ok\n"); + puts("No message, no subject; hope that's ok"); else - printf("Null message body; hope that's ok\n"); + puts("Null message body; hope that's ok"); /* * Now, take the user names from the combined * to and cc lists and do all the alias @@ -338,7 +338,7 @@ mail1(hp, printheaders) senderr = 0; to = usermap(cat(hp->h_bcc, cat(hp->h_to, hp->h_cc))); if (to == NIL) { - printf("No recipients specified\n"); + puts("No recipients specified"); senderr++; } /* @@ -353,17 +353,17 @@ mail1(hp, printheaders) goto out; fixhead(hp, to); if ((mtf = infix(hp, mtf)) == NULL) { - fprintf(stderr, ". . . message lost, sorry.\n"); + fputs(". . . message lost, sorry.\n", stderr); return; } namelist = unpack(cat(hp->h_smopts, to)); if (debug) { char **t; - printf("Sendmail arguments:"); + fputs("Sendmail arguments:", stdout); for (t = namelist; *t != NOSTR; t++) printf(" \"%s\"", *t); - printf("\n"); + putchar('\n'); goto out; } if ((cp = value("record")) != NOSTR) @@ -375,7 +375,7 @@ mail1(hp, printheaders) */ pid = fork(); if (pid == -1) { - perror("fork"); + warn("fork"); savedeadletter(mtf); goto out; } @@ -394,7 +394,7 @@ mail1(hp, printheaders) else cp = _PATH_SENDMAIL; execv(cp, namelist); - perror(cp); + warn(cp); _exit(1); } if (value("verbose") != NOSTR) @@ -402,7 +402,7 @@ mail1(hp, printheaders) else free_child(pid); out: - (void) Fclose(mtf); + (void)Fclose(mtf); } /* @@ -445,12 +445,12 @@ infix(hp, fi) register int c; if ((nfo = Fopen(tempMail, "w")) == NULL) { - perror(tempMail); + warn(tempMail); return(fi); } if ((nfi = Fopen(tempMail, "r")) == NULL) { - perror(tempMail); - (void) Fclose(nfo); + warn(tempMail); + (void)Fclose(nfo); return(fi); } (void) rm(tempMail); @@ -461,20 +461,20 @@ infix(hp, fi) c = getc(fi); } if (ferror(fi)) { - perror("read"); + warn("read"); rewind(fi); return(fi); } (void) fflush(nfo); if (ferror(nfo)) { - perror(tempMail); - (void) Fclose(nfo); - (void) Fclose(nfi); + warn(tempMail); + (void)Fclose(nfo); + (void)Fclose(nfi); rewind(fi); return(fi); } - (void) Fclose(nfo); - (void) Fclose(fi); + (void)Fclose(nfo); + (void)Fclose(fi); rewind(nfi); return(nfi); } @@ -555,18 +555,18 @@ savemail(name, fi) time_t now; if ((fo = Fopen(name, "a")) == NULL) { - perror(name); - return (-1); + warn(name); + return(-1); } (void) time(&now); fprintf(fo, "From %s %s", myname, ctime(&now)); - while ((i = fread(buf, 1, sizeof buf, fi)) > 0) + while ((i = fread(buf, 1, sizeof(buf), fi)) > 0) (void) fwrite(buf, 1, i, fo); (void) putc('\n', fo); (void) fflush(fo); if (ferror(fo)) - perror(name); - (void) Fclose(fo); + warn(name); + (void)Fclose(fo); rewind(fi); - return (0); + return(0); } diff --git a/usr.bin/mail/strings.c b/usr.bin/mail/strings.c index 33e0793d5e6..f7d10710094 100644 --- a/usr.bin/mail/strings.c +++ b/usr.bin/mail/strings.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strings.c,v 1.2 1996/06/11 12:53:50 deraadt Exp $ */ +/* $OpenBSD: strings.c,v 1.3 1997/07/13 21:21:17 millert Exp $ */ /* $NetBSD: strings.c,v 1.5 1996/06/08 19:48:40 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)strings.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: strings.c,v 1.2 1996/06/11 12:53:50 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: strings.c,v 1.3 1997/07/13 21:21:17 millert Exp $"; #endif #endif /* not lint */ @@ -71,8 +71,8 @@ salloc(size) int index; s = size; - s += (sizeof (char *) - 1); - s &= ~(sizeof (char *) - 1); + s += (sizeof(char *) - 1); + s &= ~(sizeof(char *) - 1); index = 0; for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) { if (sp->s_topFree == NOSTR && (STRINGSIZE << index) >= s) diff --git a/usr.bin/mail/temp.c b/usr.bin/mail/temp.c index 312768ae6b3..61e4be01b64 100644 --- a/usr.bin/mail/temp.c +++ b/usr.bin/mail/temp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: temp.c,v 1.5 1997/03/29 03:01:47 millert Exp $ */ +/* $OpenBSD: temp.c,v 1.6 1997/07/13 21:21:17 millert Exp $ */ /* $NetBSD: temp.c,v 1.5 1996/06/08 19:48:42 christos Exp $ */ /* @@ -38,12 +38,11 @@ #if 0 static char sccsid[] = "@(#)temp.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: temp.c,v 1.5 1997/03/29 03:01:47 millert Exp $"; +static char rcsid[] = "$OpenBSD: temp.c,v 1.6 1997/07/13 21:21:17 millert Exp $"; #endif #endif /* not lint */ #include "rcv.h" -#include <errno.h> #include "extern.h" /* @@ -87,11 +86,8 @@ tinit() * do a spreserve() after us. */ if (myname != NOSTR) { - if (getuserid(myname) < 0) { - printf("\"%s\" is not a user of this system\n", - myname); - exit(1); - } + if (getuserid(myname) < 0) + errx(1, "\"%s\" is not a user of this system", myname); } else { if ((cp = username()) == NOSTR) { myname = "nobody"; diff --git a/usr.bin/mail/tty.c b/usr.bin/mail/tty.c index 6b3f4d2c20a..9b58d2004eb 100644 --- a/usr.bin/mail/tty.c +++ b/usr.bin/mail/tty.c @@ -1,5 +1,5 @@ -/* $OpenBSD: tty.c,v 1.2 1996/06/11 12:53:52 deraadt Exp $ */ -/* $NetBSD: tty.c,v 1.5 1996/06/08 19:48:43 christos Exp $ */ +/* $OpenBSD: tty.c,v 1.3 1997/07/13 21:21:17 millert Exp $ */ +/* $NetBSD: tty.c,v 1.7 1997/07/09 05:25:46 mikel Exp $ */ /* * Copyright (c) 1980, 1993 @@ -36,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)tty.c 8.2 (Berkeley) 4/20/95"; #else -static char rcsid[] = "$OpenBSD: tty.c,v 1.2 1996/06/11 12:53:52 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: tty.c,v 1.3 1997/07/13 21:21:17 millert Exp $"; #endif #endif /* not lint */ @@ -73,6 +73,8 @@ grabh(hp, gflags) sig_t saveint; #ifndef TIOCSTI sig_t savequit; +#else + int extproc, flag; #endif sig_t savetstp; sig_t savettou; @@ -80,6 +82,9 @@ grabh(hp, gflags) int errs; #ifdef __GNUC__ /* Avoid longjmp clobbering */ +#ifdef TIOCSTI + (void) &extproc; +#endif (void) &saveint; #endif @@ -91,7 +96,7 @@ grabh(hp, gflags) ttyset = 0; #endif if (tcgetattr(fileno(stdin), &ttybuf) < 0) { - perror("tcgetattr"); + warn("tcgetattr"); return(-1); } c_erase = ttybuf.c_cc[VERASE]; @@ -104,6 +109,14 @@ grabh(hp, gflags) if ((savequit = signal(SIGQUIT, SIG_IGN)) == SIG_DFL) signal(SIGQUIT, SIG_DFL); #else +# ifdef TIOCEXT + extproc = ((ttybuf.c_lflag & EXTPROC) ? 1 : 0); + if (extproc) { + flag = 0; + if (ioctl(fileno(stdin), TIOCEXT, &flag) < 0) + warn("TIOCEXT: off"); + } +# endif /* TIOCEXT */ if (setjmp(intjmp)) goto out; saveint = signal(SIGINT, ttyint); @@ -149,6 +162,14 @@ out: if (ttyset) tcsetattr(fileno(stdin), TCSADRAIN, &ttybuf); signal(SIGQUIT, savequit); +#else +# ifdef TIOCEXT + if (extproc) { + flag = 1; + if (ioctl(fileno(stdin), TIOCEXT, &flag) < 0) + warn("TIOCEXT: on"); + } +# endif /* TIOCEXT */ #endif signal(SIGINT, saveint); return(errs); @@ -177,7 +198,7 @@ readtty(pr, src) fputs(pr, stdout); fflush(stdout); if (src != NOSTR && strlen(src) > BUFSIZ - 2) { - printf("too long to edit\n"); + puts("too long to edit"); return(src); } #ifndef TIOCSTI diff --git a/usr.bin/mail/v7.local.c b/usr.bin/mail/v7.local.c index 344c6e29fe1..0521ce6a95f 100644 --- a/usr.bin/mail/v7.local.c +++ b/usr.bin/mail/v7.local.c @@ -1,5 +1,5 @@ -/* $OpenBSD: v7.local.c,v 1.6 1997/06/16 20:57:06 millert Exp $ */ -/* $NetBSD: v7.local.c,v 1.7 1996/06/08 19:48:44 christos Exp $ */ +/* $OpenBSD: v7.local.c,v 1.7 1997/07/13 21:21:18 millert Exp $ */ +/* $NetBSD: v7.local.c,v 1.8 1997/05/13 06:15:58 mikel Exp $ */ /* * Copyright (c) 1980, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)v7.local.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: v7.local.c,v 1.6 1997/06/16 20:57:06 millert Exp $"; +static char rcsid[] = "$OpenBSD: v7.local.c,v 1.7 1997/07/13 21:21:18 millert Exp $"; #endif #endif /* not lint */ @@ -82,7 +82,7 @@ demail() { if (value("keep") != NOSTR || rm(mailname) < 0) - close(creat(mailname, 0600)); + (void)close(creat(mailname, 0600)); } /* @@ -95,11 +95,11 @@ username() uid_t uid; if ((np = getenv("USER")) != NOSTR) - return np; + return(np); if ((np = getenv("LOGNAME")) != NOSTR) - return np; + return(np); if ((np = getname(uid = getuid())) != NOSTR) - return np; + return(np); printf("Cannot associate a name with uid %u\n", (unsigned)uid); - return NOSTR; + return(NOSTR); } diff --git a/usr.bin/mail/vars.c b/usr.bin/mail/vars.c index 22a1d9d8cf7..6110a4c3974 100644 --- a/usr.bin/mail/vars.c +++ b/usr.bin/mail/vars.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vars.c,v 1.2 1996/06/11 12:53:53 deraadt Exp $ */ +/* $OpenBSD: vars.c,v 1.3 1997/07/13 21:21:18 millert Exp $ */ /* $NetBSD: vars.c,v 1.4 1996/06/08 19:48:45 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: vars.c,v 1.2 1996/06/11 12:53:53 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: vars.c,v 1.3 1997/07/13 21:21:18 millert Exp $"; #endif #endif /* not lint */ @@ -64,7 +64,7 @@ assign(name, value) h = hash(name); vp = lookup(name); if (vp == NOVAR) { - vp = (struct var *) calloc(sizeof *vp, 1); + vp = (struct var *) calloc(sizeof(*vp), 1); vp->v_name = vcopy(name); vp->v_link = variables[h]; variables[h] = vp; @@ -100,12 +100,12 @@ vcopy(str) unsigned len; if (*str == '\0') - return ""; + return(""); len = strlen(str) + 1; if ((new = malloc(len)) == NULL) panic("Out of memory"); bcopy(str, new, (int) len); - return new; + return(new); } /* @@ -193,5 +193,5 @@ hash(name) } if (h < 0 && (h = -h) < 0) h = 0; - return (h % HSHSIZE); + return(h % HSHSIZE); } |