summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libc/stdio/test___freading.c42
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
31void setup(void);
32
30void test___freading0(void); 33void test___freading0(void);
31void test___freading1(void); 34void test___freading1(void);
35void test___freading2(void);
36
37void
38setup(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
33void 50void
34test___freading0(void) 51test___freading0(void)
@@ -75,11 +92,34 @@ test___freading1(void)
75 assert(r == 0); 92 assert(r == 0);
76} 93}
77 94
95void
96test___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
78int 117int
79main(int argc, char *argv[]) 118main(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}