summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-05-01 08:56:45 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-05-01 08:56:45 +0000
commit53118356b53259b456aabc11fb1212d965251fc4 (patch)
treecfa16b2fa793fb9a4691f21bd028a0170a598cff /util.c
parent896c0dff6330d461ce428d61df0f60fb8bad07a7 (diff)
exception model changed
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/util.c b/util.c
index 527ce87d03..8dea777ffa 100644
--- a/util.c
+++ b/util.c
@@ -86,6 +86,47 @@ int *retlen;
return retval;
}
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifndef S_ISDIR
+# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
+#endif
+
+static char *
+check_dir(dir)
+ char *dir;
+{
+ struct stat st;
+
+ if (dir == NULL) return NULL;
+ if (stat(dir, &st) < 0) return NULL;
+ if (!S_ISDIR(st.st_mode)) return NULL;
+ if (eaccess(dir, W_OK) < 0) return NULL;
+ return dir;
+}
+
+char *
+ruby_mktemp()
+{
+ char *dir;
+ char *buf;
+
+ dir = check_dir(getenv("TMP"));
+ if (!dir) dir = check_dir(getenv("TMPDIR"));
+ if (!dir) dir = "/tmp";
+
+ buf = ALLOC_N(char,strlen(dir)+10);
+ sprintf(buf, "%s/rbXXXXXX", dir);
+ dir = mktemp(buf);
+ if (dir == NULL) free(buf);
+
+ return dir;
+}
+
#if defined(MSDOS) || defined(__CYGWIN32__) || defined(NT)
#include <fcntl.h>
/*
@@ -267,7 +308,6 @@ valid_filename(char *s)
#include <go32.h>
#include <dpmi.h> /* For dpmisim */
#include <crt0.h> /* For crt0 flags */
-#include <sys/stat.h>
#include <libc/dosio.h>
static unsigned use_lfn;