summaryrefslogtreecommitdiff
path: root/pith/osdep
diff options
context:
space:
mode:
Diffstat (limited to 'pith/osdep')
-rw-r--r--pith/osdep/creatdir.c42
-rw-r--r--pith/osdep/creatdir.h2
2 files changed, 43 insertions, 1 deletions
diff --git a/pith/osdep/creatdir.c b/pith/osdep/creatdir.c
index 76a854a6..56ee4a75 100644
--- a/pith/osdep/creatdir.c
+++ b/pith/osdep/creatdir.c
@@ -53,3 +53,45 @@ create_mail_dir(char *dir)
return(0);
}
+
+
+/*----------------------------------------------------------------------
+ Create random directory
+
+ Args: dir -- Name of the directory that contains the random directory
+ len -- size of dir.
+
+ Result: Directory is created. Returns 0 on success, else -1 on error
+ and errno is valid.
+ ----*/
+int
+create_random_dir(char *dir, size_t len)
+{
+ size_t olen, dlen = strlen(dir);
+
+ olen = dlen; /* save original length */
+
+ if(dir[dlen-1] != C_FILESEP){
+ dir[dlen++] = C_FILESEP;
+ dir[dlen] = '\0';
+ }
+
+ if(dlen + 6 < len)
+ strcat(dir, "XXXXXX");
+ else{
+ dir[olen] = '\0';
+ return -1;
+ }
+
+#ifndef _WINDOWS
+ dir = mkdtemp(dir);
+ our_chmod(dir, MAILDIR_MODE);
+
+ /* Some systems need this, on others we don't care if it fails */
+ our_chown(dir, getuid(), getgid());
+#else
+ dir = _mktemp(dir);
+#endif /* !_WINDOWS */
+
+ return(0);
+}
diff --git a/pith/osdep/creatdir.h b/pith/osdep/creatdir.h
index e9d844e7..8ad6eeb5 100644
--- a/pith/osdep/creatdir.h
+++ b/pith/osdep/creatdir.h
@@ -22,6 +22,6 @@
* Exported Prototypes
*/
int create_mail_dir(char *);
-
+int create_random_dir(char *, size_t);
#endif /* PITH_OSDEP_CREATDIR_INCLUDED */