diff options
Diffstat (limited to 'src/regress/lib/libc/stdio/test___fpending.c')
-rw-r--r-- | src/regress/lib/libc/stdio/test___fpending.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/regress/lib/libc/stdio/test___fpending.c b/src/regress/lib/libc/stdio/test___fpending.c new file mode 100644 index 0000000000..96ace2e481 --- /dev/null +++ b/src/regress/lib/libc/stdio/test___fpending.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* $OpenBSD: test___fpending.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___fpending.tmp" | ||
28 | |||
29 | void test___fpending0(void); | ||
30 | |||
31 | void | ||
32 | test___fpending0(void) | ||
33 | { | ||
34 | FILE *fp; | ||
35 | int r; | ||
36 | size_t s; | ||
37 | |||
38 | fp = fopen(TMPFILENAME, "w"); | ||
39 | assert(fp != NULL); | ||
40 | r = fputs("Hello world", fp); | ||
41 | assert(r >= 0); | ||
42 | s = __fpending(fp); | ||
43 | assert(s > 0); /* assume buffered */ | ||
44 | r = fflush(fp); | ||
45 | assert(r == 0); | ||
46 | s = __fpending(fp); | ||
47 | assert(s == 0); /* buffer must be 0 */ | ||
48 | r = fclose(fp); | ||
49 | assert(r == 0); | ||
50 | } | ||
51 | |||
52 | int | ||
53 | main(int argc, char *argv[]) | ||
54 | { | ||
55 | test___fpending0(); | ||
56 | |||
57 | exit(0); | ||
58 | } | ||