win32.c: w32_getenv
* win32/win32.c (w32_getenv): extract codepage aware code from rb_w32_ugetenv() and rb_w32_getenv(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cc3ec30ac9
commit
a65261c2c1
@ -1,4 +1,7 @@
|
|||||||
Sun Jun 30 10:58:53 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun Jun 30 10:58:57 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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
|
* win32/win32.c (w32_stati64): extract codepage aware code from
|
||||||
rb_w32_ustati64() and rb_w32_stati64().
|
rb_w32_ustati64() and rb_w32_stati64().
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
#define isdirsep(x) ((x) == '/' || (x) == '\\')
|
||||||
|
|
||||||
static int w32_stati64(const char *path, struct stati64 *st, UINT cp);
|
static int w32_stati64(const char *path, struct stati64 *st, UINT cp);
|
||||||
|
static char *w32_getenv(const char *name, UINT cp);
|
||||||
|
|
||||||
#undef stat
|
#undef stat
|
||||||
#undef fclose
|
#undef fclose
|
||||||
@ -4448,8 +4449,8 @@ wait(int *status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* License: Ruby's */
|
/* License: Ruby's */
|
||||||
char *
|
static char *
|
||||||
rb_w32_ugetenv(const char *name)
|
w32_getenv(const char *name, UINT cp)
|
||||||
{
|
{
|
||||||
WCHAR *wenvarea, *wenv;
|
WCHAR *wenvarea, *wenv;
|
||||||
int len = strlen(name);
|
int len = strlen(name);
|
||||||
@ -4473,7 +4474,7 @@ rb_w32_ugetenv(const char *name)
|
|||||||
}
|
}
|
||||||
for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1)
|
for (wenv = wenvarea, wlen = 1; *wenv; wenv += lstrlenW(wenv) + 1)
|
||||||
wlen += 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);
|
FreeEnvironmentStringsW(wenvarea);
|
||||||
if (!uenvarea)
|
if (!uenvarea)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -4485,33 +4486,18 @@ rb_w32_ugetenv(const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* License: Ruby's */
|
||||||
|
char *
|
||||||
|
rb_w32_ugetenv(const char *name)
|
||||||
|
{
|
||||||
|
return w32_getenv(name, CP_UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
/* License: Ruby's */
|
/* License: Ruby's */
|
||||||
char *
|
char *
|
||||||
rb_w32_getenv(const char *name)
|
rb_w32_getenv(const char *name)
|
||||||
{
|
{
|
||||||
int len = strlen(name);
|
return w32_getenv(name, CP_ACP);
|
||||||
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 NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* License: Artistic or GPL */
|
/* License: Artistic or GPL */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user