Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/atf/dist/atf-c use writev(2) instead of dprintf...
details: https://anonhg.NetBSD.org/src/rev/edaf140dc5df
branches: trunk
changeset: 771093:edaf140dc5df
user: christos <christos%NetBSD.org@localhost>
date: Tue Nov 08 20:25:14 2011 +0000
description:
use writev(2) instead of dprintf(3) for portability. Suggested by joerg@
diffstat:
external/bsd/atf/dist/atf-c/tc.c | 47 +++++++++++++++++++++++++++------------
1 files changed, 32 insertions(+), 15 deletions(-)
diffs (67 lines):
diff -r a516ce3c7d51 -r edaf140dc5df external/bsd/atf/dist/atf-c/tc.c
--- a/external/bsd/atf/dist/atf-c/tc.c Tue Nov 08 19:36:30 2011 +0000
+++ b/external/bsd/atf/dist/atf-c/tc.c Tue Nov 08 20:25:14 2011 +0000
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/uio.h>
#include <errno.h>
#include <fcntl.h>
@@ -156,24 +157,40 @@
write_resfile(const int fd, const char *result, const int arg,
const atf_dynstr_t *reason)
{
- if (arg == -1 && reason == NULL) {
- if (dprintf(fd, "%s\n", result) <= 0)
- goto err;
- } else if (arg == -1 && reason != NULL) {
- if (dprintf(fd, "%s: %s\n", result,
- atf_dynstr_cstring(reason)) < 0)
- goto err;
- } else if (arg != -1 && reason != NULL) {
- if (dprintf(fd, "%s(%d): %s\n", result,
- arg, atf_dynstr_cstring(reason)) < 0)
- goto err;
- } else {
- UNREACHABLE;
+ static char NL[] = "\n", CS[] = ": ";
+ char buf[64];
+ const char *r;
+ struct iovec iov[5];
+ ssize_t ret;
+ int count = 0;
+
+ INV(arg == -1 && reason != NULL);
+
+ iov[count].iov_base = __UNCONST(result);
+ iov[count++].iov_len = strlen(result);
+
+ if (reason != NULL) {
+ if (arg != -1) {
+ iov[count].iov_base = buf;
+ iov[count++].iov_len = snprintf(buf, sizeof(buf), "(%d)", arg);
+ }
+
+ iov[count].iov_base = CS;
+ iov[count++].iov_len = sizeof(CS) - 1;
+
+ r = atf_dynstr_cstring(reason);
+ iov[count].iov_base = __UNCONST(r);
+ iov[count++].iov_len = strlen(r);
}
- return atf_no_error();
+ iov[count].iov_base = NL;
+ iov[count++].iov_len = sizeof(NL) - 1;
-err:
+ while ((ret = writev(fd, iov, count)) == -1 && errno == EINTR)
+ continue; /* Retry. */
+ if (ret != -1)
+ return atf_no_error();
+
return atf_libc_error(
errno, "Failed to write results file; result %s, reason %s", result,
reason == NULL ? "null" : atf_dynstr_cstring(reason));
Home |
Main Index |
Thread Index |
Old Index