annotate tests/test-fseek.c @ 17149:a49df7b88261

errno: port to LynxOS 178 2.2.2 Problem reported by Joel Brobecker in <http://lists.gnu.org/archive/html/bug-gnulib/2012-10/msg00088.html>. * doc/posix-headers/errno.texi (errno.h): Document this. * lib/errno.in.h (EILSEQ, GNULIB_defined_EILSEQ) [!EILSEQ]: New macros. * lib/strerror-override.c, lib/strerror-override.h (strerror_override): Supply a string for EILSEQ. * m4/errno_h.m4 (gl_HEADER_ERRNO_H): Check for EILSEQ.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 01 Nov 2012 15:29:14 -0700
parents 8250f2777afc
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of fseek() function.
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
2 Copyright (C) 2007-2012 Free Software Foundation, Inc.
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8886
diff changeset
4 This program is free software: you can redistribute it and/or modify
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8886
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8886
diff changeset
7 (at your option) any later version.
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8886
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
12730
8387bca9d256 tests: avoid more large file warnings
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
21 /* None of the files accessed by this test are large, so disable the
8387bca9d256 tests: avoid more large file warnings
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
22 fseek link warning if the user requested GNULIB_POSIXCHECK. */
8387bca9d256 tests: avoid more large file warnings
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
23 #define _GL_NO_LARGE_FILES
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdio.h>
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
25
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
26 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
27 SIGNATURE_CHECK (fseek, int, (FILE *, long, int));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
28
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
29 #include "macros.h"
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
11215
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
31 #ifndef FUNC_UNGETC_BROKEN
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
32 # define FUNC_UNGETC_BROKEN 0
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
33 #endif
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
34
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 int
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 main (int argc, char **argv)
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 {
9872
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
38 /* Assume stdin is non-empty, seekable, and starts with '#!/bin/sh'
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
39 iff argc > 1. */
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 int expected = argc > 1 ? 0 : -1;
9872
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
41 ASSERT (fseek (stdin, 0, SEEK_CUR) == expected);
9526
ca6c212b4ed8 Beef up fseek tests.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
42 if (argc > 1)
ca6c212b4ed8 Beef up fseek tests.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
43 {
9872
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
44 /* Test that fseek discards previously read ungetc data. */
9528
77504e34a17d Another fseek test.
Eric Blake <ebb9@byu.net>
parents: 9526
diff changeset
45 int ch = fgetc (stdin);
9872
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
46 ASSERT (ch == '#');
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
47 ASSERT (ungetc (ch, stdin) == ch);
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
48 ASSERT (fseek (stdin, 2, SEEK_SET) == 0);
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
49 ch = fgetc (stdin);
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
50 ASSERT (ch == '/');
11215
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
51 if (2 < argc)
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
52 {
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
53 if (FUNC_UNGETC_BROKEN)
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
54 {
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
55 fputs ("Skipping test: ungetc cannot handle arbitrary bytes\n",
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
56 stderr);
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
57 return 77;
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
58 }
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
59 /* Test that fseek discards random ungetc data. */
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
60 ASSERT (ungetc (ch ^ 0xff, stdin) == (ch ^ 0xff));
92a6ab18ea18 tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents: 9889
diff changeset
61 }
9872
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
62 ASSERT (fseek (stdin, 0, SEEK_END) == 0);
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
63 ASSERT (fgetc (stdin) == EOF);
9528
77504e34a17d Another fseek test.
Eric Blake <ebb9@byu.net>
parents: 9526
diff changeset
64 /* Test that fseek resets end-of-file marker. */
9872
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
65 ASSERT (feof (stdin));
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
66 ASSERT (fseek (stdin, 0, SEEK_END) == 0);
8724fb6c1548 Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents: 9528
diff changeset
67 ASSERT (!feof (stdin));
9526
ca6c212b4ed8 Beef up fseek tests.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
68 }
ca6c212b4ed8 Beef up fseek tests.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
69 return 0;
8886
b828a58c6933 Tests for module 'fseek'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 }