1 #pragma ident "%Z%%M% %I% %E% SMI" /* from UCB 5.2 3/9/86 */ 2 /* 3 * Copyright (c) 1983 Regents of the University of California. 4 * All rights reserved. The Berkeley software License Agreement 5 * specifies the terms and conditions for redistribution. 6 */ 7 8 #include <sys/file.h> 9 10 mkstemp(as) 11 char *as; 12 { 13 register char *s; 14 register unsigned int pid; 15 register int fd, i; 16 17 pid = getpid(); 18 s = as; 19 while (*s++) 20 /* void */; 21 s--; 22 while (*--s == 'X') { 23 *s = (pid % 10) + '0'; 24 pid /= 10; 25 } 26 s++; 27 i = 'a'; 28 while ((fd = open(as, O_CREAT|O_EXCL|O_RDWR, 0600)) == -1) { 29 if (i == 'z') 30 return(-1); 31 *s = i++; 32 } 33 return(fd); 34 } 35