ruby-changes:30297
From: nobu <ko1@a...>
Date: Sat, 3 Aug 2013 09:46:27 +0900 (JST)
Subject: [ruby-changes:30297] nobu:r42349 (trunk): etc.c: encodings
nobu 2013-08-03 09:46:10 +0900 (Sat, 03 Aug 2013) New Revision: 42349 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42349 Log: etc.c: encodings * ext/etc/etc.c (setup_passwd, setup_group): set proper encodings to string members. Modified files: trunk/ChangeLog trunk/ext/etc/etc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42348) +++ ChangeLog (revision 42349) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Aug 3 09:46:07 2013 Nobuyoshi Nakada <nobu@r...> + + * ext/etc/etc.c (setup_passwd, setup_group): set proper encodings to + string members. + Sat Aug 3 09:30:57 2013 Nobuyoshi Nakada <nobu@r...> * struct.c (rb_struct_define_under): new function to define Struct Index: ext/etc/etc.c =================================================================== --- ext/etc/etc.c (revision 42348) +++ ext/etc/etc.c (revision 42349) @@ -79,6 +79,20 @@ safe_setup_str(const char *str) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L79 if (str == 0) str = ""; return rb_tainted_str_new2(str); } + +static VALUE +safe_setup_locale_str(const char *str) +{ + if (str == 0) str = ""; + return rb_locale_str_new_cstr(str); +} + +static VALUE +safe_setup_filesystem_str(const char *str) +{ + if (str == 0) str = ""; + return rb_filesystem_str_new_cstr(str); +} #endif #ifdef HAVE_GETPWENT @@ -87,17 +101,17 @@ setup_passwd(struct passwd *pwd) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L101 { if (pwd == 0) rb_sys_fail("/etc/passwd"); return rb_struct_new(sPasswd, - safe_setup_str(pwd->pw_name), + safe_setup_locale_str(pwd->pw_name), #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD safe_setup_str(pwd->pw_passwd), #endif UIDT2NUM(pwd->pw_uid), GIDT2NUM(pwd->pw_gid), #ifdef HAVE_STRUCT_PASSWD_PW_GECOS - safe_setup_str(pwd->pw_gecos), + safe_setup_locale_str(pwd->pw_gecos), #endif - safe_setup_str(pwd->pw_dir), - safe_setup_str(pwd->pw_shell), + safe_setup_filesystem_str(pwd->pw_dir), + safe_setup_filesystem_str(pwd->pw_shell), #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE INT2NUM(pwd->pw_change), #endif @@ -108,10 +122,10 @@ setup_passwd(struct passwd *pwd) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L122 PW_AGE2VAL(pwd->pw_age), #endif #ifdef HAVE_STRUCT_PASSWD_PW_CLASS - safe_setup_str(pwd->pw_class), + safe_setup_locale_str(pwd->pw_class), #endif #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT - safe_setup_str(pwd->pw_comment), + safe_setup_locale_str(pwd->pw_comment), #endif #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE INT2NUM(pwd->pw_expire), @@ -351,11 +365,11 @@ setup_group(struct group *grp) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L365 mem = rb_ary_new(); tbl = grp->gr_mem; while (*tbl) { - rb_ary_push(mem, safe_setup_str(*tbl)); + rb_ary_push(mem, safe_setup_locale_str(*tbl)); tbl++; } return rb_struct_new(sGroup, - safe_setup_str(grp->gr_name), + safe_setup_locale_str(grp->gr_name), #ifdef HAVE_STRUCT_GROUP_GR_PASSWD safe_setup_str(grp->gr_passwd), #endif -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/