зеркало из https://github.com/github/ruby.git
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:
Родитель
cc3ec30ac9
Коммит
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
|
||||
rb_w32_ustati64() and rb_w32_stati64().
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#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)
|
|||
}
|
||||
|
||||
/* 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)
|
|||
}
|
||||
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;
|
||||
|
@ -4485,33 +4486,18 @@ rb_w32_ugetenv(const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
char *
|
||||
rb_w32_ugetenv(const char *name)
|
||||
{
|
||||
return w32_getenv(name, CP_UTF8);
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
char *
|
||||
rb_w32_getenv(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 NULL;
|
||||
return w32_getenv(name, CP_ACP);
|
||||
}
|
||||
|
||||
/* License: Artistic or GPL */
|
||||
|
|
Загрузка…
Ссылка в новой задаче