1#include <assert.h>2#include <stdio.h>3#include <string.h>45/*6output:7testing8test19test210done11end:12*/1314static void15test1(void)16{17 char buf[80];18 FILE *fp1, *fp2;1920 puts("test1");21 fp1 = tmpfile();22 assert(fp1);23 fp2 = tmpfile();24 assert(fp2);2526 fputs("This is the first\n", fp1);27 fputs("This is the second\n", fp2);28 fflush(fp1);29 fflush(fp2);3031 rewind(fp1);32 rewind(fp2);3334 fgets(buf, sizeof(buf), fp1);35 assert(strcmp(buf, "This is the first\n") == 0);3637 fgets(buf, sizeof(buf), fp2);38 assert(strcmp(buf, "This is the second\n") == 0);3940 assert(fclose(fp1) == 0);41 assert(fclose(fp2) == 0);42}4344static void45test2(void)46{47 int i, max;48 FILE *fp;49 static FILE *fps[FOPEN_MAX];5051 puts("test2");5253 max = TMP_MAX - 2;54 if (max > FOPEN_MAX)55 max = FOPEN_MAX - 3;56 if (max > 32)57 max = 32;5859 for (i = 0; i < max; i++)60 assert(fps[i] = tmpfile());6162 for (i = 0; i < max; i++)63 assert(fclose(fps[i]) == 0);64}6566int67main(void)68{69 puts("testing");70 test1();71 test2();72 puts("done");7374 return 0;75}