1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1986 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * Putws transforms process codes in wchar_t array pointed to by 32 * "ptr" into a byte string, and writes the string followed 33 * by a new-line character to stdout. 34 */ 35 36 #include "lint.h" 37 #include "file64.h" 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <wchar.h> 41 #include <limits.h> 42 #include "stdiom.h" 43 #include "libc.h" 44 45 int 46 putws(const wchar_t *ptr) 47 { 48 wchar_t *ptr0 = (wchar_t *)ptr; 49 ptrdiff_t diff; 50 rmutex_t *lk; 51 52 FLOCKFILE(lk, stdout); 53 for (; *ptr; ptr++) { /* putwc till NULL */ 54 if (fputwc(*ptr, stdout) == EOF) { 55 FUNLOCKFILE(lk); 56 return (EOF); 57 } 58 } 59 (void) fputwc('\n', stdout); /* append a new line */ 60 FUNLOCKFILE(lk); 61 62 if (fflush(stdout)) /* flush line */ 63 return (EOF); 64 diff = ptr - ptr0; 65 if (diff <= INT_MAX) 66 return ((int)diff); 67 else 68 return (EOF); 69 } 70