annotate tests/test-freading.c @ 9309:bbbbbf4cd1c5

Change copyright notice from GPLv2+ to GPLv3+.
author Bruno Haible <bruno@clisp.org>
date Sun, 07 Oct 2007 19:14:58 +0200
parents 1f57552cdb11
children 0be6f1ab456d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Test of freading() function.
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
4 This program is free software: you can redistribute it and/or modify
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
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: 8754
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: 8754
diff changeset
7 (at your option) any later version.
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
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: 8754
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #include <config.h>
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include "freading.h"
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
23 #include <stdio.h>
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24 #include <stdlib.h>
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
26 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
27 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
28 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
29 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
30 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
31 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
32 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
33 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
34 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
35 while (0)
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 #define TESTFILE "t-freading.tmp"
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 int
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 main ()
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 {
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 FILE *fp;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 /* Create a file with some contents. Write-only file is never reading. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 fp = fopen (TESTFILE, "w");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 ASSERT (!freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 if (fwrite ("foobarsh", 1, 8, fp) < 8)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 ASSERT (!freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 /* Open it in read-only mode. Read-only file is always reading. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 fp = fopen (TESTFILE, "r");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 ASSERT (freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 if (fgetc (fp) != 'f')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 ASSERT (freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63 if (fseek (fp, 2, SEEK_CUR))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 ASSERT (freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 if (fgetc (fp) != 'b')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 ASSERT (freading (fp));
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
69 fflush (fp);
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
70 ASSERT (freading (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
71 if (fgetc (fp) != 'a')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
72 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
73 ASSERT (freading (fp));
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 if (fseek (fp, 0, SEEK_END))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 ASSERT (freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
78 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
80 /* Open it in read-write mode. POSIX requires a reposition (fseek,
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
81 fsetpos, rewind) or EOF when transitioning from read to write;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 freading is only deterministic after input or output, but this
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 test case should be portable even on open, after reposition, and
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 at EOF. */
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
85 /* First a scenario with only fgetc, fseek, fputc. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86 fp = fopen (TESTFILE, "r+");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
88 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 ASSERT (!freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90 if (fgetc (fp) != 'f')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
91 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
92 ASSERT (freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
93 if (fseek (fp, 2, SEEK_CUR))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
94 goto skip;
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
95 /* freading (fp) is undefined here, but fwriting (fp) is false. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
96 if (fgetc (fp) != 'b')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
97 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
98 ASSERT (freading (fp));
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
99 /* This fseek call is necessary when switching from reading to writing.
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
100 See the description of fopen(), ISO C 99 7.19.5.3.(6). */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
101 if (fseek (fp, 0, SEEK_CUR) != 0)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
102 goto skip;
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
103 /* freading (fp) is undefined here, but fwriting (fp) is false. */
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
104 if (fputc ('x', fp) != 'x')
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
105 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
106 ASSERT (!freading (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
107 if (fseek (fp, 0, SEEK_END))
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
108 goto skip;
8753
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
109 /* freading (fp) is undefined here, because on some implementations (e.g.
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
110 glibc) fseek causes a buffer to be read.
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
111 fwriting (fp) is undefined as well. */
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
112 if (fclose (fp))
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
113 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
114
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
115 /* Open it in read-write mode. POSIX requires a reposition (fseek,
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
116 fsetpos, rewind) or EOF when transitioning from read to write;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
117 freading is only deterministic after input or output, but this
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
118 test case should be portable even on open, after reposition, and
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
119 at EOF. */
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
120 /* Here a scenario that includes fflush. */
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
121 fp = fopen (TESTFILE, "r+");
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
122 if (fp == NULL)
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
123 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
124 ASSERT (!freading (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
125 if (fgetc (fp) != 'f')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
126 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
127 ASSERT (freading (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
128 if (fseek (fp, 2, SEEK_CUR))
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
129 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
130 /* freading (fp) is undefined here, but fwriting (fp) is false. */
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
131 if (fgetc (fp) != 'b')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
132 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
133 ASSERT (freading (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
134 fflush (fp);
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
135 /* freading (fp) is undefined here, but fwriting (fp) is false. */
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
136 if (fgetc (fp) != 'x')
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
137 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
138 ASSERT (freading (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
139 /* This fseek call is necessary when switching from reading to writing.
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
140 See the description of fopen(), ISO C 99 7.19.5.3.(6). */
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
141 if (fseek (fp, 0, SEEK_CUR) != 0)
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
142 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
143 /* freading (fp) is undefined here, but fwriting (fp) is false. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
144 if (fputc ('z', fp) != 'z')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
145 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
146 ASSERT (!freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
147 if (fseek (fp, 0, SEEK_END))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
148 goto skip;
8753
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
149 /* freading (fp) is undefined here, because on some implementations (e.g.
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
150 glibc) fseek causes a buffer to be read.
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
151 fwriting (fp) is undefined as well. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
152 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
153 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
154
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
155 /* Open it in append mode. Write-only file is never reading. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
156 fp = fopen (TESTFILE, "a");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
157 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
158 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
159 ASSERT (!freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
160 if (fwrite ("bla", 1, 3, fp) < 3)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
161 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
162 ASSERT (!freading (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
163 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
164 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
165
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
166 return 0;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
167
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
168 skip:
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
169 fprintf (stderr, "Skipping test: file operations failed.\n");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
170 return 77;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
171 }