chmod(p1)
public
Changes permission bits on file to the bit pattern represented by
mode_int. Actual effects are platform dependent; on Unix systems,
see chmod(2) for details. Follows symbolic
links. Also see File#lchmod.
f = File.new("out", "w");
f.chmod(0644)
Show source
static VALUE
rb_file_chmod(VALUE obj, VALUE vmode)
{
rb_io_t *fptr;
int mode;
VALUE path;
mode = NUM2INT(vmode);
GetOpenFile(obj, fptr);
if (fchmod(fptr->fd, mode) == -1) {
if (HAVE_FCHMOD || errno != ENOSYS)
rb_sys_fail_path(fptr->pathv);
}
else {
if (!HAVE_FCHMOD) return INT2FIX(0);
}
if (NIL_P(fptr->pathv)) return Qnil;
path = rb_str_encode_ospath(fptr->pathv);
if (chmod(RSTRING_PTR(path), mode) == -1)
rb_sys_fail_path(fptr->pathv);
return INT2FIX(0);
}