Feature #15797 » use-native-realpath-v4.patch
configure.ac | ||
---|---|---|
AC_CHECK_FUNCS(qsort_r)
|
||
AC_CHECK_FUNCS(qsort_s)
|
||
AC_CHECK_FUNCS(readlink)
|
||
AC_CHECK_FUNCS(realpath)
|
||
AC_CHECK_FUNCS(round)
|
||
AC_CHECK_FUNCS(sched_getaffinity)
|
||
AC_CHECK_FUNCS(seekdir)
|
file.c | ||
---|---|---|
#define rename(f, t) rb_w32_urename((f), (t))
|
||
#undef symlink
|
||
#define symlink(s, l) rb_w32_usymlink((s), (l))
|
||
#ifdef HAVE_REALPATH
|
||
/* Don't use native realpath(3) on Windows, as the check for
|
||
absolute paths does not work for drive letters. */
|
||
#undef HAVE_REALPATH
|
||
#endif
|
||
#else
|
||
#define STAT(p, s) stat((p), (s))
|
||
#endif
|
||
... | ... | |
# define UTIME_EINVAL
|
||
#endif
|
||
#ifdef HAVE_REALPATH
|
||
#if defined __OpenBSD__ || defined __FreeBSD__
|
||
#include <limits.h>
|
||
#include <stdlib.h>
|
||
/* Only use native realpath(3) for RB_REALPATH_DIR on FreeBSD and OpenBSD,
|
||
as these do not require that the last element of the path exists.
|
||
NetBSD started requiring the last element to exist in 2005. */
|
||
#define ALLOW_NATIVE_REALPATH_DIR 1
|
||
#endif
|
||
#endif
|
||
VALUE rb_cFile;
|
||
VALUE rb_mFileTest;
|
||
VALUE rb_cStat;
|
||
... | ... | |
RB_REALPATH_MODE_MAX
|
||
};
|
||
#if !defined(HAVE_REALPATH) || !defined(ALLOW_NATIVE_REALPATH_DIR)
|
||
static int
|
||
realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE fallback,
|
||
VALUE loopcheck, enum rb_realpath_mode mode, int last)
|
||
... | ... | |
}
|
||
return 0;
|
||
}
|
||
#endif
|
||
static VALUE rb_file_join(VALUE ary);
|
||
static VALUE
|
||
rb_check_realpath_internal(VALUE basedir, VALUE path, enum rb_realpath_mode mode)
|
||
{
|
||
#if defined(HAVE_REALPATH) && !defined(ALLOW_NATIVE_REALPATH_DIR)
|
||
if (mode != RB_REALPATH_DIR) {
|
||
#endif
|
||
#ifdef HAVE_REALPATH
|
||
VALUE unresolved_path;
|
||
rb_encoding *origenc;
|
||
char *resolved_ptr = NULL;
|
||
VALUE resolved;
|
||
unresolved_path = rb_str_dup_frozen(path);
|
||
origenc = rb_enc_get(unresolved_path);
|
||
if (*RSTRING_PTR(unresolved_path) != '/' && !NIL_P(basedir)) {
|
||
unresolved_path = rb_file_join(rb_ary_new_from_args(2, basedir, unresolved_path));
|
||
}
|
||
unresolved_path = TO_OSPATH(unresolved_path);
|
||
if((resolved_ptr = realpath(RSTRING_PTR(unresolved_path), NULL)) == NULL) {
|
||
if (mode == RB_REALPATH_CHECK) {
|
||
return Qnil;
|
||
}
|
||
rb_sys_fail_path(unresolved_path);
|
||
}
|
||
resolved = rb_enc_str_new_cstr(resolved_ptr, origenc);
|
||
free(resolved_ptr);
|
||
if (mode == RB_REALPATH_STRICT || mode == RB_REALPATH_CHECK) {
|
||
struct stat st;
|
||
if (rb_stat(resolved, &st) < 0) {
|
||
if (mode == RB_REALPATH_STRICT) {
|
||
rb_sys_fail_path(unresolved_path);
|
||
}
|
||
return Qnil;
|
||
}
|
||
}
|
||
if(rb_enc_str_coderange(resolved) == ENC_CODERANGE_BROKEN) {
|
||
rb_enc_associate(resolved, rb_ascii8bit_encoding());
|
||
}
|
||
rb_obj_taint(resolved);
|
||
RB_GC_GUARD(unresolved_path);
|
||
return resolved;
|
||
#endif
|
||
#if defined(HAVE_REALPATH) && !defined(ALLOW_NATIVE_REALPATH_DIR)
|
||
} else {
|
||
#endif
|
||
#if !defined(HAVE_REALPATH) || !defined(ALLOW_NATIVE_REALPATH_DIR)
|
||
long prefixlen;
|
||
VALUE resolved;
|
||
VALUE unresolved_path;
|
||
... | ... | |
RB_GC_GUARD(unresolved_path);
|
||
RB_GC_GUARD(curdir);
|
||
return resolved;
|
||
#endif
|
||
#if defined(HAVE_REALPATH) && !defined(ALLOW_NATIVE_REALPATH_DIR)
|
||
}
|
||
#endif
|
||
}
|
||
VALUE
|
||
... | ... | |
return rb_assoc_new(rb_file_dirname(path), rb_file_s_basename(1,&path));
|
||
}
|
||
static VALUE rb_file_join(VALUE ary);
|
||
static VALUE
|
||
file_inspect_join(VALUE ary, VALUE arg, int recur)
|
||
{
|
- « Previous
- 1
- 2
- 3
- 4
- Next »