summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-23 12:22:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-23 12:22:10 +0000
commit2ffb87995a33cdc7ba609a4b867f03f18da0c3b3 (patch)
treeb5d86908fb6ab1ea7dda7266bb97cee14b969dec /win32
parentc57932f782ba03b3aab667a877c5b6143b214d26 (diff)
file.c: move rb_readlink on Windows
* win32/file.c (rb_readlink): move from file.c for better buffer allocation and the result encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/file.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/win32/file.c b/win32/file.c
index 1884f2a..0f5b285 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -653,6 +653,35 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
return result;
}
+ssize_t rb_w32_wreadlink(const WCHAR *path, WCHAR *buf, size_t bufsize);
+
+VALUE
+rb_readlink(VALUE path)
+{
+ ssize_t len;
+ WCHAR *wpath, wbuf[MAX_PATH];
+ rb_encoding *enc;
+ UINT cp, path_cp;
+
+ rb_secure(2);
+ FilePathValue(path);
+ enc = rb_enc_get(path);
+ cp = path_cp = code_page(enc);
+ if (cp == INVALID_CODE_PAGE) {
+ path = fix_string_encoding(path, enc);
+ cp = CP_UTF8;
+ }
+ wpath = mbstr_to_wstr(cp, RSTRING_PTR(path), RSTRING_LEN(path), NULL);
+ if (!wpath) rb_memerror();
+ len = rb_w32_wreadlink(wpath, wbuf, numberof(wbuf));
+ free(wpath);
+ if (len < 0) rb_sys_fail_path(path);
+ enc = rb_filesystem_encoding();
+ cp = path_cp = code_page(enc);
+ if (cp == INVALID_CODE_PAGE) cp = CP_UTF8;
+ return append_wstr(rb_enc_str_new(0, 0, enc), wbuf, len, cp, path_cp, enc);
+}
+
int
rb_file_load_ok(const char *path)
{