mailing list of musl libc
 help / color / mirror / code / Atom feed
c0e06f5ef424216c3b142999942b1146c801fa4d blob 727 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
#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 "libc.h"

char *__mktemp(char *template)
{
	struct timespec ts;
	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--) {
		clock_gettime(CLOCK_REALTIME, &ts);
		r = ts.tv_nsec + (uintptr_t)&ts / 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);
debug log:

solving c0e06f5 ...
found c0e06f5 in https://git.vuxu.org/mirror/musl/

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).