10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
30Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
40Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
50Sstevel@tonic-gate */
60Sstevel@tonic-gate
7*722Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
8*722Smuffin
90Sstevel@tonic-gate #include <sys/file.h>
100Sstevel@tonic-gate
11*722Smuffin int
mkstemp(char * as)12*722Smuffin mkstemp(char *as)
130Sstevel@tonic-gate {
14*722Smuffin char *s;
15*722Smuffin unsigned int pid;
16*722Smuffin int fd, i;
170Sstevel@tonic-gate
180Sstevel@tonic-gate pid = getpid();
190Sstevel@tonic-gate s = as;
200Sstevel@tonic-gate while (*s++)
210Sstevel@tonic-gate /* void */;
220Sstevel@tonic-gate s--;
230Sstevel@tonic-gate while (*--s == 'X') {
240Sstevel@tonic-gate *s = (pid % 10) + '0';
250Sstevel@tonic-gate pid /= 10;
260Sstevel@tonic-gate }
270Sstevel@tonic-gate s++;
280Sstevel@tonic-gate i = 'a';
290Sstevel@tonic-gate while ((fd = open(as, O_CREAT|O_EXCL|O_RDWR, 0600)) == -1) {
300Sstevel@tonic-gate if (i == 'z')
31*722Smuffin return (-1);
320Sstevel@tonic-gate *s = i++;
330Sstevel@tonic-gate }
34*722Smuffin return (fd);
350Sstevel@tonic-gate }
36