11475Scasper /* 21475Scasper * CDDL HEADER START 31475Scasper * 41475Scasper * The contents of this file are subject to the terms of the 51475Scasper * Common Development and Distribution License (the "License"). 61475Scasper * You may not use this file except in compliance with the License. 71475Scasper * 81475Scasper * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91475Scasper * or http://www.opensolaris.org/os/licensing. 101475Scasper * See the License for the specific language governing permissions 111475Scasper * and limitations under the License. 121475Scasper * 131475Scasper * When distributing Covered Code, include this CDDL HEADER in each 141475Scasper * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151475Scasper * If applicable, add the following below this CDDL HEADER, with the 161475Scasper * fields enclosed by brackets "[]" replaced with your own identifying 171475Scasper * information: Portions Copyright [yyyy] [name of copyright owner] 181475Scasper * 191475Scasper * CDDL HEADER END 201475Scasper */ 211475Scasper 221475Scasper /* 23*13093SRoger.Faulkner@Oracle.COM * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 241475Scasper */ 251475Scasper 261475Scasper /* 271475Scasper * mkdtemp(3C) - create a directory with a unique name. 281475Scasper */ 291475Scasper 306812Sraf #include "lint.h" 311475Scasper #include <errno.h> 321475Scasper #include <stdlib.h> 331475Scasper #include <string.h> 341475Scasper #include <sys/stat.h> 351475Scasper 361475Scasper char * mkdtemp(char * template)371475Scaspermkdtemp(char *template) 381475Scasper { 39*13093SRoger.Faulkner@Oracle.COM char *t; 401475Scasper char *r; 411475Scasper 421475Scasper /* Save template */ 43*13093SRoger.Faulkner@Oracle.COM t = strdupa(template); 446812Sraf for (;;) { 451475Scasper r = mktemp(template); 461475Scasper 471475Scasper if (*r == '\0') 481475Scasper return (NULL); 491475Scasper 501475Scasper if (mkdir(template, 0700) == 0) 511475Scasper return (r); 521475Scasper 531475Scasper /* Other errors indicate persistent conditions. */ 541475Scasper if (errno != EEXIST) 551475Scasper return (NULL); 561475Scasper 571475Scasper /* Reset template */ 581475Scasper (void) strcpy(template, t); 591475Scasper } 601475Scasper } 61