scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 117094fdd583ac0907bef5e80e27f23a84847735
parent 6f15a112f5ed7705f322845bdb7c9914d191dbc7
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Thu,  7 May 2026 10:38:17 +0200

tests/libc: Add 0098-tmpfil

Diffstat:
Mtests/libc/execute/.gitignore | 1+
Atests/libc/execute/0098-tmpfil.c | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/libc/execute/libc-tests.lst | 1+
3 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore @@ -96,3 +96,4 @@ test.log 0095-abs 0096-div 0097-fops +0098-tmpfil diff --git a/tests/libc/execute/0098-tmpfil.c b/tests/libc/execute/0098-tmpfil.c @@ -0,0 +1,75 @@ +#include <assert.h> +#include <stdio.h> +#include <string.h> + +/* +output: +testing +test1 +test2 +done +end: +*/ + +static void +test1(void) +{ + char buf[80]; + FILE *fp1, *fp2; + + puts("test1"); + fp1 = tmpfile(); + assert(fp1); + fp2 = tmpfile(); + assert(fp2); + + fputs("This is the first\n", fp1); + fputs("This is the second\n", fp2); + fflush(fp1); + fflush(fp2); + + rewind(fp1); + rewind(fp2); + + fgets(buf, sizeof(buf), fp1); + assert(strcmp(buf, "This is the first\n") == 0); + + fgets(buf, sizeof(buf), fp2); + assert(strcmp(buf, "This is the second\n") == 0); + + assert(fclose(fp1) == 0); + assert(fclose(fp2) == 0); +} + +static void +test2(void) +{ + int i, max; + FILE *fp; + static FILE *fps[FOPEN_MAX]; + + puts("test2"); + + max = TMP_MAX - 2; + if (max > FOPEN_MAX) + max = FOPEN_MAX; + if (max > 32) + max = 32; + + for (i = 0; i < max; i++) + assert(fps[i] = tmpfile()); + + for (i = 0; i < max; i++) + assert(fclose(fps[i]) == 0); +} + +int +main(void) +{ + puts("testing"); + test1(); + test2(); + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst @@ -94,3 +94,4 @@ 0095-abs 0096-div 0097-fops +0098-tmpfil