fputws.c (7591ae56aeeefc978363f92d208d5e1140090f96) fputws.c (2f2c1839f8d6025a050277b9abf31a330100c06d)
1/*-
1/*-
2 * Copyright (c) 2002 Tim J. Robbins.
2 * Copyright (c) 2002-2004 Tim J. Robbins.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 16 unchanged lines hidden (view full) ---

27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD$");
29
30#include "namespace.h"
31#include <errno.h>
32#include <stdio.h>
33#include <wchar.h>
34#include "un-namespace.h"
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 16 unchanged lines hidden (view full) ---

27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD$");
29
30#include "namespace.h"
31#include <errno.h>
32#include <stdio.h>
33#include <wchar.h>
34#include "un-namespace.h"
35#include "fvwrite.h"
35#include "libc_private.h"
36#include "local.h"
36#include "libc_private.h"
37#include "local.h"
38#include "mblocal.h"
37
38int
39fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
40{
39
40int
41fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
42{
43 size_t nbytes;
44 char buf[BUFSIZ];
45 struct __suio uio;
46 struct __siov iov;
41
42 FLOCKFILE(fp);
43 ORIENT(fp, 1);
47
48 FLOCKFILE(fp);
49 ORIENT(fp, 1);
44 /* XXX Inefficient */
45 while (*ws != '\0')
46 if (__fputwc(*ws++, fp) == WEOF) {
47 FUNLOCKFILE(fp);
48 return (-1);
49 }
50 if (prepwrite(fp) != 0)
51 goto error;
52 uio.uio_iov = &iov;
53 uio.uio_iovcnt = 1;
54 iov.iov_base = buf;
55 do {
56 nbytes = __wcsrtombs(buf, &ws, sizeof(buf),
57 &fp->_extra->mbstate);
58 if (nbytes == (size_t)-1)
59 goto error;
60 iov.iov_len = uio.uio_resid = nbytes;
61 if (__sfvwrite(fp, &uio) != 0)
62 goto error;
63 } while (ws != NULL);
50 FUNLOCKFILE(fp);
64 FUNLOCKFILE(fp);
51
52 return (0);
65 return (0);
66
67error:
68 FUNLOCKFILE(fp);
69 return (-1);
53}
70}