Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jan 2010 07:17:16 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r202183 - user/ed/utmpx/lib/libc/gen
Message-ID:  <201001130717.o0D7HGlj035266@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Wed Jan 13 07:17:16 2010
New Revision: 202183
URL: http://svn.freebsd.org/changeset/base/202183

Log:
  Just use an iovec instead of copying things around unnecessary.

Modified:
  user/ed/utmpx/lib/libc/gen/pututxline.c

Modified: user/ed/utmpx/lib/libc/gen/pututxline.c
==============================================================================
--- user/ed/utmpx/lib/libc/gen/pututxline.c	Wed Jan 13 06:47:27 2010	(r202182)
+++ user/ed/utmpx/lib/libc/gen/pututxline.c	Wed Jan 13 07:17:16 2010	(r202183)
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
 #include "namespace.h"
 #include <sys/endian.h>
 #include <sys/stat.h>
+#include <sys/uio.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
@@ -211,12 +212,9 @@ utx_lastlogin_upgrade(void)
 static void
 utx_log_add(const struct futx *fu)
 {
-	struct {
-		uint16_t	len;
-		struct futx	data;
-	} __packed r;
-	size_t l;
-	int f;
+	int fd;
+	uint16_t l;
+	struct iovec vec[2];
 
 	/*
 	 * Append an entry to the log file.  We only need to append
@@ -224,15 +222,18 @@ utx_log_add(const struct futx *fu)
 	 * zero-bytes.  Prepend a length field, indicating the length of
 	 * the record, excluding the length field itself.
 	 */
-	for (l = sizeof *fu; l > 0 && ((char *)fu)[l - 1] == '\0'; l--);
-	r.len = htobe16(l);
-	memcpy(&r.data, fu, l);
+	for (l = sizeof *fu; l > 0 && ((const char *)fu)[l - 1] == '\0'; l--);
+	vec[0].iov_base = &l;
+	vec[0].iov_len = sizeof l;
+	vec[1].iov_base = __DECONST(void*, fu);
+	vec[1].iov_len = l;
+	l = htobe16(l);
 
-	f = _open(_PATH_UTX_LOG, O_CREAT|O_WRONLY|O_APPEND, 0644);
-	if (f < 0)
+	fd = _open(_PATH_UTX_LOG, O_CREAT|O_WRONLY|O_APPEND, 0644);
+	if (fd < 0)
 		return;
-	_write(f, &r, sizeof r.len + l);
-	_close(f);
+	_writev(fd, vec, 2);
+	_close(fd);
 }
 
 struct utmpx *



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001130717.o0D7HGlj035266>