Mercurial > hg > octave-lojdl > gnulib-hg
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 |
rev | line source |
---|---|
8886 | 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 | 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 | 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 | 8 |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
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 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
19 #include <config.h> | |
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 | 24 #include <stdio.h> |
12489 | 25 |
26 #include "signature.h" | |
27 SIGNATURE_CHECK (fseek, int, (FILE *, long, int)); | |
28 | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
29 #include "macros.h" |
8886 | 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 | 35 int |
36 main (int argc, char **argv) | |
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 | 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 | 42 if (argc > 1) |
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 | 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 | 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 | 68 } |
69 return 0; | |
8886 | 70 } |