mailing list of musl libc
 help / color / mirror / code / Atom feed
a22f69c3318462e9dc71720f7c781ed18e33dbe2 blob 780 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
36
37
38
39
40
 
#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"

void __randname(char *x6)
{
	size_t i = 0;
	struct timespec ts;
	clock_gettime(CLOCK_REALTIME, &ts);
	unsigned long r = ts.tv_nsec + (uintptr_t)&ts / 16 + (uintptr_t)x6;
	for (; i<6; i++, r>>=4) x6[i] = 'A'+(r&15);
}

char *__mktemp(char *template)
{
	int retries = 10000;
	size_t l = strlen(template);
	char *x6 = template +l -6;

	if(l < 6 || memcmp(x6, "XXXXXX", 6)) {
		errno = EINVAL;
		*template = 0;
		return template;
	}
	while (retries--) {
		__randname(x6);
		if (access(template, F_OK) < 0) return template;
	}
	*template = 0;
	errno = EEXIST;
	return template;
}

weak_alias(__mktemp, mktemp);
debug log:

solving a22f69c ...
found a22f69c in https://inbox.vuxu.org/musl/510D6E30.60206@barfooze.de/
found c0e06f5 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 c0e06f5ef424216c3b142999942b1146c801fa4d	src/temp/mktemp.c

applying [1/1] https://inbox.vuxu.org/musl/510D6E30.60206@barfooze.de/
diff --git a/src/temp/mktemp.c b/src/temp/mktemp.c
index c0e06f5..a22f69c 100644

Checking patch src/temp/mktemp.c...
Applied patch src/temp/mktemp.c cleanly.

index at:
100644 a22f69c3318462e9dc71720f7c781ed18e33dbe2	src/temp/mktemp.c

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).