1 /* Verify that fseek/ftell combination works for wide chars.
2 Copyright (C) 2012-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
27 #include <support/temp_file.h>
30 do_seek_end (FILE *fp
)
34 if (fputws (L
"abc\n", fp
) == -1)
36 printf ("do_seek_end: fputws: %s\n", strerror (errno
));
43 if (fseek (fp
, 0, SEEK_END
) == -1)
45 printf ("do_seek_end: fseek: %s\n", strerror (errno
));
49 if (save
!= ftell (fp
))
51 printf ("save = %ld, ftell = %ld\n", save
, ftell (fp
));
59 do_seek_set (FILE *fp
)
63 if (fputws (L
"ゅう\n", fp
) == -1)
65 printf ("seek_set: fputws(1): %s\n", strerror (errno
));
71 if (fputws (L
"ゅう\n", fp
) == -1)
73 printf ("seek_set: fputws(2): %s\n", strerror (errno
));
79 if (fputws (L
"ゅう\n", fp
) == -1)
81 printf ("seek_set: fputws(3): %s\n", strerror (errno
));
85 if (fseek (fp
, save1
, SEEK_SET
) == -1)
87 printf ("seek_set: fseek(1): %s\n", strerror (errno
));
91 if (save1
!= ftell (fp
))
93 printf ("save1 = %ld, ftell = %ld\n", save1
, ftell (fp
));
97 if (fseek (fp
, save2
, SEEK_SET
) == -1)
99 printf ("seek_set: fseek(2): %s\n", strerror (errno
));
103 if (save2
!= ftell (fp
))
105 printf ("save2 = %ld, ftell = %ld\n", save2
, ftell (fp
));
115 if (setlocale (LC_ALL
, "ja_JP.UTF-8") == NULL
)
117 printf ("Cannot set ja_JP.UTF-8 locale.\n");
121 /* Retain messages in English. */
122 if (setlocale (LC_MESSAGES
, "en_US.ISO-8859-1") == NULL
)
124 printf ("Cannot set LC_MESSAGES to en_US.ISO-8859-1 locale.\n");
130 int fd
= create_temp_file ("tst-fseek.out", &filename
);
135 FILE *fp
= fdopen (fd
, "w+");
138 printf ("seek_set: fopen: %s\n", strerror (errno
));
143 if (do_seek_set (fp
))
145 printf ("SEEK_SET test failed\n");
149 /* Reopen the file. */
151 fp
= fopen (filename
, "w+");
154 printf ("seek_end: fopen: %s\n", strerror (errno
));
158 if (do_seek_end (fp
))
160 printf ("SEEK_END test failed\n");
169 #include <support/test-driver.c>