mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
etc.c: encodings
* ext/etc/etc.c (setup_passwd, setup_group): set proper encodings to string members. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
042e5013a3
commit
4c00941411
2 changed files with 27 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Aug 3 09:46:07 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/etc/etc.c (setup_passwd, setup_group): set proper encodings to
|
||||||
|
string members.
|
||||||
|
|
||||||
Sat Aug 3 09:30:57 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Aug 3 09:30:57 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* struct.c (rb_struct_define_under): new function to define Struct
|
* struct.c (rb_struct_define_under): new function to define Struct
|
||||||
|
|
|
@ -79,6 +79,20 @@ safe_setup_str(const char *str)
|
||||||
if (str == 0) str = "";
|
if (str == 0) str = "";
|
||||||
return rb_tainted_str_new2(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
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GETPWENT
|
#ifdef HAVE_GETPWENT
|
||||||
|
@ -87,17 +101,17 @@ setup_passwd(struct passwd *pwd)
|
||||||
{
|
{
|
||||||
if (pwd == 0) rb_sys_fail("/etc/passwd");
|
if (pwd == 0) rb_sys_fail("/etc/passwd");
|
||||||
return rb_struct_new(sPasswd,
|
return rb_struct_new(sPasswd,
|
||||||
safe_setup_str(pwd->pw_name),
|
safe_setup_locale_str(pwd->pw_name),
|
||||||
#ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
|
#ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
|
||||||
safe_setup_str(pwd->pw_passwd),
|
safe_setup_str(pwd->pw_passwd),
|
||||||
#endif
|
#endif
|
||||||
UIDT2NUM(pwd->pw_uid),
|
UIDT2NUM(pwd->pw_uid),
|
||||||
GIDT2NUM(pwd->pw_gid),
|
GIDT2NUM(pwd->pw_gid),
|
||||||
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS
|
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS
|
||||||
safe_setup_str(pwd->pw_gecos),
|
safe_setup_locale_str(pwd->pw_gecos),
|
||||||
#endif
|
#endif
|
||||||
safe_setup_str(pwd->pw_dir),
|
safe_setup_filesystem_str(pwd->pw_dir),
|
||||||
safe_setup_str(pwd->pw_shell),
|
safe_setup_filesystem_str(pwd->pw_shell),
|
||||||
#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
|
#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
|
||||||
INT2NUM(pwd->pw_change),
|
INT2NUM(pwd->pw_change),
|
||||||
#endif
|
#endif
|
||||||
|
@ -108,10 +122,10 @@ setup_passwd(struct passwd *pwd)
|
||||||
PW_AGE2VAL(pwd->pw_age),
|
PW_AGE2VAL(pwd->pw_age),
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
|
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
|
||||||
safe_setup_str(pwd->pw_class),
|
safe_setup_locale_str(pwd->pw_class),
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
|
#ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
|
||||||
safe_setup_str(pwd->pw_comment),
|
safe_setup_locale_str(pwd->pw_comment),
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
|
#ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
|
||||||
INT2NUM(pwd->pw_expire),
|
INT2NUM(pwd->pw_expire),
|
||||||
|
@ -351,11 +365,11 @@ setup_group(struct group *grp)
|
||||||
mem = rb_ary_new();
|
mem = rb_ary_new();
|
||||||
tbl = grp->gr_mem;
|
tbl = grp->gr_mem;
|
||||||
while (*tbl) {
|
while (*tbl) {
|
||||||
rb_ary_push(mem, safe_setup_str(*tbl));
|
rb_ary_push(mem, safe_setup_locale_str(*tbl));
|
||||||
tbl++;
|
tbl++;
|
||||||
}
|
}
|
||||||
return rb_struct_new(sGroup,
|
return rb_struct_new(sGroup,
|
||||||
safe_setup_str(grp->gr_name),
|
safe_setup_locale_str(grp->gr_name),
|
||||||
#ifdef HAVE_STRUCT_GROUP_GR_PASSWD
|
#ifdef HAVE_STRUCT_GROUP_GR_PASSWD
|
||||||
safe_setup_str(grp->gr_passwd),
|
safe_setup_str(grp->gr_passwd),
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue