mailing list of musl libc
 help / color / mirror / code / Atom feed
023ff422ad48553593222242dd7972b1cedd427d blob 1019 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "syscall.h"
#include "kstat.h"
#include "statx.h"

#define MAXTRIES 100

char *tempnam(const char *dir, const char *pfx)
{
	char s[PATH_MAX];
	size_t l, dl, pl;
	int try;
	int r;

	if (!dir) dir = P_tmpdir;
	if (!pfx) pfx = "temp";

	dl = strlen(dir);
	pl = strlen(pfx);
	l = dl + 1 + pl + 1 + 6;

	if (l >= PATH_MAX) {
		errno = ENAMETOOLONG;
		return 0;
	}

	memcpy(s, dir, dl);
	s[dl] = '/';
	memcpy(s+dl+1, pfx, pl);
	s[dl+1+pl] = '_';
	s[l] = 0;

	for (try=0; try<MAXTRIES; try++) {
		__randname(s+l-6);
#ifdef SYS_lstat
		r = __syscall(SYS_lstat, s, &(struct kstat){0});
#else
#ifdef SYS_fstatat
		r = __syscall(SYS_fstatat, AT_FDCWD, s,
			&(struct kstat){0}, AT_SYMLINK_NOFOLLOW);
#else
		r = __syscall(SYS_statx, AT_FDCWD, s, AT_SYMLINK_NOFOLLOW, 0,
			&(struct statx){0});
#endif
#endif
		if (r == -ENOENT) return strdup(s);
	}
	return 0;
}
debug log:

solving 023ff422 ...
found 023ff422 in https://inbox.vuxu.org/musl/20200903112309.102601-7-sorear@fastmail.com/
found 565df6b6 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 565df6b656a957d58694853b982dc1705cac424e	src/stdio/tempnam.c

applying [1/1] https://inbox.vuxu.org/musl/20200903112309.102601-7-sorear@fastmail.com/
diff --git a/src/stdio/tempnam.c b/src/stdio/tempnam.c
index 565df6b6..023ff422 100644

Checking patch src/stdio/tempnam.c...
Applied patch src/stdio/tempnam.c cleanly.

index at:
100644 023ff422ad48553593222242dd7972b1cedd427d	src/stdio/tempnam.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).