diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-09-16 19:06:07 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-09-16 19:06:07 +0000 |
commit | d024d31ed98a56ad094940e60162854ee8b7ea2a (patch) | |
tree | 7f148b0544ae17459ff99e4015d98572e3c9631f | |
parent | af38769ea40b77df6f90b6d4cca1e580dea9dd5f (diff) |
use writev() where possible
-rw-r--r-- | lib/libc/gen/exec.c | 15 | ||||
-rw-r--r-- | lib/libc/gen/psignal.c | 21 | ||||
-rw-r--r-- | lib/libc/stdlib/malloc.c | 41 |
3 files changed, 56 insertions, 21 deletions
diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c index 98d4a46776b..4da6feb6cd4 100644 --- a/lib/libc/gen/exec.c +++ b/lib/libc/gen/exec.c @@ -32,11 +32,12 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: exec.c,v 1.8 1998/08/14 21:39:23 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: exec.c,v 1.9 1999/09/16 19:05:58 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> #include <sys/types.h> +#include <sys/uio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> @@ -241,9 +242,15 @@ execvp(name, argv) * the user may execute the wrong program. */ if (lp + ln + 2 > sizeof(buf)) { - (void)write(STDERR_FILENO, "execvp: ", 8); - (void)write(STDERR_FILENO, p, lp); - (void)write(STDERR_FILENO, ": path too long\n", 16); + struct iovec iov[3]; + + iov[0].iov_base = "execvp: "; + iov[0].iov_len = 8; + iov[1].iov_base = p; + iov[1].iov_len = lp; + iov[2].iov_base = ": path too long\n"; + iov[2].iov_len = 16; + (void)writev(STDERR_FILENO, iov, 3); continue; } bcopy(p, buf, lp); diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c index 844e45161d0..c248a4a3251 100644 --- a/lib/libc/gen/psignal.c +++ b/lib/libc/gen/psignal.c @@ -32,13 +32,15 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: psignal.c,v 1.2 1996/08/19 08:25:24 tholo Exp $"; +static char rcsid[] = "$OpenBSD: psignal.c,v 1.3 1999/09/16 19:06:00 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* * Print the name of the signal indicated * along with the supplied message. */ +#include <sys/types.h> +#include <sys/uio.h> #include <signal.h> #include <string.h> #include <unistd.h> @@ -54,13 +56,22 @@ psignal(sig, s) static char buf[NL_TEXTMAX]; register const char *c; register int n; + struct iovec iov[4]; + int niov = 0; c = __strsignal(sig, buf); if (s && *s) { + n = strlen(s); - (void)write(STDERR_FILENO, s, n); - (void)write(STDERR_FILENO, ": ", 2); + iov[0].iov_base = (void *)s; + iov[0].iov_len = n; + iov[1].iov_base = ": "; + iov[1].iov_len = 2; + niov = 2; } - (void)write(STDERR_FILENO, c, strlen(c)); - (void)write(STDERR_FILENO, "\n", 1); + iov[niov].iov_base = (void *)c; + iov[niov].iov_len = strlen(c); + iov[niov+1].iov_base = "\n"; + iov[niov+1].iov_len = 1; + (void)writev(STDERR_FILENO, iov, niov+2); } diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index e75c7cdb097..8b90bb5d57b 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -8,7 +8,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: malloc.c,v 1.35 1999/02/03 03:58:05 d Exp $"; +static char rcsid[] = "$OpenBSD: malloc.c,v 1.36 1999/09/16 19:06:06 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -37,15 +37,16 @@ static char rcsid[] = "$OpenBSD: malloc.c,v 1.35 1999/02/03 03:58:05 d Exp $"; */ #define SOME_JUNK 0xd0 /* as in "Duh" :-) */ +#include <sys/types.h> +#include <sys/param.h> +#include <sys/mman.h> +#include <sys/uio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> -#include <sys/types.h> -#include <sys/param.h> -#include <sys/mman.h> /* * The basic parameters you can tweak. @@ -363,10 +364,18 @@ wrterror(p) char *p; { char *q = " error: "; - write(2, __progname, strlen(__progname)); - write(2, malloc_func, strlen(malloc_func)); - write(2, q, strlen(q)); - write(2, p, strlen(p)); + struct iovec iov[4]; + + iov[0].iov_base = __progname; + iov[0].iov_len = strlen(__progname); + iov[1].iov_base = malloc_func; + iov[1].iov_len = strlen(malloc_func); + iov[2].iov_base = q; + iov[2].iov_len = strlen(q); + iov[3].iov_base = p; + iov[3].iov_len = strlen(p); + writev(STDERR_FILENO, iov, 4); + suicide = 1; #ifdef MALLOC_STATS if (malloc_stats) @@ -380,14 +389,22 @@ wrtwarning(p) char *p; { char *q = " warning: "; + struct iovec iov[4]; + if (malloc_abort) wrterror(p); else if (malloc_silent) return; - write(2, __progname, strlen(__progname)); - write(2, malloc_func, strlen(malloc_func)); - write(2, q, strlen(q)); - write(2, p, strlen(p)); + + iov[0].iov_base = __progname; + iov[0].iov_len = strlen(__progname); + iov[1].iov_base = malloc_func; + iov[1].iov_len = strlen(malloc_func); + iov[2].iov_base = q; + iov[2].iov_len = strlen(q); + iov[3].iov_base = p; + iov[3].iov_len = strlen(p); + writev(STDERR_FILENO, iov, 4); } #ifdef MALLOC_STATS |