Mercurial > gnulib
annotate tests/test-fseeko.c @ 17363:5a51fb7777a9
sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin
Problem reported by Marco Atzeri in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>.
* lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]:
Simply delegate to the system <sys/select.h> in this case too.
Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only
if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to
be needed on Solaris either.
* lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]:
Simply delgate to the system <sys/time.h> in this case.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 19 Mar 2013 09:08:47 -0700 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
8709 | 1 /* Test of fseeko() function. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2007-2013 Free Software Foundation, Inc. |
8709 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8872
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
8709 | 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:
8872
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:
8872
diff
changeset
|
7 (at your option) any later version. |
8709 | 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:
8872
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8709 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
19 #include <config.h> | |
20 | |
12255
83ddd76ac091
fflush, freadseek: use fseeko, not fseek
Eric Blake <ebb9@byu.net>
parents:
11215
diff
changeset
|
21 /* None of the files accessed by this test are large, so disable the |
83ddd76ac091
fflush, freadseek: use fseeko, not fseek
Eric Blake <ebb9@byu.net>
parents:
11215
diff
changeset
|
22 fseek link warning if we are not using the gnulib fseek module. */ |
12724 | 23 #define _GL_NO_LARGE_FILES |
12388
c14905650e6d
test-fseeko: fix test for mingw
Eric Blake <ebb9@byu.net>
parents:
12255
diff
changeset
|
24 #include <stdio.h> |
12489 | 25 |
26 #include "signature.h" | |
27 SIGNATURE_CHECK (fseeko, int, (FILE *, off_t, int)); | |
28 | |
12388
c14905650e6d
test-fseeko: fix test for mingw
Eric Blake <ebb9@byu.net>
parents:
12255
diff
changeset
|
29 |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12489
diff
changeset
|
30 #include "macros.h" |
8709 | 31 |
11215
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
32 #ifndef FUNC_UNGETC_BROKEN |
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
33 # define FUNC_UNGETC_BROKEN 0 |
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
34 #endif |
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
35 |
8709 | 36 int |
12482
11bc92a9e2bc
gnulib-common: prefer _GL_UNUSED over _UNUSED_PARAMETER_
Eric Blake <ebb9@byu.net>
parents:
12481
diff
changeset
|
37 main (int argc, char **argv _GL_UNUSED) |
8709 | 38 { |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
39 /* 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
|
40 iff argc > 1. */ |
8872 | 41 int expected = argc > 1 ? 0 : -1; |
42 /* Exit with success only if fseek/fseeko agree. */ | |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
43 int r1 = fseeko (stdin, 0, SEEK_CUR); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
44 int r2 = fseek (stdin, 0, SEEK_CUR); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
45 ASSERT (r1 == r2 && r1 == expected); |
9526 | 46 if (argc > 1) |
47 { | |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
48 /* Test that fseek discards previously read ungetc data. */ |
9528 | 49 int ch = fgetc (stdin); |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
50 ASSERT (ch == '#'); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
51 ASSERT (ungetc (ch, stdin) == ch); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
52 ASSERT (fseeko (stdin, 2, SEEK_SET) == 0); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
53 ch = fgetc (stdin); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
54 ASSERT (ch == '/'); |
11215
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
55 if (2 < argc) |
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
56 { |
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
57 if (FUNC_UNGETC_BROKEN) |
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 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
|
60 stderr); |
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
61 return 77; |
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
62 } |
92a6ab18ea18
tests: skip fseek/ftell tests if ungetc is broken
Eric Blake <ebb9@byu.net>
parents:
9889
diff
changeset
|
63 /* 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
|
64 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
|
65 } |
9872
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
66 ASSERT (fseeko (stdin, 0, SEEK_END) == 0); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
67 ASSERT (fgetc (stdin) == EOF); |
9528 | 68 /* 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
|
69 ASSERT (feof (stdin)); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
70 ASSERT (fseeko (stdin, 0, SEEK_END) == 0); |
8724fb6c1548
Make test-fseeko.c failures meaningful.
Eric Blake <ebb9@byu.net>
parents:
9528
diff
changeset
|
71 ASSERT (!feof (stdin)); |
9526 | 72 } |
73 return 0; | |
8709 | 74 } |