]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/tst-fopenloc.c
INSTALL, install.texi: minor updates, regenerate
[thirdparty/glibc.git] / libio / tst-fopenloc.c
CommitLineData
277f8cdf 1/* Test for ,ccs= handling in fopen.
dff8da6b 2 Copyright (C) 2001-2024 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>
5324d258 20#include <fcntl.h>
277f8cdf
UD
21#include <locale.h>
22#include <mcheck.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <wchar.h>
6909d276 27#include <sys/resource.h>
5324d258 28#include <support/check.h>
f0f0d79a
AS
29#include <support/support.h>
30#include <support/xstdio.h>
277f8cdf 31
277f8cdf
UD
32static const char inputfile[] = "../iconvdata/testdata/ISO-8859-1";
33
d68eba50
PP
34static int
35do_bz17916 (void)
6909d276
PP
36{
37 /* BZ #17916 -- check invalid large ccs= case. */
38 struct rlimit rl;
39 getrlimit (RLIMIT_STACK, &rl);
40 rl.rlim_cur = 1024 * 1024;
41 setrlimit (RLIMIT_STACK, &rl);
42
43 const size_t sz = 2 * 1024 * 1024;
850c6760 44 char *ccs = xmalloc (sz);
6909d276
PP
45 strcpy (ccs, "r,ccs=");
46 memset (ccs + 6, 'A', sz - 6 - 1);
47 ccs[sz - 1] = '\0';
48
49 FILE *fp = fopen (inputfile, ccs);
50 if (fp != NULL)
51 {
7f0d9e61 52 printf ("unexpected success\n");
5324d258
JST
53 free (ccs);
54 fclose (fp);
6909d276
PP
55 return 1;
56 }
5324d258 57
6909d276
PP
58 free (ccs);
59
60 return 0;
61}
277f8cdf 62
5324d258
JST
63static int
64do_bz18906 (void)
65{
66 /* BZ #18906 -- check processing of ,ccs= as flags case. */
67
68 const char *ccs = "r,ccs=+ISO-8859-1";
69 size_t retval;
70
71 FILE *fp = fopen (inputfile, ccs);
72 int flags;
73
74 TEST_VERIFY (fp != NULL);
75
76 if (fp != NULL)
77 {
78 flags = fcntl (fileno (fp), F_GETFL);
f7f181c1
ST
79 retval = ((flags & O_ACCMODE) == O_RDWR);
80 retval |= ((flags & O_ACCMODE) == O_WRONLY);
5324d258
JST
81 TEST_COMPARE (retval, false);
82 fclose (fp);
83 }
84
85 return EXIT_SUCCESS;
86}
87
8b460906
AS
88static int
89do_test (void)
277f8cdf
UD
90{
91 FILE *fp;
92
93 mtrace ();
94
f0f0d79a 95 xsetlocale (LC_ALL, "de_DE.UTF-8");
277f8cdf 96
f0f0d79a 97 fp = xfopen (inputfile, "r,ccs=ISO-8859-1");
277f8cdf
UD
98
99 while (! feof_unlocked (fp))
100 {
101 wchar_t buf[200];
102
103 if (fgetws_unlocked (buf, sizeof (buf) / sizeof (buf[0]), fp) == NULL)
104 break;
105
106 fputws (buf, stdout);
107 }
108
f0f0d79a 109 xfclose (fp);
277f8cdf 110
5324d258
JST
111 TEST_COMPARE (do_bz17916 (), 0);
112 TEST_COMPARE (do_bz18906 (), 0);
113
114 return EXIT_SUCCESS;
277f8cdf 115}
f0f0d79a
AS
116
117#include <support/test-driver.c>