]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 2001-2019 Free Software Foundation, Inc. |
c4f66413 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 2001. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
c4f66413 UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
c4f66413 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
c4f66413 UD |
18 | |
19 | #include <errno.h> | |
20 | #include <iconv.h> | |
21 | #include <mcheck.h> | |
22 | #include <stddef.h> | |
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
25 | #include <string.h> | |
26 | ||
27 | ||
29955b5d AS |
28 | static int |
29 | do_test (void) | |
c4f66413 UD |
30 | { |
31 | char buf[3]; | |
32 | const wchar_t wc[1] = L"a"; | |
33 | iconv_t cd; | |
34 | char *inptr; | |
35 | size_t inlen; | |
36 | char *outptr; | |
37 | size_t outlen; | |
38 | size_t n; | |
39 | int e; | |
40 | int result = 0; | |
41 | ||
42 | mtrace (); | |
43 | ||
44 | cd = iconv_open ("UCS4", "WCHAR_T"); | |
45 | if (cd == (iconv_t) -1) | |
46 | { | |
47 | printf ("cannot convert from wchar_t to UCS4: %m\n"); | |
48 | exit (1); | |
49 | } | |
50 | ||
51 | inptr = (char *) wc; | |
52 | inlen = sizeof (wchar_t); | |
53 | outptr = buf; | |
54 | outlen = 3; | |
55 | ||
56 | n = iconv (cd, &inptr, &inlen, &outptr, &outlen); | |
57 | e = errno; | |
58 | ||
59 | if (n != (size_t) -1) | |
60 | { | |
61 | printf ("incorrect iconv() return value: %zd, expected -1\n", n); | |
62 | result = 1; | |
63 | } | |
64 | ||
65 | if (e != E2BIG) | |
66 | { | |
67 | printf ("incorrect error value: %s, expected %s\n", | |
68 | strerror (e), strerror (E2BIG)); | |
69 | result = 1; | |
70 | } | |
71 | ||
72 | if (inptr != (char *) wc) | |
73 | { | |
74 | puts ("inptr changed"); | |
75 | result = 1; | |
76 | } | |
77 | ||
78 | if (inlen != sizeof (wchar_t)) | |
79 | { | |
80 | puts ("inlen changed"); | |
81 | result = 1; | |
82 | } | |
83 | ||
84 | if (outptr != buf) | |
85 | { | |
86 | puts ("outptr changed"); | |
87 | result = 1; | |
88 | } | |
89 | ||
90 | if (outlen != 3) | |
91 | { | |
92 | puts ("outlen changed"); | |
93 | result = 1; | |
94 | } | |
95 | ||
96 | iconv_close (cd); | |
97 | ||
98 | return result; | |
99 | } | |
29955b5d AS |
100 | |
101 | #define TEST_FUNCTION do_test () | |
102 | #include "../test-skeleton.c" |