2004-03-21 14:05:38 +00:00
|
|
|
#include <u.h>
|
|
|
|
|
#include <libc.h>
|
|
|
|
|
|
|
|
|
|
int
|
2008-07-09 08:27:22 -04:00
|
|
|
opentemp(char *template, int mode)
|
2004-03-21 14:05:38 +00:00
|
|
|
{
|
2008-07-09 08:27:22 -04:00
|
|
|
int fd, fd1;
|
2004-06-17 21:19:37 +00:00
|
|
|
|
|
|
|
|
fd = mkstemp(template);
|
|
|
|
|
if(fd < 0)
|
|
|
|
|
return -1;
|
2008-07-09 08:27:22 -04:00
|
|
|
/* reopen for mode */
|
|
|
|
|
fd1 = open(template, mode);
|
|
|
|
|
if(fd1 < 0){
|
|
|
|
|
close(fd);
|
|
|
|
|
remove(template);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
|
|
|
|
return fd1;
|
2004-03-21 14:05:38 +00:00
|
|
|
}
|