=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/signify/signify.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/signify/signify.c 2014/01/01 17:50:33 1.6 --- src/usr.bin/signify/signify.c 2014/01/02 16:34:02 1.7 *************** *** 1,4 **** ! /* $OpenBSD: signify.c,v 1.6 2014/01/01 17:50:33 tedu Exp $ */ /* * Copyright (c) 2013 Ted Unangst * --- 1,4 ---- ! /* $OpenBSD: signify.c,v 1.7 2014/01/02 16:34:02 espie Exp $ */ /* * Copyright (c) 2013 Ted Unangst * *************** *** 92,101 **** } static void ! readall(int fd, void *buf, size_t len) { ! if (read(fd, buf, len) != len) ! err(1, "read"); } static void --- 92,105 ---- } static void ! readall(int fd, void *buf, size_t len, const char *filename) { ! ssize_t x = read(fd, buf, len); ! if (x == -1) { ! err(1, "read from %s", filename); ! } else if (x != len) { ! errx(1, "short read from %s", filename); ! } } static void *************** *** 108,114 **** memset(b64, 0, sizeof(b64)); rv = read(fd, b64, sizeof(b64) - 1); if (rv == -1) ! err(1, "read in %s", filename); for (i = 0; i < rv; i++) if (b64[i] == '\n') break; --- 112,118 ---- memset(b64, 0, sizeof(b64)); rv = read(fd, b64, sizeof(b64) - 1); if (rv == -1) ! err(1, "read from %s", filename); for (i = 0; i < rv; i++) if (b64[i] == '\n') break; *************** *** 137,143 **** if (msglen > (1UL << 30)) errx(1, "msg too large in %s", filename); msg = xmalloc(msglen); ! readall(fd, msg, msglen); close(fd); *msglenp = msglen; --- 141,147 ---- if (msglen > (1UL << 30)) errx(1, "msg too large in %s", filename); msg = xmalloc(msglen); ! readall(fd, msg, msglen, filename); close(fd); *msglenp = msglen; *************** *** 145,154 **** } static void ! writeall(int fd, const void *buf, size_t len) { ! if (write(fd, buf, len) != len) ! err(1, "write"); } static void --- 149,162 ---- } static void ! writeall(int fd, const void *buf, size_t len, const char *filename) { ! ssize_t x = write(fd, buf, len); ! if (x == -1) { ! err(1, "write to %s", filename); ! } else if (x != len) { ! errx(1, "short write to %s", filename); ! } } static void *************** *** 161,170 **** fd = xopen(filename, O_CREAT|O_EXCL|O_NOFOLLOW|O_RDWR, mode); snprintf(header, sizeof(header), "signify -- %s\n", comment); ! writeall(fd, header, strlen(header)); if ((rv = b64_ntop(buf, len, b64, sizeof(b64))) == -1) errx(1, "b64 encode failed"); ! writeall(fd, b64, rv); memset(b64, 0, sizeof(b64)); close(fd); } --- 169,178 ---- fd = xopen(filename, O_CREAT|O_EXCL|O_NOFOLLOW|O_RDWR, mode); snprintf(header, sizeof(header), "signify -- %s\n", comment); ! writeall(fd, header, strlen(header), filename); if ((rv = b64_ntop(buf, len, b64, sizeof(b64))) == -1) errx(1, "b64 encode failed"); ! writeall(fd, b64, rv, filename); memset(b64, 0, sizeof(b64)); close(fd); }