diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libc/stdio/test_fflush.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/regress/lib/libc/stdio/test_fflush.c b/src/regress/lib/libc/stdio/test_fflush.c index 76f2d88aba..a0586b7d14 100644 --- a/src/regress/lib/libc/stdio/test_fflush.c +++ b/src/regress/lib/libc/stdio/test_fflush.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: test_fflush.c,v 1.2 2025/05/25 05:35:13 yasuoka Exp $ */ | 1 | /* $OpenBSD: test_fflush.c,v 1.3 2025/06/08 08:53:53 yasuoka Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 2025 YASUOKA Masahiko <yasuoka@yasuoka.net> | 4 | * Copyright (c) 2025 YASUOKA Masahiko <yasuoka@yasuoka.net> |
| @@ -38,6 +38,7 @@ void test_fflush_read3(void); | |||
| 38 | void test_fflush_read4(void); | 38 | void test_fflush_read4(void); |
| 39 | void setupw(void); | 39 | void setupw(void); |
| 40 | void test_fflush_read5(void); | 40 | void test_fflush_read5(void); |
| 41 | void test_fflush_read6(void); | ||
| 41 | 42 | ||
| 42 | void | 43 | void |
| 43 | setup(void) | 44 | setup(void) |
| @@ -290,6 +291,43 @@ test_fflush_read5(void) | |||
| 290 | r = fclose(fp); | 291 | r = fclose(fp); |
| 291 | assert(r == 0); | 292 | assert(r == 0); |
| 292 | } | 293 | } |
| 294 | |||
| 295 | void | ||
| 296 | test_fflush_read6(void) | ||
| 297 | { | ||
| 298 | int r, c; | ||
| 299 | FILE *fp; | ||
| 300 | |||
| 301 | setup(); | ||
| 302 | fp = fopen(TMPFILENAME, "r"); | ||
| 303 | assert(fp != NULL); | ||
| 304 | |||
| 305 | /* | ||
| 306 | * https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html | ||
| 307 | * .. any characters pushed back onto the stream by ungetc() or ungetwc() | ||
| 308 | * that have not subsequently been read from the stream shall be discarded | ||
| 309 | * (without further changing the file offset). | ||
| 310 | */ | ||
| 311 | |||
| 312 | assert(fgetc(fp) == 'H'); | ||
| 313 | c = getc(fp); | ||
| 314 | ungetc(c, fp); /* push back the character has been read */ | ||
| 315 | r = fflush(fp); | ||
| 316 | assert(r == 0); | ||
| 317 | assert(getc(fp) == c); | ||
| 318 | |||
| 319 | fseek(fp, 0, SEEK_SET); | ||
| 320 | assert(fgetc(fp) == 'H'); | ||
| 321 | c = getc(fp); | ||
| 322 | ungetc('X', fp); /* push back the character has not been read */ | ||
| 323 | r = fflush(fp); | ||
| 324 | assert(r == 0); | ||
| 325 | assert(getc(fp) == 'l'); | ||
| 326 | |||
| 327 | r = fclose(fp); | ||
| 328 | assert(r == 0); | ||
| 329 | } | ||
| 330 | |||
| 293 | int | 331 | int |
| 294 | main(int argc, char *argv[]) | 332 | main(int argc, char *argv[]) |
| 295 | { | 333 | { |
| @@ -301,6 +339,7 @@ main(int argc, char *argv[]) | |||
| 301 | test_fflush_read3(); | 339 | test_fflush_read3(); |
| 302 | test_fflush_read4(); | 340 | test_fflush_read4(); |
| 303 | test_fflush_read5(); | 341 | test_fflush_read5(); |
| 342 | test_fflush_read6(); | ||
| 304 | 343 | ||
| 305 | exit(0); | 344 | exit(0); |
| 306 | } | 345 | } |
