diff options
Diffstat (limited to '')
-rw-r--r-- | src/regress/lib/libc/stdio/test___fseterr.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/regress/lib/libc/stdio/test___fseterr.c b/src/regress/lib/libc/stdio/test___fseterr.c new file mode 100644 index 0000000000..70fb491c6c --- /dev/null +++ b/src/regress/lib/libc/stdio/test___fseterr.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* $OpenBSD: test___fseterr.c,v 1.1 2025/05/25 00:20:54 yasuoka Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2025 YASUOKA Masahiko <yasuoka@yasuoka.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <assert.h> | ||
20 | #include <stdio.h> | ||
21 | #include <stdio_ext.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* we use assert() */ | ||
25 | #undef NDEBUG | ||
26 | |||
27 | #define TMPFILENAME "test___fseterr.tmp" | ||
28 | |||
29 | void test___fseterr0(void); | ||
30 | |||
31 | void | ||
32 | test___fseterr0(void) | ||
33 | { | ||
34 | FILE *fp; | ||
35 | int r; | ||
36 | |||
37 | fp = fopen(TMPFILENAME, "w+"); | ||
38 | assert(fp != NULL); | ||
39 | |||
40 | assert(!ferror(fp)); | ||
41 | |||
42 | r = fprintf(fp, "hello world\n"); | ||
43 | assert(r > 0); | ||
44 | |||
45 | __fseterr(fp); | ||
46 | assert(ferror(fp)); | ||
47 | |||
48 | r = fprintf(fp, "hello world\n"); | ||
49 | assert(r == -1); | ||
50 | |||
51 | fclose(fp); | ||
52 | } | ||
53 | |||
54 | int | ||
55 | main(int argc, char *argv[]) | ||
56 | { | ||
57 | test___fseterr0(); | ||
58 | |||
59 | exit(0); | ||
60 | } | ||