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