1*86d7f5d3SJohn Marino /* $NetBSD: wcio.h,v 1.3 2003/01/18 11:30:00 thorpej Exp $ */ 2*86d7f5d3SJohn Marino /* $DragonFly: src/lib/libc/stdio/wcio.h,v 1.1 2005/07/25 00:37:41 joerg Exp $ */ 3*86d7f5d3SJohn Marino 4*86d7f5d3SJohn Marino /*- 5*86d7f5d3SJohn Marino * Copyright (c)2001 Citrus Project, 6*86d7f5d3SJohn Marino * All rights reserved. 7*86d7f5d3SJohn Marino * 8*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without 9*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions 10*86d7f5d3SJohn Marino * are met: 11*86d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright 12*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer. 13*86d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 14*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the 15*86d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution. 16*86d7f5d3SJohn Marino * 17*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18*86d7f5d3SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*86d7f5d3SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*86d7f5d3SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21*86d7f5d3SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*86d7f5d3SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*86d7f5d3SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*86d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*86d7f5d3SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*86d7f5d3SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*86d7f5d3SJohn Marino * SUCH DAMAGE. 28*86d7f5d3SJohn Marino * 29*86d7f5d3SJohn Marino * $Citrus$ 30*86d7f5d3SJohn Marino */ 31*86d7f5d3SJohn Marino 32*86d7f5d3SJohn Marino #ifndef _WCIO_H_ 33*86d7f5d3SJohn Marino #define _WCIO_H_ 34*86d7f5d3SJohn Marino 35*86d7f5d3SJohn Marino #include <wchar.h> /* for mbstate_t and wchar_t */ 36*86d7f5d3SJohn Marino 37*86d7f5d3SJohn Marino /* minimal requirement of SUSv2 */ 38*86d7f5d3SJohn Marino #define WCIO_UNGETWC_BUFSIZE 1 39*86d7f5d3SJohn Marino 40*86d7f5d3SJohn Marino struct wchar_io_data { 41*86d7f5d3SJohn Marino mbstate_t wcio_mbstate_in; 42*86d7f5d3SJohn Marino mbstate_t wcio_mbstate_out; 43*86d7f5d3SJohn Marino 44*86d7f5d3SJohn Marino wchar_t wcio_ungetwc_buf[WCIO_UNGETWC_BUFSIZE]; 45*86d7f5d3SJohn Marino size_t wcio_ungetwc_inbuf; 46*86d7f5d3SJohn Marino 47*86d7f5d3SJohn Marino int wcio_mode; /* orientation */ 48*86d7f5d3SJohn Marino }; 49*86d7f5d3SJohn Marino 50*86d7f5d3SJohn Marino #define _SET_ORIENTATION(fp, mode) \ 51*86d7f5d3SJohn Marino do {\ 52*86d7f5d3SJohn Marino struct wchar_io_data *_wcio = WCIO_GET(fp);\ 53*86d7f5d3SJohn Marino if (_wcio && _wcio->wcio_mode == 0)\ 54*86d7f5d3SJohn Marino _wcio->wcio_mode = (mode);\ 55*86d7f5d3SJohn Marino } while (/*CONSTCOND*/0) 56*86d7f5d3SJohn Marino 57*86d7f5d3SJohn Marino /* 58*86d7f5d3SJohn Marino * WCIO_FREE should be called by fclose 59*86d7f5d3SJohn Marino */ 60*86d7f5d3SJohn Marino #define WCIO_GET(fp) (&(fp)->_wcio) 61*86d7f5d3SJohn Marino #define WCIO_FREE(fp) \ 62*86d7f5d3SJohn Marino do {\ 63*86d7f5d3SJohn Marino (fp)->_wcio.wcio_mode = 0;\ 64*86d7f5d3SJohn Marino WCIO_FREEUB(fp);\ 65*86d7f5d3SJohn Marino } while (/*CONSTCOND*/0) 66*86d7f5d3SJohn Marino #define WCIO_FREEUB(fp) \ 67*86d7f5d3SJohn Marino do {\ 68*86d7f5d3SJohn Marino (fp)->_wcio.wcio_ungetwc_inbuf = 0;\ 69*86d7f5d3SJohn Marino } while (/*CONSTCOND*/0) 70*86d7f5d3SJohn Marino 71*86d7f5d3SJohn Marino #endif /*_WCIO_H_*/ 72