Class: File::Stat
Overview
Objects of class File::Stat
encapsulate common status information for File
objects. The information is recorded at the moment the File::Stat
object is created; changes made to the file after that point will not be reflected. File::Stat
objects are returned by IO#stat
, File::stat
, File#lstat
, and File::lstat
. Many of these methods return platform-specific values, and not all values are meaningful on all systems. See also Kernel#test
.
Instance Method Summary collapse
-
#<=>(other_stat) ⇒ -1, ...
Compares File::Stat objects by comparing their respective modification times.
-
#atime ⇒ Time
Returns the last access time for this file as an object of class
Time
. -
#blksize ⇒ Integer?
Returns the native file system’s block size.
-
#blockdev? ⇒ Boolean
Returns
true
if the file is a block device,false
if it isn’t or if the operating system doesn’t support this feature. -
#blocks ⇒ Integer?
Returns the number of native file system blocks allocated for this file, or
nil
if the operating system doesn’t support this feature. -
#chardev? ⇒ Boolean
Returns
true
if the file is a character device,false
if it isn’t or if the operating system doesn’t support this feature. -
#ctime ⇒ aTime
Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself).
-
#dev ⇒ Fixnum
Returns an integer representing the device on which stat resides.
-
#dev_major ⇒ Fixnum
Returns the major part of
File_Stat#dev
ornil
. -
#dev_minor ⇒ Fixnum
Returns the minor part of
File_Stat#dev
ornil
. -
#directory? ⇒ Boolean
Returns
true
if stat is a directory,false
otherwise. -
#executable? ⇒ Boolean
Returns
true
if stat is executable or if the operating system doesn’t distinguish executable files from nonexecutable files. -
#executable_real? ⇒ Boolean
Same as
executable?
, but tests using the real owner of the process. -
#file? ⇒ Boolean
Returns
true
if stat is a regular file (not a device file, pipe, socket, etc.). -
#ftype ⇒ String
Identifies the type of stat.
-
#gid ⇒ Fixnum
Returns the numeric group id of the owner of stat.
-
#grpowned? ⇒ Boolean
Returns true if the effective group id of the process is the same as the group id of stat.
-
#File::Stat.new(file_name) ⇒ Object
constructor
Create a File::Stat object for the given file name (raising an exception if the file doesn’t exist).
-
#initialize_copy ⇒ Object
:nodoc:.
-
#ino ⇒ Fixnum
Returns the inode number for stat.
-
#inspect ⇒ String
Produce a nicely formatted description of stat.
-
#mode ⇒ Fixnum
Returns an integer representing the permission bits of stat.
-
#mtime ⇒ aTime
Returns the modification time of stat.
-
#nlink ⇒ Fixnum
Returns the number of hard links to stat.
-
#owned? ⇒ Boolean
Returns
true
if the effective user id of the process is the same as the owner of stat. -
#pipe? ⇒ Boolean
Returns
true
if the operating system supports pipes and stat is a pipe;false
otherwise. -
#rdev ⇒ Fixnum?
Returns an integer representing the device type on which stat resides.
-
#rdev_major ⇒ Fixnum
Returns the major part of
File_Stat#rdev
ornil
. -
#rdev_minor ⇒ Fixnum
Returns the minor part of
File_Stat#rdev
ornil
. -
#readable? ⇒ Boolean
Returns
true
if stat is readable by the effective user id of this process. -
#readable_real? ⇒ Boolean
Returns
true
if stat is readable by the real user id of this process. -
#setgid? ⇒ Boolean
Returns
true
if stat has the set-group-id permission bit set,false
if it doesn’t or if the operating system doesn’t support this feature. -
#setuid? ⇒ Boolean
Returns
true
if stat has the set-user-id permission bit set,false
if it doesn’t or if the operating system doesn’t support this feature. -
#size ⇒ Fixnum
Returns the size of stat in bytes.
-
#size ⇒ Integer
Returns the size of stat in bytes.
-
#socket? ⇒ Boolean
Returns
true
if stat is a socket,false
if it isn’t or if the operating system doesn’t support this feature. -
#sticky? ⇒ Boolean
Returns
true
if stat has its sticky bit set,false
if it doesn’t or if the operating system doesn’t support this feature. -
#symlink? ⇒ Boolean
Returns
true
if stat is a symbolic link,false
if it isn’t or if the operating system doesn’t support this feature. -
#uid ⇒ Fixnum
Returns the numeric user id of the owner of stat.
-
#world_readable? ⇒ Fixnum?
If stat is readable by others, returns an integer representing the file permission bits of stat.
-
#world_writable? ⇒ Fixnum?
If stat is writable by others, returns an integer representing the file permission bits of stat.
-
#writable? ⇒ Boolean
Returns
true
if stat is writable by the effective user id of this process. -
#writable_real? ⇒ Boolean
Returns
true
if stat is writable by the real user id of this process. -
#zero? ⇒ Boolean
Returns
true
if stat is a zero-length file;false
otherwise.
Methods included from Comparable
#<, #<=, #==, #>, #>=, #between?
Constructor Details
#File::Stat.new(file_name) ⇒ Object
Create a File::Stat object for the given file name (raising an exception if the file doesn’t exist).
4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 |
# File 'file.c', line 4666
static VALUE
rb_stat_init(VALUE obj, VALUE fname)
{
struct stat st, *nst;
rb_secure(2);
FilePathValue(fname);
fname = rb_str_encode_ospath(fname);
if (STAT(StringValueCStr(fname), &st) == -1) {
rb_sys_fail_path(fname);
}
if (DATA_PTR(obj)) {
xfree(DATA_PTR(obj));
DATA_PTR(obj) = NULL;
}
nst = ALLOC(struct stat);
*nst = st;
DATA_PTR(obj) = nst;
return Qnil;
}
|
Instance Method Details
#<=>(other_stat) ⇒ -1, ...
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'file.c', line 412
static VALUE
rb_stat_cmp(VALUE self, VALUE other)
{
if (rb_obj_is_kind_of(other, rb_obj_class(self))) {
struct timespec ts1 = stat_mtimespec(get_stat(self));
struct timespec ts2 = stat_mtimespec(get_stat(other));
if (ts1.tv_sec == ts2.tv_sec) {
if (ts1.tv_nsec == ts2.tv_nsec) return INT2FIX(0);
if (ts1.tv_nsec < ts2.tv_nsec) return INT2FIX(-1);
return INT2FIX(1);
}
if (ts1.tv_sec < ts2.tv_sec) return INT2FIX(-1);
return INT2FIX(1);
}
return Qnil;
}
|
#atime ⇒ Time
796 797 798 799 800 |
# File 'file.c', line 796
static VALUE
rb_stat_atime(VALUE self)
{
return stat_atime(get_stat(self));
}
|
#blksize ⇒ Integer?
678 679 680 681 682 683 684 685 686 |
# File 'file.c', line 678
static VALUE
rb_stat_blksize(VALUE self)
{
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
return ULONG2NUM(get_stat(self)->st_blksize);
#else
return Qnil;
#endif
}
|
#blockdev? ⇒ Boolean
4825 4826 4827 4828 4829 4830 4831 4832 4833 |
# File 'file.c', line 4825
static VALUE
rb_stat_b(VALUE obj)
{
#ifdef S_ISBLK
if (S_ISBLK(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}
|
#blocks ⇒ Integer?
699 700 701 702 703 704 705 706 707 708 709 710 711 |
# File 'file.c', line 699
static VALUE
rb_stat_blocks(VALUE self)
{
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
# if SIZEOF_STRUCT_STAT_ST_BLOCKS > SIZEOF_LONG
return ULL2NUM(get_stat(self)->st_blocks);
# else
return ULONG2NUM(get_stat(self)->st_blocks);
# endif
#else
return Qnil;
#endif
}
|
#chardev? ⇒ Boolean
4847 4848 4849 4850 4851 4852 4853 |
# File 'file.c', line 4847
static VALUE
rb_stat_c(VALUE obj)
{
if (S_ISCHR(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}
|
#ctime ⇒ aTime
832 833 834 835 836 |
# File 'file.c', line 832
static VALUE
rb_stat_ctime(VALUE self)
{
return stat_ctime(get_stat(self));
}
|
#dev ⇒ Fixnum
451 452 453 454 455 |
# File 'file.c', line 451
static VALUE
rb_stat_dev(VALUE self)
{
return DEVT2NUM(get_stat(self)->st_dev);
}
|
#dev_major ⇒ Fixnum
468 469 470 471 472 473 474 475 476 |
# File 'file.c', line 468
static VALUE
rb_stat_dev_major(VALUE self)
{
#if defined(major)
return INT2NUM(major(get_stat(self)->st_dev));
#else
return Qnil;
#endif
}
|
#dev_minor ⇒ Fixnum
489 490 491 492 493 494 495 496 497 |
# File 'file.c', line 489
static VALUE
rb_stat_dev_minor(VALUE self)
{
#if defined(minor)
return INT2NUM(minor(get_stat(self)->st_dev));
#else
return Qnil;
#endif
}
|
#directory? ⇒ Boolean
4739 4740 4741 4742 4743 4744 |
# File 'file.c', line 4739
static VALUE
rb_stat_d(VALUE obj)
{
if (S_ISDIR(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}
|
#executable? ⇒ Boolean
5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 |
# File 'file.c', line 5099
static VALUE
rb_stat_x(VALUE obj)
{
struct stat *st = get_stat(obj);
#ifdef USE_GETEUID
if (geteuid() == 0) {
return st->st_mode & S_IXUGO ? Qtrue : Qfalse;
}
#endif
#ifdef S_IXUSR
if (rb_stat_owned(obj))
return st->st_mode & S_IXUSR ? Qtrue : Qfalse;
#endif
#ifdef S_IXGRP
if (rb_stat_grpowned(obj))
return st->st_mode & S_IXGRP ? Qtrue : Qfalse;
#endif
#ifdef S_IXOTH
if (!(st->st_mode & S_IXOTH)) return Qfalse;
#endif
return Qtrue;
}
|
#executable_real? ⇒ Boolean
Same as executable?
, but tests using the real owner of the process.
5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 |
# File 'file.c', line 5131
static VALUE
rb_stat_X(VALUE obj)
{
struct stat *st = get_stat(obj);
#ifdef USE_GETEUID
if (getuid() == 0) {
return st->st_mode & S_IXUGO ? Qtrue : Qfalse;
}
#endif
#ifdef S_IXUSR
if (rb_stat_rowned(obj))
return st->st_mode & S_IXUSR ? Qtrue : Qfalse;
#endif
#ifdef S_IXGRP
if (rb_group_member(get_stat(obj)->st_gid))
return st->st_mode & S_IXGRP ? Qtrue : Qfalse;
#endif
#ifdef S_IXOTH
if (!(st->st_mode & S_IXOTH)) return Qfalse;
#endif
return Qtrue;
}
|
#file? ⇒ Boolean
5166 5167 5168 5169 5170 5171 |
# File 'file.c', line 5166
static VALUE
rb_stat_f(VALUE obj)
{
if (S_ISREG(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}
|
#ftype ⇒ String
4722 4723 4724 4725 4726 |
# File 'file.c', line 4722
static VALUE
rb_stat_ftype(VALUE obj)
{
return rb_file_ftype(get_stat(obj));
}
|
#gid ⇒ Fixnum
582 583 584 585 586 |
# File 'file.c', line 582
static VALUE
rb_stat_gid(VALUE self)
{
return GIDT2NUM(get_stat(self)->st_gid);
}
|
#grpowned? ⇒ Boolean
4893 4894 4895 4896 4897 4898 4899 4900 |
# File 'file.c', line 4893
static VALUE
rb_stat_grpowned(VALUE obj)
{
#ifndef _WIN32
if (rb_group_member(get_stat(obj)->st_gid)) return Qtrue;
#endif
return Qfalse;
}
|
#initialize_copy ⇒ Object
:nodoc:
4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 |
# File 'file.c', line 4689
static VALUE
rb_stat_init_copy(VALUE copy, VALUE orig)
{
struct stat *nst;
if (!OBJ_INIT_COPY(copy, orig)) return copy;
if (DATA_PTR(copy)) {
xfree(DATA_PTR(copy));
DATA_PTR(copy) = 0;
}
if (DATA_PTR(orig)) {
nst = ALLOC(struct stat);
*nst = *(struct stat*)DATA_PTR(orig);
DATA_PTR(copy) = nst;
}
return copy;
}
|
#ino ⇒ Fixnum
509 510 511 512 513 514 515 516 517 |
# File 'file.c', line 509
static VALUE
rb_stat_ino(VALUE self)
{
#if SIZEOF_STRUCT_STAT_ST_INO > SIZEOF_LONG
return ULL2NUM(get_stat(self)->st_ino);
#else
return ULONG2NUM(get_stat(self)->st_ino);
#endif
}
|
#inspect ⇒ String
Produce a nicely formatted description of stat.
File.stat("/etc/passwd").inspect
#=> "#<File::Stat dev=0xe000005, ino=1078078, mode=0100644,
# nlink=1, uid=0, gid=0, rdev=0x0, size=1374, blksize=4096,
# blocks=8, atime=Wed Dec 10 10:16:12 CST 2003,
# mtime=Fri Sep 12 15:41:41 CDT 2003,
# ctime=Mon Oct 27 11:20:27 CST 2003>"
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 |
# File 'file.c', line 852
static VALUE
rb_stat_inspect(VALUE self)
{
VALUE str;
size_t i;
static const struct {
const char *name;
VALUE (*func)(VALUE);
} member[] = {
{"dev", rb_stat_dev},
{"ino", rb_stat_ino},
{"mode", rb_stat_mode},
{"nlink", rb_stat_nlink},
{"uid", rb_stat_uid},
{"gid", rb_stat_gid},
{"rdev", rb_stat_rdev},
{"size", rb_stat_size},
{"blksize", rb_stat_blksize},
{"blocks", rb_stat_blocks},
{"atime", rb_stat_atime},
{"mtime", rb_stat_mtime},
{"ctime", rb_stat_ctime},
};
struct stat* st;
TypedData_Get_Struct(self, struct stat, &stat_data_type, st);
if (!st) {
return rb_sprintf("#<%s: uninitialized>", rb_obj_classname(self));
}
str = rb_str_buf_new2("#<");
rb_str_buf_cat2(str, rb_obj_classname(self));
rb_str_buf_cat2(str, " ");
for (i = 0; i < sizeof(member)/sizeof(member[0]); i++) {
VALUE v;
if (i > 0) {
rb_str_buf_cat2(str, ", ");
}
rb_str_buf_cat2(str, member[i].name);
rb_str_buf_cat2(str, "=");
v = (*member[i].func)(self);
if (i == 2) { /* mode */
rb_str_catf(str, "0%lo", (unsigned long)NUM2ULONG(v));
}
else if (i == 0 || i == 6) { /* dev/rdev */
rb_str_catf(str, "0x%"PRI_DEVT_PREFIX"x", NUM2DEVT(v));
}
else {
rb_str_append(str, rb_inspect(v));
}
}
rb_str_buf_cat2(str, ">");
OBJ_INFECT(str, self);
return str;
}
|
#mode ⇒ Fixnum
532 533 534 535 536 |
# File 'file.c', line 532
static VALUE
rb_stat_mode(VALUE self)
{
return UINT2NUM(ST2UINT(get_stat(self)->st_mode));
}
|
#mtime ⇒ aTime
812 813 814 815 816 |
# File 'file.c', line 812
static VALUE
rb_stat_mtime(VALUE self)
{
return stat_mtime(get_stat(self));
}
|
#nlink ⇒ Fixnum
550 551 552 553 554 |
# File 'file.c', line 550
static VALUE
rb_stat_nlink(VALUE self)
{
return UINT2NUM(get_stat(self)->st_nlink);
}
|
#owned? ⇒ Boolean
4867 4868 4869 4870 4871 4872 |
# File 'file.c', line 4867
static VALUE
rb_stat_owned(VALUE obj)
{
if (get_stat(obj)->st_uid == geteuid()) return Qtrue;
return Qfalse;
}
|
#pipe? ⇒ Boolean
Returns true
if the operating system supports pipes and stat is a pipe; false
otherwise.
4754 4755 4756 4757 4758 4759 4760 4761 4762 |
# File 'file.c', line 4754
static VALUE
rb_stat_p(VALUE obj)
{
#ifdef S_IFIFO
if (S_ISFIFO(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}
|
#rdev ⇒ Fixnum?
600 601 602 603 604 605 606 607 608 |
# File 'file.c', line 600
static VALUE
rb_stat_rdev(VALUE self)
{
#ifdef HAVE_STRUCT_STAT_ST_RDEV
return DEVT2NUM(get_stat(self)->st_rdev);
#else
return Qnil;
#endif
}
|
#rdev_major ⇒ Fixnum
621 622 623 624 625 626 627 628 629 |
# File 'file.c', line 621
static VALUE
rb_stat_rdev_major(VALUE self)
{
#if defined(HAVE_STRUCT_STAT_ST_RDEV) && defined(major)
return DEVT2NUM(major(get_stat(self)->st_rdev));
#else
return Qnil;
#endif
}
|
#rdev_minor ⇒ Fixnum
642 643 644 645 646 647 648 649 650 |
# File 'file.c', line 642
static VALUE
rb_stat_rdev_minor(VALUE self)
{
#if defined(HAVE_STRUCT_STAT_ST_RDEV) && defined(minor)
return DEVT2NUM(minor(get_stat(self)->st_rdev));
#else
return Qnil;
#endif
}
|
#readable? ⇒ Boolean
4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 |
# File 'file.c', line 4913
static VALUE
rb_stat_r(VALUE obj)
{
struct stat *st = get_stat(obj);
#ifdef USE_GETEUID
if (geteuid() == 0) return Qtrue;
#endif
#ifdef S_IRUSR
if (rb_stat_owned(obj))
return st->st_mode & S_IRUSR ? Qtrue : Qfalse;
#endif
#ifdef S_IRGRP
if (rb_stat_grpowned(obj))
return st->st_mode & S_IRGRP ? Qtrue : Qfalse;
#endif
#ifdef S_IROTH
if (!(st->st_mode & S_IROTH)) return Qfalse;
#endif
return Qtrue;
}
|
#readable_real? ⇒ Boolean
4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 |
# File 'file.c', line 4946
static VALUE
rb_stat_R(VALUE obj)
{
struct stat *st = get_stat(obj);
#ifdef USE_GETEUID
if (getuid() == 0) return Qtrue;
#endif
#ifdef S_IRUSR
if (rb_stat_rowned(obj))
return st->st_mode & S_IRUSR ? Qtrue : Qfalse;
#endif
#ifdef S_IRGRP
if (rb_group_member(get_stat(obj)->st_gid))
return st->st_mode & S_IRGRP ? Qtrue : Qfalse;
#endif
#ifdef S_IROTH
if (!(st->st_mode & S_IROTH)) return Qfalse;
#endif
return Qtrue;
}
|
#setgid? ⇒ Boolean
5242 5243 5244 5245 5246 5247 5248 5249 |
# File 'file.c', line 5242
static VALUE
rb_stat_sgid(VALUE obj)
{
#ifdef S_ISGID
if (get_stat(obj)->st_mode & S_ISGID) return Qtrue;
#endif
return Qfalse;
}
|
#setuid? ⇒ Boolean
5221 5222 5223 5224 5225 5226 5227 5228 |
# File 'file.c', line 5221
static VALUE
rb_stat_suid(VALUE obj)
{
#ifdef S_ISUID
if (get_stat(obj)->st_mode & S_ISUID) return Qtrue;
#endif
return Qfalse;
}
|
#size ⇒ Fixnum
661 662 663 664 665 |
# File 'file.c', line 661
static VALUE
rb_stat_size(VALUE self)
{
return OFFT2NUM(get_stat(self)->st_size);
}
|
#size ⇒ Integer
5201 5202 5203 5204 5205 5206 5207 5208 |
# File 'file.c', line 5201
static VALUE
rb_stat_s(VALUE obj)
{
off_t size = get_stat(obj)->st_size;
if (size == 0) return Qnil;
return OFFT2NUM(size);
}
|
#socket? ⇒ Boolean
4802 4803 4804 4805 4806 4807 4808 4809 4810 |
# File 'file.c', line 4802
static VALUE
rb_stat_S(VALUE obj)
{
#ifdef S_ISSOCK
if (S_ISSOCK(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}
|
#sticky? ⇒ Boolean
5263 5264 5265 5266 5267 5268 5269 5270 |
# File 'file.c', line 5263
static VALUE
rb_stat_sticky(VALUE obj)
{
#ifdef S_ISVTX
if (get_stat(obj)->st_mode & S_ISVTX) return Qtrue;
#endif
return Qfalse;
}
|
#symlink? ⇒ Boolean
Returns true
if stat is a symbolic link, false
if it isn’t or if the operating system doesn’t support this feature. As File::stat
automatically follows symbolic links, symlink?
will always be false
for an object returned by File::stat
.
File.symlink("testfile", "alink") #=> 0
File.stat("alink").symlink? #=> false
File.lstat("alink").symlink? #=> true
4781 4782 4783 4784 4785 4786 4787 4788 |
# File 'file.c', line 4781
static VALUE
rb_stat_l(VALUE obj)
{
#ifdef S_ISLNK
if (S_ISLNK(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}
|
#uid ⇒ Fixnum
566 567 568 569 570 |
# File 'file.c', line 566
static VALUE
rb_stat_uid(VALUE self)
{
return UIDT2NUM(get_stat(self)->st_uid);
}
|
#world_readable? ⇒ Fixnum?
4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 |
# File 'file.c', line 4981
static VALUE
rb_stat_wr(VALUE obj)
{
#ifdef S_IROTH
if ((get_stat(obj)->st_mode & (S_IROTH)) == S_IROTH) {
return UINT2NUM(get_stat(obj)->st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
}
else {
return Qnil;
}
#endif
}
|
#world_writable? ⇒ Fixnum?
5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 |
# File 'file.c', line 5073
static VALUE
rb_stat_ww(VALUE obj)
{
#ifdef S_IROTH
if ((get_stat(obj)->st_mode & (S_IWOTH)) == S_IWOTH) {
return UINT2NUM(get_stat(obj)->st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
}
else {
return Qnil;
}
#endif
}
|
#writable? ⇒ Boolean
5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 |
# File 'file.c', line 5005
static VALUE
rb_stat_w(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;
}
|
#writable_real? ⇒ Boolean
5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 |
# File 'file.c', line 5038
static VALUE
rb_stat_W(VALUE obj)
{
struct stat *st = get_stat(obj);
#ifdef USE_GETEUID
if (getuid() == 0) return Qtrue;
#endif
#ifdef S_IWUSR
if (rb_stat_rowned(obj))
return st->st_mode & S_IWUSR ? Qtrue : Qfalse;
#endif
#ifdef S_IWGRP
if (rb_group_member(get_stat(obj)->st_gid))
return st->st_mode & S_IWGRP ? Qtrue : Qfalse;
#endif
#ifdef S_IWOTH
if (!(st->st_mode & S_IWOTH)) return Qfalse;
#endif
return Qtrue;
}
|