diff options
author | yasuoka <> | 2025-06-12 07:39:26 +0000 |
---|---|---|
committer | yasuoka <> | 2025-06-12 07:39:26 +0000 |
commit | 3af56aa67c2ee450d5fe9bb9dd8b27ab96164ec4 (patch) | |
tree | 25bb1c81c50103e97c8e5b02d348e4a5b6b00467 /src | |
parent | db595b260f3f3a5526a970bb9dd98392840d6550 (diff) | |
download | openbsd-3af56aa67c2ee450d5fe9bb9dd8b27ab96164ec4.tar.gz openbsd-3af56aa67c2ee450d5fe9bb9dd8b27ab96164ec4.tar.bz2 openbsd-3af56aa67c2ee450d5fe9bb9dd8b27ab96164ec4.zip |
Add a test to verify the fpurge problem doesn't happen. fpurge()
mistaknely made the write buffer usable even if the stream is read
mode. See the change of lib/libc/stdio/fpurge.c,v 1.11.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/stdio/test___freading.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/regress/lib/libc/stdio/test___freading.c b/src/regress/lib/libc/stdio/test___freading.c index 05716f3a38..f74eb78d35 100644 --- a/src/regress/lib/libc/stdio/test___freading.c +++ b/src/regress/lib/libc/stdio/test___freading.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: test___freading.c,v 1.1 2025/05/25 00:20:54 yasuoka Exp $ */ | 1 | /* $OpenBSD: test___freading.c,v 1.2 2025/06/12 07:39:26 yasuoka Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2025 YASUOKA Masahiko <yasuoka@yasuoka.net> | 4 | * Copyright (c) 2025 YASUOKA Masahiko <yasuoka@yasuoka.net> |
@@ -21,14 +21,31 @@ | |||
21 | #include <stdio_ext.h> | 21 | #include <stdio_ext.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <unistd.h> | ||
24 | 25 | ||
25 | /* we use assert() */ | 26 | /* we use assert() */ |
26 | #undef NDEBUG | 27 | #undef NDEBUG |
27 | 28 | ||
28 | #define TMPFILENAME "test___freading.tmp" | 29 | #define TMPFILENAME "test___freading.tmp" |
29 | 30 | ||
31 | void setup(void); | ||
32 | |||
30 | void test___freading0(void); | 33 | void test___freading0(void); |
31 | void test___freading1(void); | 34 | void test___freading1(void); |
35 | void test___freading2(void); | ||
36 | |||
37 | void | ||
38 | setup(void) | ||
39 | { | ||
40 | FILE *fp; | ||
41 | |||
42 | /* common setup */ | ||
43 | unlink(TMPFILENAME); | ||
44 | fp = fopen(TMPFILENAME, "w+"); | ||
45 | assert(fp != NULL); | ||
46 | fputs("Hello world\n", fp); | ||
47 | fclose(fp); | ||
48 | } | ||
32 | 49 | ||
33 | void | 50 | void |
34 | test___freading0(void) | 51 | test___freading0(void) |
@@ -75,11 +92,34 @@ test___freading1(void) | |||
75 | assert(r == 0); | 92 | assert(r == 0); |
76 | } | 93 | } |
77 | 94 | ||
95 | void | ||
96 | test___freading2(void) | ||
97 | { | ||
98 | int r; | ||
99 | FILE *fp; | ||
100 | |||
101 | /* | ||
102 | * until v1.10 of fpurge.c mistakenly enables the writing buffer | ||
103 | * without _SRD flag set. | ||
104 | */ | ||
105 | fp = fopen(TMPFILENAME, "r+"); | ||
106 | assert(fp != NULL); | ||
107 | assert(fgetc(fp) == 'H'); | ||
108 | fpurge(fp); | ||
109 | fseek(fp, 0, SEEK_CUR); | ||
110 | assert(fputc('X', fp) == 'X'); | ||
111 | assert(__freading(fp) == 0); | ||
112 | |||
113 | r = fclose(fp); | ||
114 | assert(r == 0); | ||
115 | } | ||
116 | |||
78 | int | 117 | int |
79 | main(int argc, char *argv[]) | 118 | main(int argc, char *argv[]) |
80 | { | 119 | { |
81 | test___freading0(); | 120 | test___freading0(); |
82 | test___freading1(); | 121 | test___freading1(); |
122 | test___freading2(); | ||
83 | 123 | ||
84 | exit(0); | 124 | exit(0); |
85 | } | 125 | } |