public Method

File.chown(p1, p2)

file.chown(owner_int, group_int )    0

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)

Source Code

/*
*  call-seq:
*     file.chown(owner_int, group_int )   => 0
*  
*  Changes the owner and group of <i>file</i> 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
*  <code>nil</code> or -1 owner or group id is ignored. Follows
*  symbolic links. See also <code>File#lchown</code>.
*     
*     File.new("testfile").chown(502, 1000)
*     
*/

static VALUE
rb_file_chown(obj, owner, group)
   VALUE obj, owner, group;
{
   OpenFile *fptr;
   int o, g;

   rb_secure(2);
   o = NIL_P(owner) ? -1 : NUM2INT(owner);
   g = NIL_P(group) ? -1 : NUM2INT(group);
   GetOpenFile(obj, fptr);
#if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32) || defined(__EMX__)
   if (!fptr->path) return Qnil;
   if (chown(fptr->path, o, g) == -1)
       rb_sys_fail(fptr->path);
#else
   if (fchown(fileno(fptr->f), o, g) == -1)
       rb_sys_fail(fptr->path);
#endif

   return INT2FIX(0);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.