]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /*-\r |
2 | * Copyright (c)2001 Citrus Project,\r | |
3 | * All rights reserved.\r | |
4 | *\r | |
5 | * Redistribution and use in source and binary forms, with or without\r | |
6 | * modification, are permitted provided that the following conditions\r | |
7 | * are met:\r | |
8 | * 1. Redistributions of source code must retain the above copyright\r | |
9 | * notice, this list of conditions and the following disclaimer.\r | |
10 | * 2. Redistributions in binary form must reproduce the above copyright\r | |
11 | * notice, this list of conditions and the following disclaimer in the\r | |
12 | * documentation and/or other materials provided with the distribution.\r | |
13 | *\r | |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r | |
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r | |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r | |
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r | |
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r | |
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r | |
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r | |
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r | |
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r | |
24 | * SUCH DAMAGE.\r | |
25 | *\r | |
26 | * $Citrus$\r | |
27 | \r | |
28 | NetBSD: ungetwc.c,v 1.3 2005/06/12 05:21:27 lukem Exp\r | |
29 | */\r | |
30 | #include <LibConfig.h>\r | |
31 | #include <sys/EfiCdefs.h>\r | |
32 | \r | |
33 | #include <assert.h>\r | |
34 | #include <errno.h>\r | |
35 | #include <stdio.h>\r | |
36 | #include <wchar.h>\r | |
37 | #include "reentrant.h"\r | |
38 | #include "local.h"\r | |
39 | \r | |
40 | wint_t\r | |
41 | ungetwc(wint_t wc, FILE *fp)\r | |
42 | {\r | |
43 | struct wchar_io_data *wcio;\r | |
44 | \r | |
45 | _DIAGASSERT(fp);\r | |
46 | \r | |
47 | if (wc == WEOF)\r | |
48 | return WEOF;\r | |
49 | \r | |
50 | FLOCKFILE(fp);\r | |
51 | _SET_ORIENTATION(fp, 1);\r | |
52 | /*\r | |
53 | * XXX since we have no way to transform a wchar string to\r | |
54 | * a char string in reverse order, we can't use ungetc.\r | |
55 | */\r | |
56 | /* XXX should we flush ungetc buffer? */\r | |
57 | \r | |
58 | wcio = WCIO_GET(fp);\r | |
59 | if (wcio == 0) {\r | |
60 | FUNLOCKFILE(fp);\r | |
61 | errno = ENOMEM; /* XXX */\r | |
62 | return WEOF;\r | |
63 | }\r | |
64 | \r | |
65 | if (wcio->wcio_ungetwc_inbuf >= WCIO_UNGETWC_BUFSIZE) {\r | |
66 | FUNLOCKFILE(fp);\r | |
67 | return WEOF;\r | |
68 | }\r | |
69 | \r | |
70 | wcio->wcio_ungetwc_buf[wcio->wcio_ungetwc_inbuf++] = (wchar_t)wc;\r | |
71 | __sclearerr(fp);\r | |
72 | FUNLOCKFILE(fp);\r | |
73 | \r | |
74 | return wc;\r | |
75 | }\r |