summaryrefslogtreecommitdiff
path: root/src/temp/__randname.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-02-20 22:43:23 -0500
committerRich Felker <dalias@aerifal.cx>2013-02-20 22:43:23 -0500
commit2cc63358cdb0309ca996ffe56ccf402c2f2f16d5 (patch)
tree067001fb5f1a5a09de6d8417c5d1d80249e382ce /src/temp/__randname.c
parentf78cdbe8993d072bf60a65754544199016a1fe29 (diff)
downloadmusl-2cc63358cdb0309ca996ffe56ccf402c2f2f16d5.tar.gz
add mkostemp, mkstemps, and mkostemps functions and reorganize temp internals
based on patch contributed by Anthony G. Basile (blueness) some issues remain with the filename generation algorithm and other small bugs, but this patch has been sitting around long enough that I feel it's best to get it committed and then work out any remaining issues.
Diffstat (limited to 'src/temp/__randname.c')
-rw-r--r--src/temp/__randname.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/temp/__randname.c b/src/temp/__randname.c
new file mode 100644
index 00000000..b097576d
--- /dev/null
+++ b/src/temp/__randname.c
@@ -0,0 +1,21 @@
+#include <string.h>
+#include <time.h>
+#include <stdint.h>
+
+int __clock_gettime(clockid_t, struct timespec *);
+
+/* This assumes that a check for the
+ template size has alrady 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;
+}