APIdock / Ruby
/
method

chmod

ruby latest stable - Class: File
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) #=> 0
static VALUE
rb_file_chmod(VALUE obj, VALUE vmode)
{
 rb_io_t *fptr;
 int mode;
#if !defined HAVE_FCHMOD || !HAVE_FCHMOD
 VALUE path;
#endif
 mode = NUM2INT(vmode);
 GetOpenFile(obj, fptr);
#ifdef HAVE_FCHMOD
 if (fchmod(fptr->fd, mode) == -1) {
 if (HAVE_FCHMOD || errno != ENOSYS)
 rb_sys_fail_path(fptr->pathv);
 }
 else {
 if (!HAVE_FCHMOD) return INT2FIX(0);
 }
#endif
#if !defined HAVE_FCHMOD || !HAVE_FCHMOD
 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);
#endif
 return INT2FIX(0);
}

AltStyle によって変換されたページ (->オリジナル) /