1 /* Verify that ftell does not go into an infinite loop when a conversion fails
2 due to insufficient space in the buffer.
3 Copyright (C) 2014 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
28 static int do_test (void);
29 #define TEST_FUNCTION do_test ()
30 #include "../test-skeleton.c"
32 /* Arbitrary number large enough so that the target buffer during conversion is
34 #define STRING_SIZE (1400)
41 wchar_t *inputs[NSTRINGS] = {NULL};
44 if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
46 printf ("Cannot set en_US.UTF-8 locale.\n");
51 /* Generate input from one character, chosen because it has an odd number of
52 bytes in UTF-8, making it easier to reproduce the problem:
54 NAME Hiragana letter GO
60 for (int i = 0; i < NSTRINGS; i++)
62 inputs[i] = malloc (STRING_SIZE * sizeof (wchar_t));
63 if (inputs[i] == NULL)
65 printf ("Failed to allocate memory for inputs: %m\n");
68 wmemset (inputs[i], seed, STRING_SIZE - 1);
69 inputs[i][STRING_SIZE - 1] = L'\0';
73 int fd = create_temp_file ("tst-fseek-wide-partial.out", &filename);
77 printf ("create_temp_file: %m\n");
81 fp = fdopen (fd, "w+");
84 printf ("fopen: %m\n");
89 for (int i = 0; i < NSTRINGS; i++)
91 printf ("offset: %ld\n", ftell (fp));
92 if (fputws (inputs[i], fp) == -1)
103 for (int i = 0; i < NSTRINGS; i++)