forked from enlightenment/efl
Evil: add mkdtemp
This commit is contained in:
parent
fe409a5b42
commit
1c50ffe83f
|
@ -1,3 +1,7 @@
|
|||
2013-03-30 Cedric Bail
|
||||
|
||||
* Evil: Add mkdtemp.
|
||||
|
||||
2013-03-29 Carsten Haitzler (The Rasterman)
|
||||
|
||||
* Fix edje entry to resepct filter callbacks and not clear
|
||||
|
|
2
NEWS
2
NEWS
|
@ -86,6 +86,8 @@ Additions:
|
|||
- automatically support Watchdog.
|
||||
* ecore_imf: Add ecore_imf_context_input_panel_layout_variation_set/get API
|
||||
* Add edje_object_part_text_input_panel_layout_variation_set/get API
|
||||
* Evil:
|
||||
- Add mkdtemp.
|
||||
|
||||
Deprecations:
|
||||
* ecore_x:
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -269,38 +270,30 @@ unsetenv(const char *name)
|
|||
* Files related functions
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
mkstemp(char *__template)
|
||||
static int
|
||||
_mkstemp_init(char *__template, char **suffix, size_t *length, DWORD *val)
|
||||
{
|
||||
const char lookup[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
char *suffix;
|
||||
DWORD val;
|
||||
size_t length;
|
||||
int i;
|
||||
|
||||
if (!__template)
|
||||
return 0;
|
||||
|
||||
length = strlen(__template);
|
||||
if ((length < 6) ||
|
||||
(strncmp (__template + length - 6, "XXXXXX", 6)))
|
||||
*length = strlen(__template);
|
||||
if ((*length < 6) ||
|
||||
(strncmp (__template + *length - 6, "XXXXXX", 6)))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
suffix = __template + length - 6;
|
||||
*suffix = __template + *length - 6;
|
||||
|
||||
val = GetTickCount();
|
||||
val += GetCurrentProcessId();
|
||||
*val = GetTickCount();
|
||||
*val += GetCurrentProcessId();
|
||||
|
||||
for (i = 0; i < 32768; i++)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
_mkstemp(char *suffix, int val)
|
||||
{
|
||||
DWORD v;
|
||||
int fd;
|
||||
|
||||
v = val;
|
||||
const char lookup[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
DWORD v = val;
|
||||
|
||||
suffix[0] = lookup[v % 62];
|
||||
v /= 62;
|
||||
|
@ -315,6 +308,69 @@ mkstemp(char *__template)
|
|||
suffix[5] = lookup[v % 62];
|
||||
v /= 62;
|
||||
|
||||
val += 7777;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
EAPI char *
|
||||
mkdtemp(char *__template)
|
||||
{
|
||||
char *suffix;
|
||||
DWORD val;
|
||||
size_t length;
|
||||
int i;
|
||||
|
||||
if (!__template)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!_mkstemp_init(__template, &suffix, &length, &val))
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < 32768; i++)
|
||||
{
|
||||
val = _mkstemp(suffix, val);
|
||||
|
||||
if (mkdir(__template))
|
||||
return __template;
|
||||
|
||||
if (errno == EFAULT ||
|
||||
errno == ENOSPC ||
|
||||
errno == ENOMEM ||
|
||||
errno == ENOENT ||
|
||||
errno == ENOTDIR ||
|
||||
errno == EPERM ||
|
||||
errno == EROFS)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
errno = EEXIST;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
mkstemp(char *__template)
|
||||
{
|
||||
char *suffix;
|
||||
DWORD val;
|
||||
size_t length;
|
||||
int i;
|
||||
|
||||
if (!__template)
|
||||
return 0;
|
||||
|
||||
if (!_mkstemp_init(__template, &suffix, &length, &val))
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < 32768; i++)
|
||||
{
|
||||
int fd;
|
||||
|
||||
val = _mkstemp(suffix, val);
|
||||
|
||||
#ifndef __MINGW32CE__
|
||||
fd = _open(__template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE);
|
||||
#else /* ! __MINGW32CE__ */
|
||||
|
@ -337,8 +393,6 @@ mkstemp(char *__template)
|
|||
#endif /* __MINGW32CE__ */
|
||||
if (fd >= 0)
|
||||
return fd;
|
||||
|
||||
val += 7777;
|
||||
}
|
||||
|
||||
errno = EEXIST;
|
||||
|
|
|
@ -159,6 +159,13 @@ EAPI int unsetenv(const char *name);
|
|||
*/
|
||||
EAPI int mkstemp(char *__template);
|
||||
|
||||
/**
|
||||
* @brief create an unique temporary directory
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
EAPI char *mkdtemp(char *__template);
|
||||
|
||||
/**
|
||||
* @brief Return an absolute or full path name for a specified relative path name.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue