mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-03 20:38:59 +00:00
Merged revisions 289104 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r289104 | tilghman | 2010-09-28 13:18:43 -0500 (Tue, 28 Sep 2010) | 4 lines Solaris compatibility fixes Review: https://reviewboard.asterisk.org/r/942/ ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@289112 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
#include <unistd.h> /* for fcntl(2) */
|
||||
#include <fcntl.h> /* for fcntl(2) */
|
||||
|
||||
#include "asterisk/utils.h"
|
||||
|
||||
#ifndef HAVE_STRSEP
|
||||
char *strsep(char **str, const char *delims)
|
||||
{
|
||||
@@ -478,3 +480,91 @@ void closefrom(int n)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MKDTEMP
|
||||
/* $OpenBSD: mktemp.c,v 1.30 2010/03/21 23:09:30 schwarze Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1996-1998, 2008 Theo de Raadt
|
||||
* Copyright (c) 1997, 2008-2009 Todd C. Miller
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#define MKTEMP_NAME 0
|
||||
#define MKTEMP_FILE 1
|
||||
#define MKTEMP_DIR 2
|
||||
|
||||
#define TEMPCHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_."
|
||||
#define NUM_CHARS (sizeof(TEMPCHARS) - 1)
|
||||
|
||||
static int mktemp_internal(char *path, int slen, int mode)
|
||||
{
|
||||
char *start, *cp, *ep;
|
||||
const char *tempchars = TEMPCHARS;
|
||||
unsigned int r, tries;
|
||||
struct stat sb;
|
||||
size_t len;
|
||||
int fd;
|
||||
|
||||
len = strlen(path);
|
||||
if (len == 0 || slen >= len) {
|
||||
errno = EINVAL;
|
||||
return(-1);
|
||||
}
|
||||
ep = path + len - slen;
|
||||
|
||||
tries = 1;
|
||||
for (start = ep; start > path && start[-1] == 'X'; start--) {
|
||||
if (tries < INT_MAX / NUM_CHARS) {
|
||||
tries *= NUM_CHARS;
|
||||
}
|
||||
}
|
||||
tries *= 2;
|
||||
|
||||
do {
|
||||
for (cp = start; cp != ep; cp++) {
|
||||
r = ast_random() % NUM_CHARS;
|
||||
*cp = tempchars[r];
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case MKTEMP_NAME:
|
||||
if (lstat(path, &sb) != 0) {
|
||||
return (errno == ENOENT ? 0 : -1);
|
||||
}
|
||||
break;
|
||||
case MKTEMP_FILE:
|
||||
fd = open(path, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
if (fd != -1 || errno != EEXIST) {
|
||||
return (fd);
|
||||
}
|
||||
break;
|
||||
case MKTEMP_DIR:
|
||||
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0) {
|
||||
return (0);
|
||||
}
|
||||
if (errno != EEXIST) {
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (--tries);
|
||||
|
||||
errno = EEXIST;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
char *mkdtemp(char *path)
|
||||
{
|
||||
return mktemp_internal(path, 0, MKTEMP_DIR) ? NULL : path;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user