summaryrefslogtreecommitdiff
path: root/libc/stdlib/mktemp.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-05-14 04:16:35 +0000
committerErik Andersen <andersen@codepoet.org>2000-05-14 04:16:35 +0000
commit64bc6412188b141c010ac3b8e813b837dd991e80 (patch)
treeffa12b79ea4b13191754f54b872eb1a4f9e3a04b /libc/stdlib/mktemp.c
Initial revision
Diffstat (limited to 'libc/stdlib/mktemp.c')
-rw-r--r--libc/stdlib/mktemp.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/libc/stdlib/mktemp.c b/libc/stdlib/mktemp.c
new file mode 100644
index 000000000..08b356710
--- /dev/null
+++ b/libc/stdlib/mktemp.c
@@ -0,0 +1,40 @@
+
+#include <features.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+char * mktemp(template)
+char * template;
+{
+ int i;
+ int num; /* UNINITIALIZED */
+ int n2;
+ int l = strlen(template);
+ struct stat stbuf;
+
+ if (l<6) {
+ errno = EINVAL;
+ return 0;
+ }
+
+ for(i=l-6;i<l;i++)
+ if (template[i] != 'X') {
+ errno = EINVAL;
+ return 0;
+ }
+
+again:
+ n2 = num;
+ for(i=l-1;i>=l-6;i--) {
+ template[i] = '0' + n2 % 10;
+ n2 /= 10;
+ }
+
+ if (stat(template, &stbuf) == 0) {
+ num++;
+ goto again;
+ }
+
+ return template;
+}