#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "debug.h"
#include "file.h"
+#define TLEN 8
+
/* read full file */
int readfile (char **buffer, char *filename)
return size;
}
+/* temp name */
+
+char *tempname (char *tempdir)
+{
+ char table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
+
+ unsigned int len = strlen (tempdir) + 1 + 4 + TLEN + 1;
+ char *name = (char *) calloc (len, 1);
+
+ sprintf (name, "%s/tmp-", tempdir);
+ while (strlen (name) + 1 < len) {
+ name[strlen (name)] = table[rand () % 64];
+ }
+
+ return name;
+}
+
/* vim: set ts=4 sw=4 et: */