ruby-changes:37982
From: nobu <ko1@a...>
Date: Mon, 23 Mar 2015 21:22:41 +0900 (JST)
Subject: [ruby-changes:37982] nobu:r50063 (trunk): file.c: move rb_readlink on Windows
nobu 2015-03-23 21:22:10 +0900 (Mon, 23 Mar 2015) New Revision: 50063 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50063 Log: file.c: move rb_readlink on Windows * win32/file.c (rb_readlink): move from file.c for better buffer allocation and the result encoding. Modified files: trunk/ChangeLog trunk/file.c trunk/win32/file.c Index: ChangeLog =================================================================== --- ChangeLog (revision 50062) +++ ChangeLog (revision 50063) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Mon Mar 23 17:36:00 2015 Nobuyoshi Nakada <nobu@r...> +Mon Mar 23 21:22:07 2015 Nobuyoshi Nakada <nobu@r...> + + * win32/file.c (rb_readlink): move from file.c for better buffer + allocation and the result encoding. * win32/win32.c (wreadlink, rb_w32_ureadlink): implement readlink(). Index: win32/file.c =================================================================== --- win32/file.c (revision 50062) +++ win32/file.c (revision 50063) @@ -653,6 +653,35 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L653 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) { Index: file.c =================================================================== --- file.c (revision 50062) +++ file.c (revision 50063) @@ -2790,6 +2790,7 @@ rb_file_s_readlink(VALUE klass, VALUE pa https://github.com/ruby/ruby/blob/trunk/file.c#L2790 return rb_readlink(path); } +#ifndef _WIN32 VALUE rb_readlink(VALUE path) { @@ -2818,6 +2819,7 @@ rb_readlink(VALUE path) https://github.com/ruby/ruby/blob/trunk/file.c#L2819 return v; } +#endif #else #define rb_file_s_readlink rb_f_notimplement #endif -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/