diff options
author | yasuoka <> | 2025-05-25 00:20:54 +0000 |
---|---|---|
committer | yasuoka <> | 2025-05-25 00:20:54 +0000 |
commit | 05d2a9c66d6d77326bcdda5607d6a1cc119a16da (patch) | |
tree | c57eee305f3da335d6fa3adb48553f06b3da3f7c /src/regress/lib/libc/stdio/test___freadahead.c | |
parent | 9e8330b94fd53de40ec3bf3d580cedb3dcbe0131 (diff) | |
download | openbsd-05d2a9c66d6d77326bcdda5607d6a1cc119a16da.tar.gz openbsd-05d2a9c66d6d77326bcdda5607d6a1cc119a16da.tar.bz2 openbsd-05d2a9c66d6d77326bcdda5607d6a1cc119a16da.zip |
Add tests for the functions in <stdio_ext.h>.
Diffstat (limited to 'src/regress/lib/libc/stdio/test___freadahead.c')
-rw-r--r-- | src/regress/lib/libc/stdio/test___freadahead.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/regress/lib/libc/stdio/test___freadahead.c b/src/regress/lib/libc/stdio/test___freadahead.c new file mode 100644 index 0000000000..c853e23975 --- /dev/null +++ b/src/regress/lib/libc/stdio/test___freadahead.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* $OpenBSD: test___freadahead.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 <errno.h> | ||
21 | #include <stdio.h> | ||
22 | #include <stdio_ext.h> | ||
23 | #include <stdlib.h> | ||
24 | |||
25 | /* we use assert() */ | ||
26 | #undef NDEBUG | ||
27 | |||
28 | #define TMPFILENAME "test___freadahead.tmp" | ||
29 | |||
30 | void test___freadahead0(void); | ||
31 | |||
32 | void | ||
33 | test___freadahead0(void) | ||
34 | { | ||
35 | FILE *fp; | ||
36 | int r; | ||
37 | size_t s; | ||
38 | |||
39 | fp = fopen(TMPFILENAME, "w"); | ||
40 | assert(fp != NULL); | ||
41 | r = fputs("Hello world", fp); | ||
42 | assert(r >= 0); | ||
43 | r = fclose(fp); | ||
44 | |||
45 | fp = fopen(TMPFILENAME, "r"); | ||
46 | s = __freadahead(fp); | ||
47 | assert(s == 0); | ||
48 | assert(fgetc(fp) == 'H'); | ||
49 | s = __freadahead(fp); | ||
50 | assert(s == 10); | ||
51 | r = fflush(fp); | ||
52 | #if 1 | ||
53 | /* fflush() to reading file is not supported (yet) */ | ||
54 | assert(errno == EBADF); | ||
55 | #else | ||
56 | assert(r == 0); | ||
57 | s = __freadahead(fp); | ||
58 | assert(s == 0); | ||
59 | #endif | ||
60 | |||
61 | r = fclose(fp); | ||
62 | assert(r == 0); | ||
63 | } | ||
64 | |||
65 | int | ||
66 | main(int argc, char *argv[]) | ||
67 | { | ||
68 | test___freadahead0(); | ||
69 | |||
70 | exit(0); | ||
71 | } | ||