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.
-
#birthtime ⇒ aTime
Returns the birth time for stat.
-
#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 ⇒ Integer
Returns an integer representing the device on which stat resides.
-
#dev_major ⇒ Integer
Returns the major part of
File_Stat#dev
ornil
. -
#dev_minor ⇒ Integer
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 ⇒ Integer
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(orig) ⇒ Object
:nodoc:.
-
#ino ⇒ Integer
Returns the inode number for stat.
-
#inspect ⇒ String
Produce a nicely formatted description of stat.
-
#mode ⇒ Integer
Returns an integer representing the permission bits of stat.
-
#mtime ⇒ aTime
Returns the modification time of stat.
-
#nlink ⇒ Integer
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 ⇒ Integer?
Returns an integer representing the device type on which stat resides.
-
#rdev_major ⇒ Integer
Returns the major part of
File_Stat#rdev
ornil
. -
#rdev_minor ⇒ Integer
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 ⇒ Integer
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 ⇒ Integer
Returns the numeric user id of the owner of stat.
-
#world_readable? ⇒ Integer?
If stat is readable by others, returns an integer representing the file permission bits of stat.
-
#world_writable? ⇒ Integer?
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?, #clamp
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).
5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 |
# File 'file.c', line 5421
static VALUE
rb_stat_init(VALUE obj, VALUE fname)
{
struct stat st, *nst;
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, ...
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'file.c', line 523
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
929 930 931 932 933 |
# File 'file.c', line 929
static VALUE
rb_stat_atime(VALUE self)
{
return stat_atime(get_stat(self));
}
|
#birthtime ⇒ aTime
Returns the birth time for stat.
If the platform doesn’t have birthtime, raises NotImplementedError.
File.write("testfile", "foo")
sleep 10
File.write("testfile", "bar")
sleep 10
File.chmod(0644, "testfile")
sleep 10
File.read("testfile")
File.stat("testfile").birthtime #=> 2014-02-24 11:19:17 +0900
File.stat("testfile").mtime #=> 2014-02-24 11:19:27 +0900
File.stat("testfile").ctime #=> 2014-02-24 11:19:37 +0900
File.stat("testfile").atime #=> 2014-02-24 11:19:47 +0900
994 995 996 997 998 |
# File 'file.c', line 994
static VALUE
rb_stat_birthtime(VALUE self)
{
return stat_birthtime(get_stat(self));
}
|
#blksize ⇒ Integer?
795 796 797 798 799 800 801 802 803 |
# File 'file.c', line 795
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
5578 5579 5580 5581 5582 5583 5584 5585 5586 |
# File 'file.c', line 5578
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?
816 817 818 819 820 821 822 823 824 825 826 827 828 |
# File 'file.c', line 816
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
5600 5601 5602 5603 5604 5605 5606 |
# File 'file.c', line 5600
static VALUE
rb_stat_c(VALUE obj)
{
if (S_ISCHR(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}
|
#ctime ⇒ aTime
965 966 967 968 969 |
# File 'file.c', line 965
static VALUE
rb_stat_ctime(VALUE self)
{
return stat_ctime(get_stat(self));
}
|
#dev ⇒ Integer
562 563 564 565 566 |
# File 'file.c', line 562
static VALUE
rb_stat_dev(VALUE self)
{
return DEVT2NUM(get_stat(self)->st_dev);
}
|
#dev_major ⇒ Integer
579 580 581 582 583 584 585 586 587 |
# File 'file.c', line 579
static VALUE
rb_stat_dev_major(VALUE self)
{
#if defined(major)
return UINT2NUM(major(get_stat(self)->st_dev));
#else
return Qnil;
#endif
}
|
#dev_minor ⇒ Integer
600 601 602 603 604 605 606 607 608 |
# File 'file.c', line 600
static VALUE
rb_stat_dev_minor(VALUE self)
{
#if defined(minor)
return UINT2NUM(minor(get_stat(self)->st_dev));
#else
return Qnil;
#endif
}
|
#directory? ⇒ Boolean
5493 5494 5495 5496 5497 5498 |
# File 'file.c', line 5493
static VALUE
rb_stat_d(VALUE obj)
{
if (S_ISDIR(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}
|
#executable? ⇒ Boolean
5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 |
# File 'file.c', line 5854
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.
5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 |
# File 'file.c', line 5886
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
5921 5922 5923 5924 5925 5926 |
# File 'file.c', line 5921
static VALUE
rb_stat_f(VALUE obj)
{
if (S_ISREG(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}
|
#ftype ⇒ String
5476 5477 5478 5479 5480 |
# File 'file.c', line 5476
static VALUE
rb_stat_ftype(VALUE obj)
{
return rb_file_ftype(get_stat(obj));
}
|
#gid ⇒ Integer
699 700 701 702 703 |
# File 'file.c', line 699
static VALUE
rb_stat_gid(VALUE self)
{
return GIDT2NUM(get_stat(self)->st_gid);
}
|
#grpowned? ⇒ Boolean
5646 5647 5648 5649 5650 5651 5652 5653 |
# File 'file.c', line 5646
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(orig) ⇒ Object
:nodoc:
5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 |
# File 'file.c', line 5443
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 ⇒ Integer
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'file.c', line 620
static VALUE
rb_stat_ino(VALUE self)
{
#ifdef HAVE_STRUCT_STAT_ST_INOHIGH
/* assume INTEGER_PACK_LSWORD_FIRST and st_inohigh is just next of st_ino */
return rb_integer_unpack(&get_stat(self)->st_ino, 2,
SIZEOF_STRUCT_STAT_ST_INO, 0,
INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER|
INTEGER_PACK_2COMP);
#elif 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,
# birthtime=Mon Aug 04 08:13:49 CDT 2003>"
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 |
# File 'file.c', line 1018
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},
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC)
{"birthtime", rb_stat_birthtime},
#endif
};
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, ">");
return str;
}
|
#mode ⇒ Integer
649 650 651 652 653 |
# File 'file.c', line 649
static VALUE
rb_stat_mode(VALUE self)
{
return UINT2NUM(ST2UINT(get_stat(self)->st_mode));
}
|
#mtime ⇒ aTime
945 946 947 948 949 |
# File 'file.c', line 945
static VALUE
rb_stat_mtime(VALUE self)
{
return stat_mtime(get_stat(self));
}
|
#nlink ⇒ Integer
667 668 669 670 671 |
# File 'file.c', line 667
static VALUE
rb_stat_nlink(VALUE self)
{
return UINT2NUM(get_stat(self)->st_nlink);
}
|
#owned? ⇒ Boolean
5620 5621 5622 5623 5624 5625 |
# File 'file.c', line 5620
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.
5508 5509 5510 5511 5512 5513 5514 5515 5516 |
# File 'file.c', line 5508
static VALUE
rb_stat_p(VALUE obj)
{
#ifdef S_IFIFO
if (S_ISFIFO(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}
|
#rdev ⇒ Integer?
717 718 719 720 721 722 723 724 725 |
# File 'file.c', line 717
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 ⇒ Integer
738 739 740 741 742 743 744 745 746 |
# File 'file.c', line 738
static VALUE
rb_stat_rdev_major(VALUE self)
{
#if defined(HAVE_STRUCT_STAT_ST_RDEV) && defined(major)
return UINT2NUM(major(get_stat(self)->st_rdev));
#else
return Qnil;
#endif
}
|
#rdev_minor ⇒ Integer
759 760 761 762 763 764 765 766 767 |
# File 'file.c', line 759
static VALUE
rb_stat_rdev_minor(VALUE self)
{
#if defined(HAVE_STRUCT_STAT_ST_RDEV) && defined(minor)
return UINT2NUM(minor(get_stat(self)->st_rdev));
#else
return Qnil;
#endif
}
|
#readable? ⇒ Boolean
5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 |
# File 'file.c', line 5666
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
5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 |
# File 'file.c', line 5699
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
5997 5998 5999 6000 6001 6002 6003 6004 |
# File 'file.c', line 5997
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
5976 5977 5978 5979 5980 5981 5982 5983 |
# File 'file.c', line 5976
static VALUE
rb_stat_suid(VALUE obj)
{
#ifdef S_ISUID
if (get_stat(obj)->st_mode & S_ISUID) return Qtrue;
#endif
return Qfalse;
}
|
#size ⇒ Integer
778 779 780 781 782 |
# File 'file.c', line 778
static VALUE
rb_stat_size(VALUE self)
{
return OFFT2NUM(get_stat(self)->st_size);
}
|
#size ⇒ Integer
5956 5957 5958 5959 5960 5961 5962 5963 |
# File 'file.c', line 5956
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
5555 5556 5557 5558 5559 5560 5561 5562 5563 |
# File 'file.c', line 5555
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
6018 6019 6020 6021 6022 6023 6024 6025 |
# File 'file.c', line 6018
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
5534 5535 5536 5537 5538 5539 5540 5541 |
# File 'file.c', line 5534
static VALUE
rb_stat_l(VALUE obj)
{
#ifdef S_ISLNK
if (S_ISLNK(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}
|
#uid ⇒ Integer
683 684 685 686 687 |
# File 'file.c', line 683
static VALUE
rb_stat_uid(VALUE self)
{
return UIDT2NUM(get_stat(self)->st_uid);
}
|
#world_readable? ⇒ Integer?
5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 |
# File 'file.c', line 5734
static VALUE
rb_stat_wr(VALUE obj)
{
#ifdef S_IROTH
struct stat *st = get_stat(obj);
if ((st->st_mode & (S_IROTH)) == S_IROTH) {
return UINT2NUM(st->st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
}
else {
return Qnil;
}
#endif
}
|
#world_writable? ⇒ Integer?
5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 |
# File 'file.c', line 5827
static VALUE
rb_stat_ww(VALUE obj)
{
#ifdef S_IROTH
struct stat *st = get_stat(obj);
if ((st->st_mode & (S_IWOTH)) == S_IWOTH) {
return UINT2NUM(st->st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
}
else {
return Qnil;
}
#endif
}
|
#writable? ⇒ Boolean
5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 |
# File 'file.c', line 5759
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
5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 |
# File 'file.c', line 5792
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;
}
|