aboutsummaryrefslogtreecommitdiff
path: root/src/lib9/opentemp.c
blob: c999f49c15746137278d5f033f90a0cec1ff2c80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <u.h>
#include <libc.h>

int
opentemp(char *template, int mode)
{
	int fd, fd1;

	fd = mkstemp(template);
	if(fd < 0)
		return -1;
	if((fd1 = open(template, mode)) < 0){
		remove(template);
		close(fd);
		return -1;
	}
	close(fd);
	return fd1;
}