Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1176)

Unified Diff: fusl/src/temp/mktemp.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/temp/mkstemps.c ('k') | fusl/src/termios/cfgetospeed.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/temp/mktemp.c
diff --git a/fusl/src/temp/mktemp.c b/fusl/src/temp/mktemp.c
new file mode 100644
index 0000000000000000000000000000000000000000..4ab0df2069ac6d0c685ea2265f15d40596392217
--- /dev/null
+++ b/fusl/src/temp/mktemp.c
@@ -0,0 +1,32 @@
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+char *__randname(char *);
+
+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;
+}
« no previous file with comments | « fusl/src/temp/mkstemps.c ('k') | fusl/src/termios/cfgetospeed.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698