From 8c1ab65c0f548d20b7f177bdb736daaf603340e1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 15:54:38 +0200 Subject: Adding upstream version 0.0~git20221206.8b7148f. Signed-off-by: Daniel Baumann --- libc-top-half/musl/src/temp/__randname.c | 18 ++++++++++++++++++ libc-top-half/musl/src/temp/mkdtemp.c | 23 +++++++++++++++++++++++ libc-top-half/musl/src/temp/mkostemp.c | 9 +++++++++ libc-top-half/musl/src/temp/mkostemps.c | 29 +++++++++++++++++++++++++++++ libc-top-half/musl/src/temp/mkstemp.c | 8 ++++++++ libc-top-half/musl/src/temp/mkstemps.c | 9 +++++++++ libc-top-half/musl/src/temp/mktemp.c | 30 ++++++++++++++++++++++++++++++ 7 files changed, 126 insertions(+) create mode 100644 libc-top-half/musl/src/temp/__randname.c create mode 100644 libc-top-half/musl/src/temp/mkdtemp.c create mode 100644 libc-top-half/musl/src/temp/mkostemp.c create mode 100644 libc-top-half/musl/src/temp/mkostemps.c create mode 100644 libc-top-half/musl/src/temp/mkstemp.c create mode 100644 libc-top-half/musl/src/temp/mkstemps.c create mode 100644 libc-top-half/musl/src/temp/mktemp.c (limited to 'libc-top-half/musl/src/temp') diff --git a/libc-top-half/musl/src/temp/__randname.c b/libc-top-half/musl/src/temp/__randname.c new file mode 100644 index 0000000..2bce37a --- /dev/null +++ b/libc-top-half/musl/src/temp/__randname.c @@ -0,0 +1,18 @@ +#include +#include + +/* This assumes that a check for the + template size has already been made */ +char *__randname(char *template) +{ + int i; + struct timespec ts; + unsigned long r; + + __clock_gettime(CLOCK_REALTIME, &ts); + r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template; + for (i=0; i<6; i++, r>>=5) + template[i] = 'A'+(r&15)+(r&16)*2; + + return template; +} diff --git a/libc-top-half/musl/src/temp/mkdtemp.c b/libc-top-half/musl/src/temp/mkdtemp.c new file mode 100644 index 0000000..5708257 --- /dev/null +++ b/libc-top-half/musl/src/temp/mkdtemp.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +char *mkdtemp(char *template) +{ + size_t l = strlen(template); + int retries = 100; + + if (l<6 || memcmp(template+l-6, "XXXXXX", 6)) { + errno = EINVAL; + return 0; + } + + do { + __randname(template+l-6); + if (!mkdir(template, 0700)) return template; + } while (--retries && errno == EEXIST); + + memcpy(template+l-6, "XXXXXX", 6); + return 0; +} diff --git a/libc-top-half/musl/src/temp/mkostemp.c b/libc-top-half/musl/src/temp/mkostemp.c new file mode 100644 index 0000000..d8dcb80 --- /dev/null +++ b/libc-top-half/musl/src/temp/mkostemp.c @@ -0,0 +1,9 @@ +#define _BSD_SOURCE +#include + +int mkostemp(char *template, int flags) +{ + return __mkostemps(template, 0, flags); +} + +weak_alias(mkostemp, mkostemp64); diff --git a/libc-top-half/musl/src/temp/mkostemps.c b/libc-top-half/musl/src/temp/mkostemps.c new file mode 100644 index 0000000..ef24eea --- /dev/null +++ b/libc-top-half/musl/src/temp/mkostemps.c @@ -0,0 +1,29 @@ +#define _BSD_SOURCE +#include +#include +#include +#include +#include + +int __mkostemps(char *template, int len, int flags) +{ + size_t l = strlen(template); + if (l<6 || len>l-6 || memcmp(template+l-len-6, "XXXXXX", 6)) { + errno = EINVAL; + return -1; + } + + flags -= flags & O_ACCMODE; + int fd, retries = 100; + do { + __randname(template+l-len-6); + if ((fd = open(template, flags | O_RDWR | O_CREAT | O_EXCL, 0600))>=0) + return fd; + } while (--retries && errno == EEXIST); + + memcpy(template+l-len-6, "XXXXXX", 6); + return -1; +} + +weak_alias(__mkostemps, mkostemps); +weak_alias(__mkostemps, mkostemps64); diff --git a/libc-top-half/musl/src/temp/mkstemp.c b/libc-top-half/musl/src/temp/mkstemp.c new file mode 100644 index 0000000..166b8af --- /dev/null +++ b/libc-top-half/musl/src/temp/mkstemp.c @@ -0,0 +1,8 @@ +#include + +int mkstemp(char *template) +{ + return __mkostemps(template, 0, 0); +} + +weak_alias(mkstemp, mkstemp64); diff --git a/libc-top-half/musl/src/temp/mkstemps.c b/libc-top-half/musl/src/temp/mkstemps.c new file mode 100644 index 0000000..6b7531b --- /dev/null +++ b/libc-top-half/musl/src/temp/mkstemps.c @@ -0,0 +1,9 @@ +#define _BSD_SOURCE +#include + +int mkstemps(char *template, int len) +{ + return __mkostemps(template, len, 0); +} + +weak_alias(mkstemps, mkstemps64); diff --git a/libc-top-half/musl/src/temp/mktemp.c b/libc-top-half/musl/src/temp/mktemp.c new file mode 100644 index 0000000..7b3d264 --- /dev/null +++ b/libc-top-half/musl/src/temp/mktemp.c @@ -0,0 +1,30 @@ +#define _GNU_SOURCE +#include +#include +#include +#include + +char *mktemp(char *template) +{ + size_t l = strlen(template); + int retries = 100; + struct stat st; + + if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) { + errno = EINVAL; + *template = 0; + return template; + } + + do { + __randname(template+l-6); + if (stat(template, &st)) { + if (errno != ENOENT) *template = 0; + return template; + } + } while (--retries); + + *template = 0; + errno = EEXIST; + return template; +} -- cgit v1.2.3