svn commit: r202183 - user/ed/utmpx/lib/libc/gen
Ed Schouten
ed at FreeBSD.org
Wed Jan 13 07:17:17 UTC 2010
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 *
More information about the svn-src-user
mailing list