chown(p1, p2)
public
Changes the owner and group of file to the given numeric owner and
group id’s. Only a process with superuser privileges may change the owner
of a file. The current owner of a file may change the file’s group to any
group to which the owner belongs. A nil or -1 owner or group id is ignored.
Follows symbolic links. See also File#lchown.
File.new("testfile").chown(502, 1000)
Show source
static VALUE
rb_file_chown(VALUE obj, VALUE owner, VALUE group)
{
rb_io_t *fptr;
int o, g;
VALUE path;
rb_secure(2);
o = NIL_P(owner) ? -1 : NUM2INT(owner);
g = NIL_P(group) ? -1 : NUM2INT(group);
GetOpenFile(obj, fptr);
if (NIL_P(fptr->pathv)) return Qnil;
path = rb_str_encode_ospath(fptr->pathv);
if (chown(RSTRING_PTR(path), o, g) == -1)
rb_sys_fail_path(fptr->pathv);
if (fchown(fptr->fd, o, g) == -1)
rb_sys_fail_path(fptr->pathv);
return INT2FIX(0);
}