summaryrefslogtreecommitdiff
path: root/mjit.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-07 13:41:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-07 13:41:32 +0000
commita8c03c45c491d7fd70e845ef83eedf198722fe9c (patch)
treee6dfe794a184f8366e36d174cdc00bb63cddc9c3 /mjit.c
parent4651988d414e19af88c39c8591d475601231c4ab (diff)
mjit.c: system_tmpdir
* mjit.c (system_tmpdir): use system provided temporary directory, and TMPDIR as well as mktemp(1), before TMP and "/tmp". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'mjit.c')
-rw-r--r--mjit.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/mjit.c b/mjit.c
index ac76121de4..499af8d000 100644
--- a/mjit.c
+++ b/mjit.c
@@ -1197,6 +1197,42 @@ valid_class_serials_add_i(ID key, VALUE v, void *unused)
return ID_TABLE_CONTINUE;
}
+static char *
+system_tmpdir(void)
+{
+ char *tmpdir;
+ /* c.f. ext/etc/etc.c:etc_systmpdir() */
+#ifdef _WIN32
+ WCHAR tmppath[_MAX_PATH];
+ UINT len = rb_w32_system_tmpdir(tmppath, numberof(tmppath));
+ if (len) {
+ tmpdir = rb_w32_wstr_to_mbstr(CP_UTF8, tmppath, -1, NULL);
+ return get_string(tmpdir);
+ }
+#elif defined _CS_DARWIN_USER_TEMP_DIR
+ #ifndef MAXPATHLEN
+ #define MAXPATHLEN 1024
+ #endif
+ char path[MAXPATHLEN];
+ size_t len = confstr(_CS_DARWIN_USER_TEMP_DIR, path, sizeof(path));
+ if (len > 0) {
+ tmpdir = xmalloc(len);
+ if (len > sizeof(path)) {
+ confstr(_CS_DARWIN_USER_TEMP_DIR, tmpdir, len);
+ }
+ else {
+ memcpy(tmpdir, path, len);
+ }
+ return tmpdir;
+ }
+#endif
+ if (!(tmpdir = getenv("TMPDIR")) &&
+ !(tmpdir = getenv("TMP"))) {
+ tmpdir = "/tmp";
+ }
+ return get_string(tmpdir);
+}
+
/* Default permitted number of units with a JIT code kept in
memory. */
#define DEFAULT_CACHE_SIZE 1000
@@ -1248,12 +1284,7 @@ mjit_init(struct mjit_options *opts)
}
#endif
- if (getenv("TMP") != NULL) { /* For MinGW */
- tmp_dir = get_string(getenv("TMP"));
- }
- else {
- tmp_dir = get_string("/tmp");
- }
+ tmp_dir = system_tmpdir();
init_header_filename();
pch_file = get_uniq_filename(0, MJIT_TMP_PREFIX "h", ".h.gch");