1 /* Verify that fseek/ftell combination works for wide chars.
2 Copyright (C) 2012 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 <http://www.gnu.org/licenses/>. */
27 /* Defined in test-skeleton.c. */
28 static int create_temp_file (const char *base
, char **filename
);
32 do_seek_end (FILE *fp
)
36 if (fputws (L
"abc\n", fp
) == -1)
38 printf ("do_seek_end: fputws: %s\n", strerror (errno
));
45 if (fseek (fp
, 0, SEEK_END
) == -1)
47 printf ("do_seek_end: fseek: %s\n", strerror (errno
));
51 if (save
!= ftell (fp
))
53 printf ("save = %ld, ftell = %ld\n", save
, ftell (fp
));
61 do_seek_set (FILE *fp
)
65 if (fputws (L
"ゅう\n", fp
) == -1)
67 printf ("seek_set: fputws(1): %s\n", strerror (errno
));
73 if (fputws (L
"ゅう\n", fp
) == -1)
75 printf ("seek_set: fputws(2): %s\n", strerror (errno
));
81 if (fputws (L
"ゅう\n", fp
) == -1)
83 printf ("seek_set: fputws(3): %s\n", strerror (errno
));
87 if (fseek (fp
, save1
, SEEK_SET
) == -1)
89 printf ("seek_set: fseek(1): %s\n", strerror (errno
));
93 if (save1
!= ftell (fp
))
95 printf ("save1 = %ld, ftell = %ld\n", save1
, ftell (fp
));
99 if (fseek (fp
, save2
, SEEK_SET
) == -1)
101 printf ("seek_set: fseek(2): %s\n", strerror (errno
));
105 if (save2
!= ftell (fp
))
107 printf ("save2 = %ld, ftell = %ld\n", save2
, ftell (fp
));
117 if (setlocale (LC_ALL
, "ja_JP.UTF-8") == NULL
)
119 printf ("Cannot set ja_JP.UTF-8 locale.\n");
123 /* Retain messages in English. */
124 if (setlocale (LC_MESSAGES
, "en_US.ISO-8859-1") == NULL
)
126 printf ("Cannot set LC_MESSAGES to en_US.ISO-8859-1 locale.\n");
132 int fd
= create_temp_file ("tst-fseek.out", &filename
);
137 FILE *fp
= fdopen (fd
, "w+");
140 printf ("seek_set: fopen: %s\n", strerror (errno
));
145 if (do_seek_set (fp
))
147 printf ("SEEK_SET test failed\n");
151 /* Reopen the file. */
153 fp
= fopen (filename
, "w+");
156 printf ("seek_end: fopen: %s\n", strerror (errno
));
160 if (do_seek_end (fp
))
162 printf ("SEEK_END test failed\n");
172 #define TEST_FUNCTION do_test ()
173 #include "../test-skeleton.c"