diff options
author | Tim J. Robbins <tjr@FreeBSD.org> | 2004-07-21 08:35:18 +0000 |
---|---|---|
committer | Tim J. Robbins <tjr@FreeBSD.org> | 2004-07-21 08:35:18 +0000 |
commit | 2f2c1839f8d6025a050277b9abf31a330100c06d (patch) | |
tree | 4044cf8d7dc6d53a8a9b9831c8f7d80cdd99bcfe /lib/libc/stdio | |
parent | 05656b6e2b1af2f71b6ddba3335ba95ea7b4ac87 (diff) | |
download | src-2f2c1839f8d6025a050277b9abf31a330100c06d.tar.gz src-2f2c1839f8d6025a050277b9abf31a330100c06d.zip |
Notes
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/fputws.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/libc/stdio/fputws.c b/lib/libc/stdio/fputws.c index 467f0982745b..b5be7317ba72 100644 --- a/lib/libc/stdio/fputws.c +++ b/lib/libc/stdio/fputws.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002 Tim J. Robbins. + * Copyright (c) 2002-2004 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,22 +32,39 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> #include <wchar.h> #include "un-namespace.h" +#include "fvwrite.h" #include "libc_private.h" #include "local.h" +#include "mblocal.h" int fputws(const wchar_t * __restrict ws, FILE * __restrict fp) { + size_t nbytes; + char buf[BUFSIZ]; + struct __suio uio; + struct __siov iov; FLOCKFILE(fp); ORIENT(fp, 1); - /* XXX Inefficient */ - while (*ws != '\0') - if (__fputwc(*ws++, fp) == WEOF) { - FUNLOCKFILE(fp); - return (-1); - } + if (prepwrite(fp) != 0) + goto error; + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + iov.iov_base = buf; + do { + nbytes = __wcsrtombs(buf, &ws, sizeof(buf), + &fp->_extra->mbstate); + if (nbytes == (size_t)-1) + goto error; + iov.iov_len = uio.uio_resid = nbytes; + if (__sfvwrite(fp, &uio) != 0) + goto error; + } while (ws != NULL); FUNLOCKFILE(fp); - return (0); + +error: + FUNLOCKFILE(fp); + return (-1); } |