scc

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

0099-tmpnam.c (560B)


      1 #include <assert.h>
      2 #include <stdio.h>
      3 #include <string.h>
      4 
      5 /*
      6 output:
      7 testing
      8 done
      9 end:
     10 */
     11 
     12 
     13 int
     14 test(void)
     15 {
     16 	int j, i, max;
     17 	char buf[32][L_tmpnam];
     18 
     19 	assert(TMP_MAX >= 25);
     20 
     21 	assert(tmpnam(NULL));
     22 
     23         max = TMP_MAX - 1;
     24         if (max > FOPEN_MAX - 3)
     25                 max = FOPEN_MAX - 3;
     26         if (max > 32)
     27                 max = 32;
     28 
     29 	for (i = 0; i < max; ++i) {
     30 		assert(tmpnam(buf[i]));
     31 		for (j = 0; j < i; j++)
     32 			assert(strcmp(buf[i], buf[j]) != 0);
     33 	}
     34 
     35 	return 0;
     36 }
     37 
     38 int
     39 main(void)
     40 {
     41 	puts("testing");
     42 	test();
     43 	puts("done");
     44 
     45 	return 0;
     46 }