2018-10-10 04:11:28 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2018-11-22 10:27:07 +03:00
|
|
|
#include <fcntl.h>
|
2018-10-10 04:11:28 +03:00
|
|
|
|
|
|
|
char * mktemp(char * template) {
|
|
|
|
if (strstr(template + strlen(template)-6, "XXXXXX") != template + strlen(template) - 6) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
static int _i = 0;
|
|
|
|
char tmp[7] = {0};
|
|
|
|
sprintf(tmp,"%04d%02d", getpid(), _i++);
|
|
|
|
memcpy(template + strlen(template) - 6, tmp, 6);
|
|
|
|
return template;
|
|
|
|
}
|
2018-11-22 10:27:07 +03:00
|
|
|
|
|
|
|
int mkstemp(char * template) {
|
|
|
|
mktemp(template);
|
|
|
|
return open(template, O_RDWR | O_CREAT, 0600);
|
|
|
|
}
|