diff options
author | Jason Wright <jason@cvs.openbsd.org> | 2005-05-17 18:48:53 +0000 |
---|---|---|
committer | Jason Wright <jason@cvs.openbsd.org> | 2005-05-17 18:48:53 +0000 |
commit | ef9da74a3a85403b02a5cccc664dd784d8fd4279 (patch) | |
tree | 4efe4dece78a33358d376f9c897bb5809afe155e /sys/dev/microcode/uyap | |
parent | e9fcc6219571e8e6318ebd29c06ddb2f9833431a (diff) |
- check return from write(2) so we KNOW the data is on the disk
- remove unneeded variables
- add missing includes
ok deraadt
Diffstat (limited to 'sys/dev/microcode/uyap')
-rw-r--r-- | sys/dev/microcode/uyap/build.c | 27 |
1 files changed, 23 insertions, 4 deletions
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 <deraadt@openbsd.org> @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/types.h> +#include <sys/uio.h> #include <fcntl.h> #include <sys/param.h> @@ -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; |