From ef9da74a3a85403b02a5cccc664dd784d8fd4279 Mon Sep 17 00:00:00 2001 From: Jason Wright Date: Tue, 17 May 2005 18:48:53 +0000 Subject: - check return from write(2) so we KNOW the data is on the disk - remove unneeded variables - add missing includes ok deraadt --- sys/dev/microcode/uyap/build.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'sys/dev/microcode/uyap') diff --git a/sys/dev/microcode/uyap/build.c b/sys/dev/microcode/uyap/build.c index 6f0b204f81f..60347695260 100644 --- a/sys/dev/microcode/uyap/build.c +++ b/sys/dev/microcode/uyap/build.c @@ -1,4 +1,4 @@ -/* $OpenBSD: build.c,v 1.2 2005/04/14 19:01:08 damien Exp $ */ +/* $OpenBSD: build.c,v 1.3 2005/05/17 18:48:52 jason Exp $ */ /* * Copyright (c) 2004 Theo de Raadt @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include +#include #include #include @@ -36,10 +37,28 @@ main(int argc, char *argv[]) err(1, "%s", FILENAME); for (ptr = uyap_firmware; ; ptr++) { - write(fd, &ptr->length, 1); + struct iovec iov[3]; + u_int8_t length; + ssize_t tlen, rlen; + + length = ptr->length; + iov[0].iov_base = &length; + iov[0].iov_len = 1; + address = htole16(ptr->address); - write(fd, &address, 2); - write(fd, ptr->data, ptr->length); + iov[1].iov_base = &address; + iov[1].iov_len = 2; + + iov[2].iov_base = ptr->data; + iov[2].iov_len = ptr->length; + + tlen = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len; + + rlen = writev(fd, iov, 3); + if (rlen == -1) + err(1, "%s", FILENAME); + if (rlen != tlen) + err(1, "%s: short write", FILENAME); if (ptr->length == 0) break; -- cgit v1.2.3