1*7e1f3053Sasou /* $OpenBSD: fwide.c,v 1.6 2019/12/03 05:03:37 asou Exp $ */
2c2fb3212Sespie /* $NetBSD: fwide.c,v 1.2 2003/01/18 11:29:54 thorpej Exp $ */
3c2fb3212Sespie
4c2fb3212Sespie /*-
5c2fb3212Sespie * Copyright (c)2001 Citrus Project,
6c2fb3212Sespie * All rights reserved.
7c2fb3212Sespie *
8c2fb3212Sespie * Redistribution and use in source and binary forms, with or without
9c2fb3212Sespie * modification, are permitted provided that the following conditions
10c2fb3212Sespie * are met:
11c2fb3212Sespie * 1. Redistributions of source code must retain the above copyright
12c2fb3212Sespie * notice, this list of conditions and the following disclaimer.
13c2fb3212Sespie * 2. Redistributions in binary form must reproduce the above copyright
14c2fb3212Sespie * notice, this list of conditions and the following disclaimer in the
15c2fb3212Sespie * documentation and/or other materials provided with the distribution.
16c2fb3212Sespie *
17c2fb3212Sespie * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18c2fb3212Sespie * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19c2fb3212Sespie * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20c2fb3212Sespie * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21c2fb3212Sespie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22c2fb3212Sespie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23c2fb3212Sespie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24c2fb3212Sespie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25c2fb3212Sespie * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26c2fb3212Sespie * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27c2fb3212Sespie * SUCH DAMAGE.
28c2fb3212Sespie *
29c2fb3212Sespie * $Citrus$
30c2fb3212Sespie */
31c2fb3212Sespie
32c2fb3212Sespie #include <stdio.h>
33c2fb3212Sespie #include <wchar.h>
34c2fb3212Sespie #include "local.h"
35c2fb3212Sespie
36c2fb3212Sespie int
fwide(FILE * fp,int mode)37c2fb3212Sespie fwide(FILE *fp, int mode)
38c2fb3212Sespie {
39c2fb3212Sespie struct wchar_io_data *wcio;
40c2fb3212Sespie
41c2fb3212Sespie /*
42c2fb3212Sespie * this implementation use only -1, 0, 1
43c2fb3212Sespie * for mode value.
44c2fb3212Sespie * (we don't need to do this, but
45c2fb3212Sespie * this can make things simpler.)
46c2fb3212Sespie */
47c2fb3212Sespie if (mode > 0)
48c2fb3212Sespie mode = 1;
49c2fb3212Sespie else if (mode < 0)
50c2fb3212Sespie mode = -1;
51c2fb3212Sespie
52c5acf43aSkurt FLOCKFILE(fp);
53c2fb3212Sespie wcio = WCIO_GET(fp);
54*7e1f3053Sasou if (!wcio) {
55*7e1f3053Sasou FUNLOCKFILE(fp);
56c2fb3212Sespie return 0; /* XXX */
57*7e1f3053Sasou }
58c2fb3212Sespie
59c2fb3212Sespie if (wcio->wcio_mode == 0 && mode != 0)
60c2fb3212Sespie wcio->wcio_mode = mode;
61c2fb3212Sespie else
62c2fb3212Sespie mode = wcio->wcio_mode;
63c5acf43aSkurt FUNLOCKFILE(fp);
64c2fb3212Sespie
65c2fb3212Sespie return mode;
66c2fb3212Sespie }
679b9d2a55Sguenther DEF_STRONG(fwide);
68