with gcc's -D_FORTIFY_SOURCE=2.
iov[1].iov_base = "\r\n";
iov[1].iov_len = 2;
- writev(socket, iov, 2);
+ if (writev(socket, iov, 2) < 0) {
+ perror ("writev");
+ }
}
/*
{
ssize_t datalen = strlen(data);
- write(socket, data, datalen);
+ if (write(socket, data, datalen) < 0) {
+ perror ("write");
+ }
}
/*
iov[1].iov_base = "\r\n";
iov[1].iov_len = 2;
- writev(socket, iov, 2);
+ if (writev(socket, iov, 2) < 0) {
+ perror ("writev");
+ }
}
/*
dat[3] = outputlinelen;
dat[4] = 0;
fmt_scan(fmt, scanl, i, dat, NULL);
- write(out, charstring_buffer (scanl), charstring_bytes (scanl));
+ if (write(out, charstring_buffer (scanl),
+ charstring_bytes (scanl)) < 0) {
+ advise (drft, "write");
+ }
charstring_free(scanl);
} else {
cpydata (in, out, form, drft);
* The stat failed. So we make sure file
* has right ownership/modes
*/
- chown (file, uid, gid);
- chmod (file, mode);
+ if (chown (file, uid, gid) < 0) {
+ advise (file, "chown");
+ }
+ if (chmod (file, mode) < 0) {
+ advise (file, "chmod");
+ }
} else if (st.st_size > (off_t) 0) {
int status;
* "From ", then prepend line with ">".
*/
if (j != 0 && strncmp (buffer, "From ", 5) == 0) {
- write (md, ">", 1);
+ if (write (md, ">", 1) < 0) {
+ advise (mailbox, "write");
+ }
size++;
}
i = strlen (buffer);
strncpy (bp, "\n\n", buflen);
}
- write (out, buffer, strlen (buffer));
+ if (write (out, buffer, strlen (buffer)) < 0) {
+ advise (drft, "write");
+ }
if ((fd = open (msgnam = m_name (msgnum), O_RDONLY)) == NOTOK) {
admonish (msgnam, "unable to read message");
snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n",
mp->numsel > 1 ? "s" : "");
}
- write (out, buffer, strlen (buffer));
+ if (write (out, buffer, strlen (buffer)) < 0) {
+ advise (drft, "write");
+ }
if (digest) {
snprintf (buffer, sizeof(buffer), "End of %s Digest [Volume %d Issue %d]\n",
*bp++ = '*';
*bp++ = '\n';
*bp = 0;
- write (out, buffer, strlen (buffer));
+ if (write (out, buffer, strlen (buffer)) < 0) {
+ advise (drft, "write");
+ }
}
}
snprintf (buffer, sizeof(buffer), "#forw [forwarded message%s] +%s",
mp->numsel == 1 ? "" : "s", mp->foldpath);
- write (out, buffer, strlen (buffer));
+ if (write (out, buffer, strlen (buffer)) < 0) {
+ advise (drft, "write");
+ }
for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
if (is_selected (mp, msgnum)) {
snprintf (buffer, sizeof(buffer), " %s", m_name (msgnum));
- write (out, buffer, strlen (buffer));
+ if (write (out, buffer, strlen (buffer)) < 0) {
+ advise (drft, "write");
+ }
}
- write (out, "\n", 1);
+ if (write (out, "\n", 1) < 0) {
+ advise (drft, "write newline");
+ }
}
}
}
- chdir (mypath);
+ if (chdir (mypath) < 0) {
+ advise (mypath, "chdir");
+ }
if (chdir (pathname) == NOTOK) {
cp = concat ("\"", pathname, "\" doesn't exist; Create it? ", NULL);
if (autof || gans (cp, anoyes))
}
fflush (stdout);
buf[0] = 0;
- read (fileno (stdout), buf, sizeof(buf));
+ if (read (fileno (stdout), buf, sizeof(buf)) < 0) {
+ advise ("stdout", "read");
+ }
}
if (strchr(buf, '\n')) {
if ((global.c_flags & CLEARSCR))
putchar ('\007');
fflush (stdout);
buf[0] = 0;
- read (fileno (stdout), buf, sizeof(buf));
+ if (read (fileno (stdout), buf, sizeof(buf)) < 0) {
+ advise ("stdout", "read");
+ }
if (strchr(buf, '\n')) {
if (global.c_flags & CLEARSCR)
nmh_clear_screen ();
while (state == BODY) {
int bufsz2 = bufsz;
- write(fdinput[1], buf, strlen(buf));
+ if (write(fdinput[1], buf, strlen(buf)) < 0) {
+ advise ("pipe output", "write");
+ }
state = m_getfld (&gstate, name, buf, &bufsz2, fp);
}
return NOTOK;
case OK:
- if (cracked)
- chdir (cracked);
+ if (cracked) {
+ if (chdir (cracked) < 0) {
+ advise (cracked, "chdir");
+ }
+ }
if (!xstdin)
dup2 (fd, 0);
close (fd);
status = NOTOK;
break;
} else {
- write (fd, dest_buffer, outbytes_before - outbytes);
+ if (write (fd, dest_buffer, outbytes_before - outbytes)
+ < 0) {
+ advise (dest, "write");
+ }
}
}
b.sequences = sequences;
if (folders == NULL) {
- chdir(m_maildir(""));
+ if (chdir(m_maildir("")) < 0) {
+ advise (m_maildir(""), "chdir");
+ }
crawl_folders(".", crawl_callback, &b);
} else {
fp = fopen(folders, "r");
/* TODO: Split enough of scan.c out so that we can call it here. */
command = concat("scan +", node->n_name, " ", sequences_s,
(void *)NULL);
- system(command);
+ if (system(command) == NOTOK) {
+ adios (command, "system");
+ }
free(command);
} else {
if (node->n_field == NULL) {
int inpipe[2]; /* for reading from the server */
int outpipe[2]; /* for sending to the server */
- pipe(inpipe);
- pipe(outpipe);
+ if (pipe(inpipe) < 0) {
+ adios ("inpipe", "pipe");
+ }
+ if (pipe(outpipe) < 0) {
+ adios ("outpipe", "pipe");
+ }
pid=fork();
if (pid==0) {
nfs = new_fs (form, format, SCANFMT);
scan (stdin, 0, 0, nfs, width, 0, 0, NULL, 0L, 0, &scanl);
scan_finished ();
- if (newline)
- write (fd, "\n\r", 2);
- write (fd, charstring_buffer (scanl), charstring_bytes (scanl));
+ if (newline) {
+ if (write (fd, "\n\r", 2) < 0) {
+ advise (tfile, "write LF/CR");
+ }
+ }
+ if (write (fd, charstring_buffer (scanl), charstring_bytes (scanl)) < 0) {
+ advise (tfile, "write");
+ }
charstring_free (scanl);
- if (bell)
- write (fd, "\007", 1);
+ if (bell) {
+ if (write (fd, "\007", 1) < 0) {
+ advise (tfile, "write BEL");
+ }
+ }
return fd;
}
register struct msgs *mp;
for (fp = folders, ep = folders + nfolders; fp < ep; fp++) {
- chdir (m_maildir (""));
+ if (chdir (m_maildir ("")) < 0) {
+ advise (m_maildir (""), "chdir");
+ }
strncpy (nmaildir, m_maildir (fp->f_name), sizeof(nmaildir));
/*
fp->f_mp = src_folder;
}
- chdir (maildir);
+ if (maildir[0] != '\0' && chdir (maildir) < 0) {
+ advise (maildir, "chdir");
+ }
}
}
execvp (mhl, arglist);
errstr = strerror(errno);
- write(2, "unable to exec ", 15);
- write(2, mhlproc, strlen(mhlproc));
- write(2, ": ", 2);
- write(2, errstr, strlen(errstr));
- write(2, "\n", 1);
+ if (write(2, "unable to exec ", 15) < 0 ||
+ write(2, mhlproc, strlen(mhlproc)) < 0 ||
+ write(2, ": ", 2) < 0 ||
+ write(2, errstr, strlen(errstr)) < 0 ||
+ write(2, "\n", 1) < 0) {
+ advise ("stderr", "write");
+ }
_exit (-1);
default:
*/
rma (folder);
- chdir ("..");
+ if (chdir ("..") < 0) {
+ advise ("..", "chdir");
+ }
if (others == 0 && remdir (maildir))
return OK;
} else {
lseek (out, (off_t) 0, SEEK_END);
strncpy (buf, "\nMessage not delivered to anyone.\n", sizeof(buf));
- write (out, buf, strlen (buf));
+ if (write (out, buf, strlen (buf)) < 0) {
+ advise (file, "write");
+ }
strncpy (buf, "\n------- Unsent Draft\n\n", sizeof(buf));
- write (out, buf, strlen (buf));
+ if (write (out, buf, strlen (buf)) < 0) {
+ advise (file, "write");
+ }
cpydgst (in, out, file, "temporary file");
close (in);
strncpy (buf, "\n------- End of Unsent Draft\n", sizeof(buf));
- write (out, buf, strlen (buf));
+ if (write (out, buf, strlen (buf)) < 0) {
+ advise (file, "write");
+ }
if (rename (file, strncpy (buf, m_backup (file), sizeof(buf))) == NOTOK)
admonish (buf, "unable to rename %s to", file);
}
/* reset the signal mask */
sigprocmask (SIG_SETMASK, &oset, &set);
- chdir (cwd);
+ if (chdir (cwd) < 0) {
+ advise (cwd, "chdir");
+ }
break;
default: /* no waiting... */
adios (NULL, "no such local user as %s", user);
if (chdir (pw->pw_dir) == -1)
- chdir ("/");
+ if (chdir ("/") < 0) {
+ advise ("/", "chdir");
+ }
umask (0077);
if (geteuid() == 0) {
/* child process */
if (fd != 0)
dup2 (fd, 0);
- freopen ("/dev/null", "w", stdout);
- freopen ("/dev/null", "w", stderr);
+ if (freopen ("/dev/null", "w", stdout) == NULL) {
+ advise ("stdout", "freopen");
+ }
+ if (freopen ("/dev/null", "w", stderr) == NULL) {
+ advise ("stderr", "freopen");
+ }
if (fd != 3)
dup2 (fd, 3);
closefds (4);
context_save (); /* save the context file */
fflush (stdout);
- if (cwd)
- chdir (cwd);
+ if (cwd) {
+ if (chdir (cwd) < 0) {
+ advise (cwd, "chdir");
+ }
+ }
/*
* If the "whatnowproc" is the nmh command "whatnow",
writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
}
if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
- fgets(cwd, sizeof (cwd), f);
+ if (fgets(cwd, sizeof (cwd), f) == NULL) {
+ advise (buf, "fgets");
+ }
if (strchr(cwd, '\n') != (char *)0)
*strchr(cwd, '\n') = '\0';
if (atfile) {
(void) m_unlink (linkpath);
if (link (altpath, linkpath) == NOTOK) {
- symlink (altpath, linkpath);
+ if (symlink (altpath, linkpath) < 0) {
+ adios (linkpath, "symlink");
+ }
slinked = 1;
} else {
slinked = 0;
break;
case OK:
- if (cwd)
- chdir (cwd);
+ if (cwd) {
+ if (chdir (cwd) < 0) {
+ advise (cwd, "chdir");
+ }
+ }
if (altmsg) {
if (mp)
m_putenv ("mhfolder", mp->foldpath);