projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix or1k atomic store
[musl]
/
src
/
temp
/
mktemp.c
diff --git
a/src/temp/mktemp.c
b/src/temp/mktemp.c
index
ed2c103
..
4ab0df2
100644
(file)
--- a/
src/temp/mktemp.c
+++ b/
src/temp/mktemp.c
@@
-1,29
+1,32
@@
+#define _GNU_SOURCE
#include <string.h>
#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
+#include <stdlib.h>
#include <errno.h>
#include <errno.h>
-#include
"libc.h"
+#include
<sys/stat.h>
char *__randname(char *);
char *__randname(char *);
-char *
__
mktemp(char *template)
+char *mktemp(char *template)
{
size_t l = strlen(template);
{
size_t l = strlen(template);
- int retries = 100
00
;
-
unsigned long r
;
+ int retries = 100;
+
struct stat st
;
- if (l < 6 ||
strcmp(template+l-6, "XXXXXX"
)) {
+ if (l < 6 ||
memcmp(template+l-6, "XXXXXX", 6
)) {
errno = EINVAL;
*template = 0;
return template;
}
errno = EINVAL;
*template = 0;
return template;
}
- while (retries--) {
+
+ do {
__randname(template+l-6);
__randname(template+l-6);
- if (access(template, F_OK) < 0) return template;
- }
+ if (stat(template, &st)) {
+ if (errno != ENOENT) *template = 0;
+ return template;
+ }
+ } while (--retries);
+
*template = 0;
errno = EEXIST;
return template;
}
*template = 0;
errno = EEXIST;
return template;
}
-
-weak_alias(__mktemp, mktemp);