annotate tests/test-fwriting.c @ 14079:97fc9a21a8fb

maint: update almost all copyright ranges to include 2011 Run the new "make update-copyright" rule.
author Jim Meyering <meyering@redhat.com>
date Sat, 01 Jan 2011 20:17:23 +0100
parents bc2866336bbb
children 8250f2777afc
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 fwriting() function.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 12724
diff changeset
2 Copyright (C) 2007-2011 Free Software Foundation, Inc.
8720
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
12724
bc2866336bbb stdio: warn on suspicious uses
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
21 /* None of the files accessed by this test are large, so disable the
bc2866336bbb stdio: warn on suspicious uses
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
22 fseek link warning if we are not using the gnulib fseek module. */
bc2866336bbb stdio: warn on suspicious uses
Eric Blake <ebb9@byu.net>
parents: 12559
diff changeset
23 #define _GL_NO_LARGE_FILES
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24 #include "fwriting.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 #include <stdio.h>
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
27
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
28 #include "macros.h"
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 #define TESTFILE "t-fwriting.tmp"
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 int
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 main ()
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 {
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 FILE *fp;
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 /* Create a file with some contents. Write-only file is always writing. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38 fp = fopen (TESTFILE, "w");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 if (fwrite ("foobarsh", 1, 8, fp) < 8)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 /* Open it in read-only mode. Read-only file is never writing. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 fp = fopen (TESTFILE, "r");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 if (fgetc (fp) != 'f')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 if (fseek (fp, 2, SEEK_CUR))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 if (fgetc (fp) != 'b')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 ASSERT (!fwriting (fp));
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
62 fflush (fp);
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
63 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
64 if (fgetc (fp) != 'a')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
65 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
66 ASSERT (!fwriting (fp));
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 if (fseek (fp, 0, SEEK_END))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
69 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
70 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
72
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
73 /* Open it in read-write mode. POSIX requires a reposition (fseek,
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 fsetpos, rewind) or fflush when transitioning from write to read,
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 fwriting is only deterministic after input or output, but this
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 test case should be portable even on open, after reposition, and
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 after fflush. */
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
78 /* First a scenario with only fgetc, fseek, fputc. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79 fp = fopen (TESTFILE, "r+");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
80 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
81 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 if (fgetc (fp) != 'f')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86 if (fseek (fp, 2, SEEK_CUR))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
88 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 if (fgetc (fp) != 'b')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
91 ASSERT (!fwriting (fp));
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
92 /* 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
93 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
94 if (fseek (fp, 0, SEEK_CUR) != 0)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
95 goto skip;
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
96 ASSERT (!fwriting (fp));
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
97 if (fputc ('x', fp) != 'x')
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
98 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
99 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
100 if (fseek (fp, 0, SEEK_END))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
101 goto skip;
8753
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
102 /* 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
103 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
104 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
105 if (fclose (fp))
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
106 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
107
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
108 /* 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
109 fsetpos, rewind) or fflush when transitioning from write to read,
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
110 fwriting 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
111 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
112 after fflush. */
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
113 /* 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
114 fp = fopen (TESTFILE, "r+");
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
115 if (fp == NULL)
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
116 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
117 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
118 if (fgetc (fp) != 'f')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
119 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
120 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
121 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
122 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
123 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
124 if (fgetc (fp) != 'b')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
125 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
126 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
127 fflush (fp);
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
128 ASSERT (!fwriting (fp));
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
129 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
130 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
131 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
132 /* 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
133 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
134 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
135 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
136 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
137 if (fputc ('z', fp) != 'z')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
138 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
139 ASSERT (fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
140 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
141 goto skip;
8753
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
142 /* 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
143 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
144 fwriting (fp) is undefined as well. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
145 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
146 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
147
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
148 /* Open it in append mode. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
149 fp = fopen (TESTFILE, "a");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
150 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
151 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
152 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
153 if (fwrite ("bla", 1, 3, fp) < 3)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
154 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
155 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
156 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
157 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
158
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
159 return 0;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
160
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
161 skip:
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
162 fprintf (stderr, "Skipping test: file operations failed.\n");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
163 return 77;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
164 }