[前][次][番号順一覧][スレッド一覧]

ruby-changes:29652

From: nobu <ko1@a...>
Date: Sun, 30 Jun 2013 10:59:16 +0900 (JST)
Subject: [ruby-changes:29652] nobu:r41704 (trunk): win32.c: w32_getenv

nobu	2013-06-30 10:58:59 +0900 (Sun, 30 Jun 2013)

  New Revision: 41704

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41704

  Log:
    win32.c: w32_getenv
    
    * win32/win32.c (w32_getenv): extract codepage aware code from
      rb_w32_ugetenv() and rb_w32_getenv().

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41703)
+++ ChangeLog	(revision 41704)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Sun Jun 30 10:58:53 2013  Nobuyoshi Nakada  <nobu@r...>
+Sun Jun 30 10:58:57 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (w32_getenv): extract codepage aware code from
+	  rb_w32_ugetenv() and rb_w32_getenv().
 
 	* win32/win32.c (w32_stati64): extract codepage aware code from
 	  rb_w32_ustati64() and rb_w32_stati64().
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 41703)
+++ win32/win32.c	(revision 41704)
@@ -50,6 +50,7 @@ https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L50
 #define isdirsep(x) ((x) == '/' || (x) == '\\')
 
 static int w32_stati64(const char *path, struct stati64 *st, UINT cp);
+static char *w32_getenv(const char *name, UINT cp);
 
 #undef stat
 #undef fclose
@@ -4448,8 +4449,8 @@ wait(int *status) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4449
 }
 
 /* License: Ruby's */
-char *
-rb_w32_ugetenv(const char *name)
+static char *
+w32_getenv(const char *name, UINT cp)
 {
     WCHAR *wenvarea, *wenv;
     int len = strlen(name);
@@ -4473,7 +4474,7 @@ rb_w32_ugetenv(const char *name) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4474
     }
     for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1)
 	wlen += lstrlenW(wenv) + 1;
-    uenvarea = wstr_to_mbstr(CP_UTF8, wenvarea, wlen, NULL);
+    uenvarea = wstr_to_mbstr(cp, wenvarea, wlen, NULL);
     FreeEnvironmentStringsW(wenvarea);
     if (!uenvarea)
 	return NULL;
@@ -4487,31 +4488,16 @@ rb_w32_ugetenv(const char *name) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4488
 
 /* License: Ruby's */
 char *
-rb_w32_getenv(const char *name)
+rb_w32_ugetenv(const char *name)
 {
-    int len = strlen(name);
-    char *env;
-
-    if (len == 0) return NULL;
-    if (uenvarea) {
-	free(uenvarea);
-	uenvarea = NULL;
-    }
-    if (envarea) {
-	FreeEnvironmentStrings(envarea);
-	envarea = NULL;
-    }
-    envarea = GetEnvironmentStrings();
-    if (!envarea) {
-	map_errno(GetLastError());
-	return NULL;
-    }
-
-    for (env = envarea; *env; env += strlen(env) + 1)
-	if (strncasecmp(env, name, len) == 0 && *(env + len) == '=')
-	    return env + len + 1;
+    return w32_getenv(name, CP_UTF8);
+}
 
-    return NULL;
+/* License: Ruby's */
+char *
+rb_w32_getenv(const char *name)
+{
+    return w32_getenv(name, CP_ACP);
 }
 
 /* License: Artistic or GPL */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]