This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/mkstemp.c

30 lines
660 B
C
Raw Permalink Normal View History

#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] );
}
}
}