Skip to content
Snippets Groups Projects
Commit 81f10993 authored by Christoph Hellwig's avatar Christoph Hellwig
Browse files

add mk*temp functions from musl

parent 22fec155
No related branches found
No related tags found
No related merge requests found
...@@ -16,3 +16,4 @@ ...@@ -16,3 +16,4 @@
/tests/tst-pthread.so: ./tests/tst-pthread.so /tests/tst-pthread.so: ./tests/tst-pthread.so
/tests/tst-malloc.so: ../../external/glibc-testsuite/build/debug/malloc/tst-malloc.so /tests/tst-malloc.so: ../../external/glibc-testsuite/build/debug/malloc/tst-malloc.so
/tests/tst-getcwd.so: ../../external/glibc-testsuite/build/debug/io/tst-getcwd.so /tests/tst-getcwd.so: ../../external/glibc-testsuite/build/debug/io/tst-getcwd.so
/tests/read01.so: ../../external/ltp/build/debug/syscalls/read/read01.so
...@@ -190,6 +190,10 @@ libc += string/wmemcpy.o ...@@ -190,6 +190,10 @@ libc += string/wmemcpy.o
libc += string/wmemmove.o libc += string/wmemmove.o
libc += string/wmemset.o libc += string/wmemset.o
libc += temp/mkdtemp.o
libc += temp/mkstemp.o
libc += temp/mktemp.o
libc += time/__asctime.o libc += time/__asctime.o
libc += time/__time_to_tm.o libc += time/__time_to_tm.o
libc += time/__tm_to_time.o libc += time/__tm_to_time.o
......
...@@ -8,3 +8,9 @@ ...@@ -8,3 +8,9 @@
/* TODO: add real locking */ /* TODO: add real locking */
#define LOCK(x) ((void)(x)) #define LOCK(x) ((void)(x))
#define UNLOCK(x) ((void)(x)) #define UNLOCK(x) ((void)(x))
#undef LFS64_2
#define LFS64_2(x, y) weak_alias(x, y)
#undef LFS64
#define LFS64(x) LFS64_2(x, x##64)
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <sys/stat.h>
#include "libc.h"
char *__mktemp(char *);
char *mkdtemp(char *template)
{
int retries = 100, t0 = *template;
while (retries--) {
if (!*__mktemp(template)) return 0;
if (!mkdir(template, 0700)) return template;
if (errno != EEXIST) return 0;
/* this is safe because mktemp verified
* that we have a valid template string */
template[0] = t0;
strcpy(template+strlen(template)-6, "XXXXXX");
}
return 0;
}
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include "libc.h"
char *__mktemp(char *);
int mkstemp(char *template)
{
int fd, retries = 100, t0 = *template;
while (retries--) {
if (!*__mktemp(template)) return -1;
if ((fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600))>=0)
return fd;
if (errno != EEXIST) return -1;
/* this is safe because mktemp verified
* that we have a valid template string */
template[0] = t0;
strcpy(template+strlen(template)-6, "XXXXXX");
}
return -1;
}
LFS64(mkstemp);
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <stdint.h>
#include <sys/time.h>
#include "libc.h"
char *__mktemp(char *template)
{
struct timeval tv;
size_t i, l = strlen(template);
int retries = 10000;
unsigned long r;
if (l < 6 || strcmp(template+l-6, "XXXXXX")) {
errno = EINVAL;
*template = 0;
return template;
}
while (retries--) {
gettimeofday(&tv, NULL);
r = tv.tv_usec + (uintptr_t)&tv / 16 + (uintptr_t)template;
for (i=1; i<=6; i++, r>>=4)
template[l-i] = 'A'+(r&15);
if (access(template, F_OK) < 0) return template;
}
*template = 0;
errno = EEXIST;
return template;
}
weak_alias(__mktemp, mktemp);
...@@ -289,8 +289,8 @@ void main_thread(elf::program& prog) ...@@ -289,8 +289,8 @@ void main_thread(elf::program& prog)
debug(fmt("clock@t1 %1%") % t1); debug(fmt("clock@t1 %1%") % t1);
debug(fmt("clock@t2 %1%") % t2); debug(fmt("clock@t2 %1%") % t2);
// load_tests(prog); load_tests(prog);
start_jvm(prog); // start_jvm(prog);
while (true) while (true)
; ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment