public Method

Stat.writable?

stat.writable?  true or false

Returns true if stat is writable by the effective user id of this process.

File.stat("testfile").writable?   #=> true

Source Code

/*
*  call-seq:
*     stat.writable? -> true or false
*  
*  Returns <code>true</code> if <i>stat</i> is writable by the
*  effective user id of this process.
*     
*     File.stat("testfile").writable?   #=> true
*     
*/

static VALUE
rb_stat_w(obj)
   VALUE obj;
{
   struct stat *st = get_stat(obj);

#ifdef USE_GETEUID
   if (geteuid() == 0) return Qtrue;
#endif
#ifdef S_IWUSR
   if (rb_stat_owned(obj))
       return st->st_mode & S_IWUSR ? Qtrue : Qfalse;
#endif
#ifdef S_IWGRP
   if (rb_stat_grpowned(obj))
       return st->st_mode & S_IWGRP ? Qtrue : Qfalse;
#endif
#ifdef S_IWOTH
   if (!(st->st_mode & S_IWOTH)) return Qfalse;
#endif
   return Qtrue;
}
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.