mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[win32] That weird mkstemp was our implementation
This commit is contained in:
parent
7ae3b46579
commit
2dfcc60be9
@ -27,6 +27,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <share.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "elinks.h"
|
#include "elinks.h"
|
||||||
|
|
||||||
@ -279,19 +281,32 @@ gettimeofday(struct timeval* p, void* tz)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
mkstemp(char *template_)
|
mkstemp(char *template_name)
|
||||||
{
|
{
|
||||||
char pathname[MAX_PATH];
|
int i, j, fd, len, index;
|
||||||
|
|
||||||
/* Get the directory for temp files */
|
static const char letters[] = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789";
|
||||||
GetTempPath(MAX_PATH, pathname);
|
|
||||||
|
|
||||||
/* Create a temporary file. */
|
if (template_name == NULL || (len = strlen(template_name)) < 6
|
||||||
GetTempFileName(pathname, "ABC", 0, template_);
|
|| memcmp(template_name + (len - 6), "XXXXXX", 6)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return open(template_, O_WRONLY | O_BINARY | O_EXCL);
|
for (index = len - 6; index > 0 && template_name[index - 1] == 'X'; index--);
|
||||||
|
|
||||||
|
for (i = 0; i >= 0; i++) {
|
||||||
|
for (j = index; j < len; j++) {
|
||||||
|
template_name[j] = letters[rand() % 62];
|
||||||
|
}
|
||||||
|
fd = _sopen(template_name,
|
||||||
|
_O_RDWR | _O_CREAT | _O_EXCL | _O_BINARY,
|
||||||
|
_SH_DENYRW, _S_IREAD | _S_IWRITE);
|
||||||
|
if (fd != -1) return fd;
|
||||||
|
if (fd == -1 && errno != EEXIST) return -1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -30,37 +30,6 @@
|
|||||||
#include "util/secsave.h"
|
#include "util/secsave.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_OS_WIN32
|
|
||||||
static int
|
|
||||||
win_mkstemp(char *template_name)
|
|
||||||
{
|
|
||||||
int i, j, fd, len, index;
|
|
||||||
|
|
||||||
static const char letters[] = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789";
|
|
||||||
|
|
||||||
if (template_name == NULL || (len = strlen(template_name)) < 6
|
|
||||||
|| memcmp(template_name + (len - 6), "XXXXXX", 6)) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (index = len - 6; index > 0 && template_name[index - 1] == 'X'; index--);
|
|
||||||
|
|
||||||
for (i = 0; i >= 0; i++) {
|
|
||||||
for (j = index; j < len; j++) {
|
|
||||||
template_name[j] = letters[rand() % 62];
|
|
||||||
}
|
|
||||||
fd = _sopen(template_name,
|
|
||||||
_O_RDWR | _O_CREAT | _O_EXCL | _O_BINARY,
|
|
||||||
_SH_DENYRW, _S_IREAD | _S_IWRITE);
|
|
||||||
if (fd != -1) return fd;
|
|
||||||
if (fd == -1 && errno != EEXIST) return -1;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If infofiles.secure_save is set:
|
/* If infofiles.secure_save is set:
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
*
|
*
|
||||||
@ -195,12 +164,9 @@ secure_open_umask(char *file_name)
|
|||||||
goto free_file_name;
|
goto free_file_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_OS_WIN32
|
|
||||||
fd = win_mkstemp(randname);
|
|
||||||
#else
|
|
||||||
/* No need to use safe_mkstemp() here. --Zas */
|
/* No need to use safe_mkstemp() here. --Zas */
|
||||||
fd = mkstemp(randname);
|
fd = mkstemp(randname);
|
||||||
#endif
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
secsave_errno = SS_ERR_MKSTEMP;
|
secsave_errno = SS_ERR_MKSTEMP;
|
||||||
mem_free(randname);
|
mem_free(randname);
|
||||||
|
Loading…
Reference in New Issue
Block a user