Files
amiga-libnix2/libnix/sources/nix/extra/mktemp.c
T
jshepher a99f123db5 Fixed missing function warnings.
Moved headers around so we include <devices/timer.h> before <sys/time.h>
(so we don't have to patch the OS headers)
2004-12-04 00:49:38 +00:00

32 lines
488 B
C
Executable File

#include <proto/exec.h>
#include <unistd.h>
#include <fcntl.h>
char *mktemp(char *buf)
{ long pid = (long)FindTask(0L);
char *c = buf;
while(*c++); --c;
while(*--c == 'X') {
*c = pid % 10 + '0';
pid /= 10;
}
if (++c,*c) {
for(*c='A'; *c <= 'Z'; (*c)++) {
if (access(buf,0)) {
return buf;
}
}
*c = 0;
}
return buf;
}
int mkstemp(char *template) {
char *buf = mktemp(template);
return open(buf, O_CREAT | O_TRUNC | O_EXCL);
}