summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/gen/mkstemp.c
blob: ef2169b590f3d0650da71035e3fd56e5cef57b85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int
mkstemp(char *template)
{
   char *s;
   int i, fd;

   s = strdup(template);
   if(s == NULL)
       return -1;
   for(i=0; i<20; i++){
       strcpy(s, template);
       mktemp(s);
       if((fd = creat(s, 0666)) >= 0){
           strcpy(template, s);
           free(s);
           return fd;
       }
   }
   free(s);
   return -1;
}