mktemp.c\temp\src - musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/temp/mktemp.c
blob: 7b3d2648b20676eb25fd451ea26db93ef8ca8b65 (plain) (blame)
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
#define _GNU_SOURCE
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
char *mktemp(char *template)
{
	size_t l = strlen(template);
	int retries = 100;
	struct stat st;
	if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) {
		errno = EINVAL;
		*template = 0;
		return template;
	}
	do {
		__randname(template+l-6);
		if (stat(template, &st)) {
			if (errno != ENOENT) *template = 0;
			return template;
		}
	} while (--retries);
	*template = 0;
	errno = EEXIST;
	return template;
}
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月07日 07:23:38 +0000

AltStyle によって変換されたページ (->オリジナル) /