]>
Commit | Line | Data |
---|---|---|
277f8cdf | 1 | /* Test for ,ccs= handling in fopen. |
6d7e8eda | 2 | Copyright (C) 2001-2023 Free Software Foundation, Inc. |
277f8cdf | 3 | This file is part of the GNU C Library. |
277f8cdf UD |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
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. | |
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 | |
13 | Lesser General Public License for more details. | |
14 | ||
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/>. */ |
277f8cdf UD |
18 | |
19 | #include <errno.h> | |
20 | #include <locale.h> | |
21 | #include <mcheck.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | #include <wchar.h> | |
6909d276 | 26 | #include <sys/resource.h> |
f0f0d79a AS |
27 | #include <support/support.h> |
28 | #include <support/xstdio.h> | |
277f8cdf | 29 | |
277f8cdf UD |
30 | static const char inputfile[] = "../iconvdata/testdata/ISO-8859-1"; |
31 | ||
d68eba50 PP |
32 | static int |
33 | do_bz17916 (void) | |
6909d276 PP |
34 | { |
35 | /* BZ #17916 -- check invalid large ccs= case. */ | |
36 | struct rlimit rl; | |
37 | getrlimit (RLIMIT_STACK, &rl); | |
38 | rl.rlim_cur = 1024 * 1024; | |
39 | setrlimit (RLIMIT_STACK, &rl); | |
40 | ||
41 | const size_t sz = 2 * 1024 * 1024; | |
850c6760 | 42 | char *ccs = xmalloc (sz); |
6909d276 PP |
43 | strcpy (ccs, "r,ccs="); |
44 | memset (ccs + 6, 'A', sz - 6 - 1); | |
45 | ccs[sz - 1] = '\0'; | |
46 | ||
47 | FILE *fp = fopen (inputfile, ccs); | |
48 | if (fp != NULL) | |
49 | { | |
7f0d9e61 | 50 | printf ("unexpected success\n"); |
6909d276 PP |
51 | return 1; |
52 | } | |
53 | free (ccs); | |
54 | ||
55 | return 0; | |
56 | } | |
277f8cdf | 57 | |
8b460906 AS |
58 | static int |
59 | do_test (void) | |
277f8cdf UD |
60 | { |
61 | FILE *fp; | |
62 | ||
63 | mtrace (); | |
64 | ||
f0f0d79a | 65 | xsetlocale (LC_ALL, "de_DE.UTF-8"); |
277f8cdf | 66 | |
f0f0d79a | 67 | fp = xfopen (inputfile, "r,ccs=ISO-8859-1"); |
277f8cdf UD |
68 | |
69 | while (! feof_unlocked (fp)) | |
70 | { | |
71 | wchar_t buf[200]; | |
72 | ||
73 | if (fgetws_unlocked (buf, sizeof (buf) / sizeof (buf[0]), fp) == NULL) | |
74 | break; | |
75 | ||
76 | fputws (buf, stdout); | |
77 | } | |
78 | ||
f0f0d79a | 79 | xfclose (fp); |
277f8cdf | 80 | |
6909d276 | 81 | return do_bz17916 (); |
277f8cdf | 82 | } |
f0f0d79a AS |
83 | |
84 | #include <support/test-driver.c> |