30 lines
660 B
C
30 lines
660 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#define TEMPLATE "_tXXXXXX"
|
|
#define MAX_TEMPS 5
|
|
|
|
void main( void )
|
|
{
|
|
char name[sizeof( TEMPLATE )];
|
|
int i;
|
|
int handles[MAX_TEMPS];
|
|
|
|
for( i = 0; i < MAX_TEMPS; i++ ) {
|
|
strcpy( name, TEMPLATE );
|
|
handles[i] = mkstemp( name );
|
|
if( handles[i] == -1 ) {
|
|
printf( "Failed to create temporary file\n" );
|
|
} else {
|
|
printf( "Created temporary file '%s'\n", name );
|
|
}
|
|
}
|
|
for( i = 0; i < MAX_TEMPS; i++ ) {
|
|
if( handles[i] != -1 ) {
|
|
close( handles[i] );
|
|
}
|
|
}
|
|
}
|