diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-25 01:40:53 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-12-25 01:40:53 +0000 |
commit | 64211a0f98f77ad8284ccb8d3654cd3fba2198c8 (patch) | |
tree | dd9a8cda06cd151acada5a855369207a53162ac5 | |
parent | 4db0887d67dace8a8c57a44fd1437a320910982b (diff) | |
download | ruby-64211a0f98f77ad8284ccb8d3654cd3fba2198c8.tar.gz |
file.c: to_uid and to_gid
* file.c (to_uid, to_gid): extract from rb_file_s_chown,
rb_file_chown, and rb_file_s_lchown.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | file.c | 50 |
1 files changed, 24 insertions, 26 deletions
@@ -2219,6 +2219,24 @@ rb_file_s_lchmod(int argc, VALUE *argv) #define rb_file_s_lchmod rb_f_notimplement #endif +static inline rb_uid_t +to_uid(VALUE u) +{ + if (NIL_P(u)) { + return (rb_uid_t)-1; + } + return NUM2UIDT(u); +} + +static inline rb_gid_t +to_gid(VALUE g) +{ + if (NIL_P(g)) { + return (rb_gid_t)-1; + } + return NUM2GIDT(g); +} + struct chown_args { rb_uid_t owner; rb_gid_t group; @@ -2256,18 +2274,8 @@ rb_file_s_chown(int argc, VALUE *argv) rb_secure(2); rb_scan_args(argc, argv, "2*", &o, &g, &rest); - if (NIL_P(o)) { - arg.owner = -1; - } - else { - arg.owner = NUM2UIDT(o); - } - if (NIL_P(g)) { - arg.group = -1; - } - else { - arg.group = NUM2GIDT(g); - } + arg.owner = to_uid(o); + arg.group = to_gid(g); n = apply2files(chown_internal, rest, &arg); return LONG2FIX(n); @@ -2299,8 +2307,8 @@ rb_file_chown(VALUE obj, VALUE owner, VALUE group) #endif rb_secure(2); - o = NIL_P(owner) ? (rb_uid_t)-1 : NUM2UIDT(owner); - g = NIL_P(group) ? (rb_gid_t)-1 : NUM2GIDT(group); + o = to_uid(owner); + g = to_gid(group); GetOpenFile(obj, fptr); #ifndef HAVE_FCHOWN if (NIL_P(fptr->pathv)) return Qnil; @@ -2344,18 +2352,8 @@ rb_file_s_lchown(int argc, VALUE *argv) rb_secure(2); rb_scan_args(argc, argv, "2*", &o, &g, &rest); - if (NIL_P(o)) { - arg.owner = -1; - } - else { - arg.owner = NUM2UIDT(o); - } - if (NIL_P(g)) { - arg.group = -1; - } - else { - arg.group = NUM2GIDT(g); - } + arg.owner = to_uid(o); + arg.group = to_gid(g); n = apply2files(lchown_internal, rest, &arg); return LONG2FIX(n); |