* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)mktemp.c 8.1 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
return (_gettemp(path
, &fd
) ? fd
: -1);
return(_gettemp(path
, (int *)NULL
) ? path
: (char *)NULL
);
register char *start
, *trv
;
for (trv
= path
; *trv
; ++trv
); /* extra X's get set to 0's */
* check the target directory; if you have six X's and it
* doesn't exist this runs for a *very* long time.
for (start
= trv
+ 1;; --trv
) {
if (!S_ISDIR(sbuf
.st_mode
)) {
open(path
, O_CREAT
|O_EXCL
|O_RDWR
, 0600)) >= 0)
else if (stat(path
, &sbuf
))
return(errno
== ENOENT
? 1 : 0);
/* tricky little algorithm for backward compatibility */