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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1996, by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 /* 28 * wio_put.c 29 * 30 * Wide I/O Library 31 * 32 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved. 33 * 34 */ 35 36 #if M_RCSID 37 #ifndef lint 38 static char rcsID[] = "$Header: /rd/src/libc/wide/rcs/wio_put.c 1.1 1995/07/26 17:51:21 ant Exp $"; 39 #endif 40 #endif 41 42 #include <mks.h> 43 #include <errno.h> 44 #include <m_wio.h> 45 46 /* 47 * Return the number of bytes written. Errno will be set for errors. 48 * 49 * The function referenced by "put" is passed a byte value and the 50 * pointer "object", and returns the byte value or EOF if no further 51 * data can be written. 52 */ 53 int 54 m_wio_put(wc, wio) 55 wint_t wc; 56 t_wide_io *wio; 57 { 58 int count, mb_len; 59 unsigned char *ptr; 60 61 if (wio == (t_wide_io *) 0 || wio->put == (int (*)(int, void *)) 0) { 62 errno = EINVAL; 63 return -1; 64 } 65 66 /* Force shift-in state at end-of-file. */ 67 if (wc == WEOF) 68 wc = '\0'; 69 70 if ((mb_len = wcrtomb((char *) wio->_mb, wc, &wio->_state)) < 0) 71 /* Note errno will have been set by wcrtomb(). */ 72 return -1; 73 74 /* When shift-in state has been forced don't write '\0' byte. 75 * The "stream" object is considered to be in "text" mode, in 76 * which case file I/O produces undefined results for systems 77 * using locking-shift character sets. 78 */ 79 if (wc == '\0') 80 --mb_len; 81 82 /* Write multibyte character sequence. */ 83 for (ptr = wio->_mb, count = 0; count < mb_len; ++ptr, ++count) 84 if ((*wio->put)(*ptr, wio->object) == EOF) 85 break; 86 87 /* Remember just in case some one needs it. */ 88 wio->_size = mb_len; 89 wio->_next = count; 90 91 return count; 92 } 93 94