summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-12 00:18:30 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-12 00:18:30 (GMT)
commitff5e3b98a0ff9563d49547d597d7d2b113fd0cec (patch)
treea19db9cc24e2103e07d5cc2f58a781108c7bc204 /win32/win32.c
parent5aff6f294821574e54f458d547cf9641dd2eca98 (diff)
win32.c: rb_dir_getwd_ospath
* win32/win32.c (rb_dir_getwd_ospath): Windows implementation moved from dir.c. get rid of freeing malloced memory by xfree. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59061 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/win32/win32.c b/win32/win32.c
index d10081b..a997cb3 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4656,7 +4656,7 @@ clock_getres(clockid_t clock_id, struct timespec *sp)
/* License: Ruby's */
static char *
-w32_getcwd(char *buffer, int size, UINT cp)
+w32_getcwd(char *buffer, int size, UINT cp, void *alloc(int, void *), void *arg)
{
WCHAR *p;
int wlen, len;
@@ -4687,7 +4687,7 @@ w32_getcwd(char *buffer, int size, UINT cp)
}
}
else {
- buffer = malloc(len);
+ buffer = (*alloc)(len, arg);
if (!buffer) {
errno = ENOMEM;
return NULL;
@@ -4699,17 +4699,42 @@ w32_getcwd(char *buffer, int size, UINT cp)
}
/* License: Ruby's */
+static void *
+getcwd_alloc(int size, void *dummy)
+{
+ return malloc(size);
+}
+
+/* License: Ruby's */
char *
rb_w32_getcwd(char *buffer, int size)
{
- return w32_getcwd(buffer, size, filecp());
+ return w32_getcwd(buffer, size, filecp(), getcwd_alloc, NULL);
}
/* License: Ruby's */
char *
rb_w32_ugetcwd(char *buffer, int size)
{
- return w32_getcwd(buffer, size, CP_UTF8);
+ return w32_getcwd(buffer, size, CP_UTF8, getcwd_alloc, NULL);
+}
+
+/* License: Ruby's */
+static void *
+getcwd_value(int size, void *arg)
+{
+ VALUE str = *(VALUE *)arg = rb_utf8_str_new(0, size - 1);
+ OBJ_TAINT(str);
+ return RSTRING_PTR(str);
+}
+
+/* License: Ruby's */
+VALUE
+rb_dir_getwd_ospath(void)
+{
+ VALUE cwd = Qnil;
+ w32_getcwd(NULL, 0, CP_UTF8, getcwd_value, &cwd);
+ return cwd;
}
/* License: Artistic or GPL */