xref: /netbsd-src/lib/libc/stdio/fputws.c (revision 526d942790cc352b6ea7931f9884cc6bdbf20404)
1*526d9427Schristos /* $NetBSD: fputws.c,v 1.2 2012/03/15 18:22:30 christos Exp $ */
25abc4b4fStshiozak 
35abc4b4fStshiozak /*-
45abc4b4fStshiozak  * Copyright (c) 2002 Tim J. Robbins.
55abc4b4fStshiozak  * All rights reserved.
65abc4b4fStshiozak  *
75abc4b4fStshiozak  * Redistribution and use in source and binary forms, with or without
85abc4b4fStshiozak  * modification, are permitted provided that the following conditions
95abc4b4fStshiozak  * are met:
105abc4b4fStshiozak  * 1. Redistributions of source code must retain the above copyright
115abc4b4fStshiozak  *    notice, this list of conditions and the following disclaimer.
125abc4b4fStshiozak  * 2. Redistributions in binary form must reproduce the above copyright
135abc4b4fStshiozak  *    notice, this list of conditions and the following disclaimer in the
145abc4b4fStshiozak  *    documentation and/or other materials provided with the distribution.
155abc4b4fStshiozak  *
165abc4b4fStshiozak  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
175abc4b4fStshiozak  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
185abc4b4fStshiozak  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
195abc4b4fStshiozak  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
205abc4b4fStshiozak  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
215abc4b4fStshiozak  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
225abc4b4fStshiozak  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
235abc4b4fStshiozak  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
245abc4b4fStshiozak  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
255abc4b4fStshiozak  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
265abc4b4fStshiozak  * SUCH DAMAGE.
275abc4b4fStshiozak  *
285abc4b4fStshiozak  * Original version ID:
295abc4b4fStshiozak  * FreeBSD: src/lib/libc/stdio/fputws.c,v 1.4 2002/09/20 13:25:40 tjr Exp
305abc4b4fStshiozak  */
315abc4b4fStshiozak 
325abc4b4fStshiozak #include <sys/cdefs.h>
335abc4b4fStshiozak #if defined(LIBC_SCCS) && !defined(lint)
34*526d9427Schristos __RCSID("$NetBSD: fputws.c,v 1.2 2012/03/15 18:22:30 christos Exp $");
355abc4b4fStshiozak #endif
365abc4b4fStshiozak 
375abc4b4fStshiozak #include <assert.h>
385abc4b4fStshiozak #include <errno.h>
395abc4b4fStshiozak #include <stdio.h>
405abc4b4fStshiozak #include <wchar.h>
415abc4b4fStshiozak #include "reentrant.h"
425abc4b4fStshiozak #include "local.h"
435abc4b4fStshiozak 
445abc4b4fStshiozak int
fputws(const wchar_t * __restrict ws,FILE * __restrict fp)45*526d9427Schristos fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
465abc4b4fStshiozak {
475abc4b4fStshiozak 	_DIAGASSERT(fp != NULL);
485abc4b4fStshiozak 	_DIAGASSERT(ws != NULL);
495abc4b4fStshiozak 
505abc4b4fStshiozak 	FLOCKFILE(fp);
515abc4b4fStshiozak 	_SET_ORIENTATION(fp, 1);
525abc4b4fStshiozak 
535abc4b4fStshiozak 	while (*ws != '\0') {
545abc4b4fStshiozak 		if (__fputwc_unlock(*ws++, fp) == WEOF) {
555abc4b4fStshiozak 			FUNLOCKFILE(fp);
56*526d9427Schristos 			return -1;
575abc4b4fStshiozak 		}
585abc4b4fStshiozak 	}
595abc4b4fStshiozak 
605abc4b4fStshiozak 	FUNLOCKFILE(fp);
615abc4b4fStshiozak 
62*526d9427Schristos 	return 0;
635abc4b4fStshiozak }
64