annotate tests/test-fwriting.c @ 9084:2932e92d6e31

* lib/version-etc.c (version_etc_va): Default to GPLv3+. * NEWS: Document this change.
author Eric Blake <ebb9@byu.net>
date Tue, 10 Jul 2007 12:22:36 +0000
parents 1f57552cdb11
children bbbbbf4cd1c5
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.
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
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
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
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 any later version.
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
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20 #include <config.h>
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22 #include "fwriting.h"
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
24 #include <stdio.h>
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 #include <stdlib.h>
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
27 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
28 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
29 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
30 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
31 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
32 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
33 abort (); \
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 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8753
diff changeset
36 while (0)
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38 #define TESTFILE "t-fwriting.tmp"
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 int
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 main ()
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 {
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 FILE *fp;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 /* 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
46 fp = fopen (TESTFILE, "w");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 if (fwrite ("foobarsh", 1, 8, fp) < 8)
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 (fclose (fp))
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
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 /* 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
57 fp = fopen (TESTFILE, "r");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 if (fgetc (fp) != 'f')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 if (fseek (fp, 2, SEEK_CUR))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 if (fgetc (fp) != 'b')
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));
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
70 fflush (fp);
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
71 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
72 if (fgetc (fp) != 'a')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
73 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
74 ASSERT (!fwriting (fp));
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 if (fseek (fp, 0, SEEK_END))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
78 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
80
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
81 /* Open it in read-write mode. POSIX requires a reposition (fseek,
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 fsetpos, rewind) or fflush when transitioning from write to read,
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 fwriting is only deterministic after input or output, but this
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 test case should be portable even on open, after reposition, and
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 after fflush. */
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
86 /* First a scenario with only fgetc, fseek, fputc. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 fp = fopen (TESTFILE, "r+");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
88 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
91 if (fgetc (fp) != 'f')
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
92 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
93 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
94 if (fseek (fp, 2, SEEK_CUR))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
95 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
96 ASSERT (!fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
97 if (fgetc (fp) != 'b')
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));
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
100 /* 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
101 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
102 if (fseek (fp, 0, SEEK_CUR) != 0)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
103 goto skip;
8750
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
104 ASSERT (!fwriting (fp));
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
105 if (fputc ('x', fp) != 'x')
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
106 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
107 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
108 if (fseek (fp, 0, SEEK_END))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
109 goto skip;
8753
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
110 /* 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
111 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
112 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
113 if (fclose (fp))
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
114 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
115
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
116 /* 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
117 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
118 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
119 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
120 after fflush. */
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
121 /* 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
122 fp = fopen (TESTFILE, "r+");
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
123 if (fp == NULL)
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
124 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
125 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
126 if (fgetc (fp) != 'f')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
127 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
128 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
129 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
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 if (fgetc (fp) != 'b')
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
133 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
134 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
135 fflush (fp);
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
136 ASSERT (!fwriting (fp));
8751
e66db74e11a7 Oops, fix details and comments of last patch.
Bruno Haible <bruno@clisp.org>
parents: 8750
diff changeset
137 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
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 /* 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
141 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
142 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
143 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
144 ASSERT (!fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
145 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
146 goto skip;
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
147 ASSERT (fwriting (fp));
67a7b3fd6cf2 Make the tests sharper: also test the interaction with fflush().
Bruno Haible <bruno@clisp.org>
parents: 8720
diff changeset
148 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
149 goto skip;
8753
10d7922803f5 freading has an undefined value after repositioning a read-write stream.
Bruno Haible <bruno@clisp.org>
parents: 8751
diff changeset
150 /* 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
151 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
152 fwriting (fp) is undefined as well. */
8720
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
153 if (fclose (fp))
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
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
156 /* Open it in append mode. */
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
157 fp = fopen (TESTFILE, "a");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
158 if (fp == NULL)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
159 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
160 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
161 if (fwrite ("bla", 1, 3, fp) < 3)
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
162 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
163 ASSERT (fwriting (fp));
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
164 if (fclose (fp))
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
165 goto skip;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
166
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
167 return 0;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
168
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
169 skip:
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
170 fprintf (stderr, "Skipping test: file operations failed.\n");
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
171 return 77;
367787d55c9c Implement freading and fwriting.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
172 }