add mkostemp, mkstemps, and mkostemps functions and reorganize temp internals
[musl] / src / temp / __randname.c
1 #include <string.h>
2 #include <time.h>
3 #include <stdint.h>
4
5 int __clock_gettime(clockid_t, struct timespec *);
6
7 /* This assumes that a check for the
8    template size has alrady been made */
9 char *__randname(char *template)
10 {
11         int i;
12         struct timespec ts;
13         unsigned long r;
14
15         __clock_gettime(CLOCK_REALTIME, &ts);
16         r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template;
17         for (i=0; i<6; i++, r>>=5)
18                 template[i] = 'A'+(r&15)+(r&16)*2;
19
20         return template;
21 }