2
Internal function to generate temporary file name for tmpnam.
4
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
5
This program and the accompanying materials are licensed and made available
6
under the terms and conditions of the BSD License that accompanies this
7
distribution. The full text of the license may be found at
8
http://opensource.org/licenses/bsd-license.php.
10
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
Copyright (c) 1987, 1993
14
The Regents of the University of California. All rights reserved.
16
Redistribution and use in source and binary forms, with or without
17
modification, are permitted provided that the following conditions
19
1. Redistributions of source code must retain the above copyright
20
notice, this list of conditions and the following disclaimer.
21
2. Redistributions in binary form must reproduce the above copyright
22
notice, this list of conditions and the following disclaimer in the
23
documentation and/or other materials provided with the distribution.
24
3. Neither the name of the University nor the names of its contributors
25
may be used to endorse or promote products derived from this software
26
without specific prior written permission.
28
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40
mktemp.c 8.1 (Berkeley) 6/4/93
41
NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp
43
#include <LibConfig.h>
45
#if HAVE_NBTOOL_CONFIG_H
46
#include "nbtool_config.h"
49
#if !defined(HAVE_NBTOOL_CONFIG_H) || !defined(HAVE_MKSTEMP) || !defined(HAVE_MKDTEMP)
51
#include <sys/EfiCdefs.h>
53
#include <sys/types.h>
64
#if HAVE_NBTOOL_CONFIG_H
65
#define GETTEMP gettemp
67
#include "reentrant.h"
69
#define GETTEMP __gettemp
82
/* To guarantee multiple calls generate unique names even if
83
the file is not created. 676 different possibilities with 7
84
or more X's, 26 with 6 or less. */
85
static char xtra[] = "aa";
88
_DIAGASSERT(path != NULL);
89
/* doopen may be NULL */
91
/* Move to end of path and count trailing X's. */
92
for (trv = path; *trv; ++trv) {
101
/* Use at least one from xtra. Use 2 if more than 6 X's. */
102
if (*(trv - 1) == 'X')
104
if (xcnt > 6 && *(trv - 1) == 'X')
107
/* Set remaining X's to 0's. */
108
while (*--trv == 'X') {
112
/* update xtra for next call. */
124
* check the target directory; if you have six X's and it
125
* doesn't exist this runs for a *very* long time.
127
for (start = trv + 1;; --trv) {
132
if (stat(path, &sbuf))
134
if (!S_ISDIR(sbuf.st_mode)) {
146
open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
150
} else if (domkdir) {
151
if (mkdir(path, 0700) >= 0)
155
} else if (lstat(path, &sbuf))
156
return (errno == ENOENT ? 1 : 0);
158
/* tricky little algorithm for backward compatibility */
159
for (trv = start;;) {
166
if (isdigit((unsigned char)*trv))
177
#endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP || !HAVE_MKDTEMP */