Hi,

At Fri, 8 Aug 2003 13:23:23 +0900,
Park Heesob wrote:
> It's due to the Unicode Conversion problem.
> 
> Try with following code.

But it would spoil portability.  Etc module should support it.

I'm not sure if this works or even compiles.


Index: ext/etc/etc.c =================================================================== RCS file: /cvs/ruby/src/ruby/ext/etc/etc.c,v retrieving revision 1.11 diff -u -2 -p -r1.11 etc.c --- ext/etc/etc.c 31 Jul 2003 14:03:34 -0000 1.11 +++ ext/etc/etc.c 8 Aug 2003 04:49:59 -0000 @@ -24,4 +24,9 @@ #endif +#if defined(_WIN32) && !defined(__CYGWIN__) +#include <lm.h> +#define HAVE_ST_PW_COMMENT 1 +#endif + static VALUE sPasswd, sGroup; @@ -126,5 +131,30 @@ etc_getpwnam(obj, nam) if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING(nam)->ptr); return setup_passwd(pwd); -#else +#elif defined(_WIN32) + DWORD level = 10; + DWORD w2mflag = WC_DISCARDNS|WC_SEPCHARS|WC_DEFAULTCHAR|WC_COMPOSITECHECK; + LPUSER_INFO_10 buf = NULL; + char* cname = StringValueCPtr(name); + int len = strlen(cname) + 1; + wchar_t *wname = ALLOCA_N(wchar_t, len); + struct passwd pwd; + + if (!MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, cname, len, wname, len) || + NetUserGetInfo(NULL, wname, level, (LPBYTE *)&buf) != NERR_Success) { + rb_raise(rb_eArgError, "can't find user for %s", cname); + } + MEMZERO(&pwd, struct passwd, 1); +#define COPY2PWD(w, s) do { \ + len = WideCharToMultiByte(CP_OEMCP, w2mflag, buf->w, NULL, 0, NULL, NULL); \ + pwd.s = ALLOCA_N(char, len + 1); \ + WideCharToMultiByte(CP_OEMCP, w2mflag, buf->w, pwd.s, len, NULL, NULL); \ +} while (0) + COPY2PWD(usri10_name, pw_name); + COPY2PWD(usri10_comment, pw_comment); + if (buf) { + NetApiBufferFree(buf); + } + return setup_passwd(&pwd); +#else return Qnil; #endif
-- Nobu Nakada