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
This commit is contained in:
parent
4651988d41
commit
a8c03c45c4
43
mjit.c
43
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");
|
||||
|
|
Loading…
Reference in New Issue