File: C:/Ruby27-x64/share/doc/ruby/html/File/Stat.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class File::Stat - RDoc Documentation</title>
<script type="text/javascript">
var rdoc_rel_prefix = "../";
var index_rel_prefix = "../";
</script>
<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>
<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/rdoc.css" rel="stylesheet">
<body id="top" role="document" class="class">
<nav role="navigation">
<div id="project-navigation">
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
<h2>
<a href="../index.html" rel="home">Home</a>
</h2>
<div id="table-of-contents-navigation">
<a href="../table_of_contents.html#pages">Pages</a>
<a href="../table_of_contents.html#classes">Classes</a>
<a href="../table_of_contents.html#methods">Methods</a>
</div>
</div>
<div id="search-section" role="search" class="project-section initially-hidden">
<form action="#" method="get" accept-charset="utf-8">
<div id="search-field-wrapper">
<input id="search-field" role="combobox" aria-label="Search"
aria-autocomplete="list" aria-controls="search-results"
type="text" name="search" placeholder="Search" spellcheck="false"
title="Type to search, Up and Down to navigate, Enter to load">
</div>
<ul id="search-results" aria-label="Search Results"
aria-busy="false" aria-expanded="false"
aria-atomic="false" class="initially-hidden"></ul>
</form>
</div>
</div>
<div id="class-metadata">
<div id="parent-class-section" class="nav-section">
<h3>Parent</h3>
<p class="link"><a href="../Object.html">Object</a>
</div>
<div id="includes-section" class="nav-section">
<h3>Included Modules</h3>
<ul class="link-list">
<li><a class="include" href="../Comparable.html">Comparable</a>
</ul>
</div>
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
<h3>Methods</h3>
<ul class="link-list" role="directory">
<li ><a href="#method-c-new">::new</a>
<li ><a href="#method-i-3C-3D-3E">#<=></a>
<li ><a href="#method-i-atime">#atime</a>
<li ><a href="#method-i-birthtime">#birthtime</a>
<li ><a href="#method-i-blksize">#blksize</a>
<li ><a href="#method-i-blockdev-3F">#blockdev?</a>
<li ><a href="#method-i-blocks">#blocks</a>
<li ><a href="#method-i-chardev-3F">#chardev?</a>
<li ><a href="#method-i-ctime">#ctime</a>
<li ><a href="#method-i-dev">#dev</a>
<li ><a href="#method-i-dev_major">#dev_major</a>
<li ><a href="#method-i-dev_minor">#dev_minor</a>
<li ><a href="#method-i-directory-3F">#directory?</a>
<li ><a href="#method-i-executable-3F">#executable?</a>
<li ><a href="#method-i-executable_real-3F">#executable_real?</a>
<li ><a href="#method-i-file-3F">#file?</a>
<li ><a href="#method-i-ftype">#ftype</a>
<li ><a href="#method-i-gid">#gid</a>
<li ><a href="#method-i-grpowned-3F">#grpowned?</a>
<li ><a href="#method-i-ino">#ino</a>
<li ><a href="#method-i-inspect">#inspect</a>
<li ><a href="#method-i-mode">#mode</a>
<li ><a href="#method-i-mtime">#mtime</a>
<li ><a href="#method-i-nlink">#nlink</a>
<li ><a href="#method-i-owned-3F">#owned?</a>
<li ><a href="#method-i-pipe-3F">#pipe?</a>
<li ><a href="#method-i-rdev">#rdev</a>
<li ><a href="#method-i-rdev_major">#rdev_major</a>
<li ><a href="#method-i-rdev_minor">#rdev_minor</a>
<li ><a href="#method-i-readable-3F">#readable?</a>
<li ><a href="#method-i-readable_real-3F">#readable_real?</a>
<li ><a href="#method-i-setgid-3F">#setgid?</a>
<li ><a href="#method-i-setuid-3F">#setuid?</a>
<li ><a href="#method-i-size">#size</a>
<li ><a href="#method-i-size-3F">#size?</a>
<li ><a href="#method-i-socket-3F">#socket?</a>
<li ><a href="#method-i-sticky-3F">#sticky?</a>
<li ><a href="#method-i-symlink-3F">#symlink?</a>
<li ><a href="#method-i-uid">#uid</a>
<li ><a href="#method-i-world_readable-3F">#world_readable?</a>
<li ><a href="#method-i-world_writable-3F">#world_writable?</a>
<li ><a href="#method-i-writable-3F">#writable?</a>
<li ><a href="#method-i-writable_real-3F">#writable_real?</a>
<li ><a href="#method-i-zero-3F">#zero?</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="class-File::Stat">
<h1 id="class-File::Stat" class="class">
class File::Stat
</h1>
<section class="description">
<p>Objects of class <a href="Stat.html"><code>File::Stat</code></a> encapsulate common status information for <a href="../File.html"><code>File</code></a> objects. The information is recorded at the moment the <a href="Stat.html"><code>File::Stat</code></a> object is created; changes made to the file after that point will not be reflected. <a href="Stat.html"><code>File::Stat</code></a> objects are returned by <a href="../IO.html#method-i-stat"><code>IO#stat</code></a>, <a href="../File.html#method-c-stat"><code>File::stat</code></a>, <a href="../File.html#method-i-lstat"><code>File#lstat</code></a>, and <a href="../File.html#method-c-lstat"><code>File::lstat</code></a>. Many of these methods return platform-specific values, and not all values are meaningful on all systems. See also <a href="../Kernel.html#method-i-test"><code>Kernel#test</code></a>.</p>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-new" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
File::Stat.new(file_name) → stat
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Create a <a href="Stat.html"><code>File::Stat</code></a> object for the given file name (raising an exception if the file doesn't exist).</p>
<div class="method-source-code" id="new-source">
<pre>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;
}</pre>
</div>
</div>
</div>
</section>
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Instance Methods</h3>
</header>
<div id="method-i-3C-3D-3E" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
stat <=> other_stat → -1, 0, 1, nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Compares <a href="Stat.html"><code>File::Stat</code></a> objects by comparing their respective modification times.</p>
<p><code>nil</code> is returned if <code>other_stat</code> is not a <a href="Stat.html"><code>File::Stat</code></a> object</p>
<pre class="ruby"><span class="ruby-identifier">f1</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"f1"</span>, <span class="ruby-string">"w"</span>)
<span class="ruby-identifier">sleep</span> <span class="ruby-value">1</span>
<span class="ruby-identifier">f2</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"f2"</span>, <span class="ruby-string">"w"</span>)
<span class="ruby-identifier">f1</span>.<span class="ruby-identifier">stat</span> <span class="ruby-operator"><=></span> <span class="ruby-identifier">f2</span>.<span class="ruby-identifier">stat</span> <span class="ruby-comment">#=> -1</span>
</pre>
<div class="method-source-code" id="3C-3D-3E-source">
<pre>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;
}</pre>
</div>
</div>
</div>
<div id="method-i-atime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
atime → time
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the last access time for this file as an object of class <a href="../Time.html"><code>Time</code></a>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">atime</span> <span class="ruby-comment">#=> Wed Dec 31 18:00:00 CST 1969</span>
</pre>
<div class="method-source-code" id="atime-source">
<pre>static VALUE
rb_stat_atime(VALUE self)
{
return stat_atime(get_stat(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-birthtime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
birthtime → aTime
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the birth time for <em>stat</em>.</p>
<p>If the platform doesn't have birthtime, raises <a href="../NotImplementedError.html"><code>NotImplementedError</code></a>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">"testfile"</span>, <span class="ruby-string">"foo"</span>)
<span class="ruby-identifier">sleep</span> <span class="ruby-value">10</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">"testfile"</span>, <span class="ruby-string">"bar"</span>)
<span class="ruby-identifier">sleep</span> <span class="ruby-value">10</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">chmod</span>(<span class="ruby-value">0644</span>, <span class="ruby-string">"testfile"</span>)
<span class="ruby-identifier">sleep</span> <span class="ruby-value">10</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-string">"testfile"</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">birthtime</span> <span class="ruby-comment">#=> 2014-02-24 11:19:17 +0900</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">mtime</span> <span class="ruby-comment">#=> 2014-02-24 11:19:27 +0900</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">ctime</span> <span class="ruby-comment">#=> 2014-02-24 11:19:37 +0900</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">atime</span> <span class="ruby-comment">#=> 2014-02-24 11:19:47 +0900</span>
</pre>
<div class="method-source-code" id="birthtime-source">
<pre>static VALUE
rb_stat_birthtime(VALUE self)
{
return stat_birthtime(get_stat(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-blksize" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
blksize → integer or nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the native file system's block size. Will return <code>nil</code> on platforms that don't support this information.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">blksize</span> <span class="ruby-comment">#=> 4096</span>
</pre>
<div class="method-source-code" id="blksize-source">
<pre>static VALUE
rb_stat_blksize(VALUE self)
{
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
return ULONG2NUM(get_stat(self)->st_blksize);
#else
return Qnil;
#endif
}</pre>
</div>
</div>
</div>
<div id="method-i-blockdev-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
blockdev? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if the file is a block device, <code>false</code> if it isn't or if the operating system doesn't support this feature.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">blockdev?</span> <span class="ruby-comment">#=> false</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/hda1"</span>).<span class="ruby-identifier">blockdev?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="blockdev-3F-source">
<pre>static VALUE
rb_stat_b(VALUE obj)
{
#ifdef S_ISBLK
if (S_ISBLK(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-blocks" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
blocks → integer or nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the number of native file system blocks allocated for this file, or <code>nil</code> if the operating system doesn't support this feature.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">blocks</span> <span class="ruby-comment">#=> 2</span>
</pre>
<div class="method-source-code" id="blocks-source">
<pre>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
}</pre>
</div>
</div>
</div>
<div id="method-i-chardev-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
chardev? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if the file is a character device, <code>false</code> if it isn't or if the operating system doesn't support this feature.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/tty"</span>).<span class="ruby-identifier">chardev?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="chardev-3F-source">
<pre>static VALUE
rb_stat_c(VALUE obj)
{
if (S_ISCHR(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-ctime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ctime → aTime
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the change time for <em>stat</em> (that is, the time directory information about the file was changed, not the file itself).</p>
<p>Note that on Windows (NTFS), returns creation time (birth time).</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">ctime</span> <span class="ruby-comment">#=> Wed Apr 09 08:53:14 CDT 2003</span>
</pre>
<div class="method-source-code" id="ctime-source">
<pre>static VALUE
rb_stat_ctime(VALUE self)
{
return stat_ctime(get_stat(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-dev" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
dev → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns an integer representing the device on which <em>stat</em> resides.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">dev</span> <span class="ruby-comment">#=> 774</span>
</pre>
<div class="method-source-code" id="dev-source">
<pre>static VALUE
rb_stat_dev(VALUE self)
{
return DEVT2NUM(get_stat(self)->st_dev);
}</pre>
</div>
</div>
</div>
<div id="method-i-dev_major" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
dev_major → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the major part of <code>File_Stat#dev</code> or <code>nil</code>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/fd1"</span>).<span class="ruby-identifier">dev_major</span> <span class="ruby-comment">#=> 2</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/tty"</span>).<span class="ruby-identifier">dev_major</span> <span class="ruby-comment">#=> 5</span>
</pre>
<div class="method-source-code" id="dev_major-source">
<pre>static VALUE
rb_stat_dev_major(VALUE self)
{
#if defined(major)
return UINT2NUM(major(get_stat(self)->st_dev));
#else
return Qnil;
#endif
}</pre>
</div>
</div>
</div>
<div id="method-i-dev_minor" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
dev_minor → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the minor part of <code>File_Stat#dev</code> or <code>nil</code>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/fd1"</span>).<span class="ruby-identifier">dev_minor</span> <span class="ruby-comment">#=> 1</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/tty"</span>).<span class="ruby-identifier">dev_minor</span> <span class="ruby-comment">#=> 0</span>
</pre>
<div class="method-source-code" id="dev_minor-source">
<pre>static VALUE
rb_stat_dev_minor(VALUE self)
{
#if defined(minor)
return UINT2NUM(minor(get_stat(self)->st_dev));
#else
return Qnil;
#endif
}</pre>
</div>
</div>
</div>
<div id="method-i-directory-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
directory?(file_name) → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if the named file is a directory, or a symlink that points at a directory, and <code>false</code> otherwise.</p>
<p><em>file_name</em> can be an <a href="../IO.html"><code>IO</code></a> object.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-string">"."</span>)
</pre>
<div class="method-source-code" id="directory-3F-source">
<pre>static VALUE
rb_stat_d(VALUE obj)
{
if (S_ISDIR(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-executable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
executable? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is executable or if the operating system doesn't distinguish executable files from nonexecutable files. The tests are made using the effective owner of the process.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">executable?</span> <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="executable-3F-source">
<pre>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;
}</pre>
</div>
</div>
</div>
<div id="method-i-executable_real-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
executable_real? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Same as <code>executable?</code>, but tests using the real owner of the process.</p>
<div class="method-source-code" id="executable_real-3F-source">
<pre>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;
}</pre>
</div>
</div>
</div>
<div id="method-i-file-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
file? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is a regular file (not a device file, pipe, socket, etc.).</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">file?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="file-3F-source">
<pre>static VALUE
rb_stat_f(VALUE obj)
{
if (S_ISREG(get_stat(obj)->st_mode)) return Qtrue;
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-ftype" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ftype → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Identifies the type of <em>stat</em>. The return string is one of: “<code>file</code>'', “<code>directory</code>'', “<code>characterSpecial</code>'', “<code>blockSpecial</code>'', “<code>fifo</code>'', “<code>link</code>'', “<code>socket</code>'', or “<code>unknown</code>''.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/tty"</span>).<span class="ruby-identifier">ftype</span> <span class="ruby-comment">#=> "characterSpecial"</span>
</pre>
<div class="method-source-code" id="ftype-source">
<pre>static VALUE
rb_stat_ftype(VALUE obj)
{
return rb_file_ftype(get_stat(obj));
}</pre>
</div>
</div>
</div>
<div id="method-i-gid" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
gid → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the numeric group id of the owner of <em>stat</em>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">gid</span> <span class="ruby-comment">#=> 500</span>
</pre>
<div class="method-source-code" id="gid-source">
<pre>static VALUE
rb_stat_gid(VALUE self)
{
return GIDT2NUM(get_stat(self)->st_gid);
}</pre>
</div>
</div>
</div>
<div id="method-i-grpowned-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
grpowned? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if the effective group id of the process is the same as the group id of <em>stat</em>. On Windows NT, returns <code>false</code>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">grpowned?</span> <span class="ruby-comment">#=> true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/etc/passwd"</span>).<span class="ruby-identifier">grpowned?</span> <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="grpowned-3F-source">
<pre>static VALUE
rb_stat_grpowned(VALUE obj)
{
#ifndef _WIN32
if (rb_group_member(get_stat(obj)->st_gid)) return Qtrue;
#endif
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-ino" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ino → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the inode number for <em>stat</em>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">ino</span> <span class="ruby-comment">#=> 1083669</span>
</pre>
<div class="method-source-code" id="ino-source">
<pre>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
}</pre>
</div>
</div>
</div>
<div id="method-i-inspect" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
inspect → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Produce a nicely formatted description of <em>stat</em>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/etc/passwd"</span>).<span class="ruby-identifier">inspect</span>
<span class="ruby-comment">#=> "#<File::Stat dev=0xe000005, ino=1078078, mode=0100644,</span>
<span class="ruby-comment"># nlink=1, uid=0, gid=0, rdev=0x0, size=1374, blksize=4096,</span>
<span class="ruby-comment"># blocks=8, atime=Wed Dec 10 10:16:12 CST 2003,</span>
<span class="ruby-comment"># mtime=Fri Sep 12 15:41:41 CDT 2003,</span>
<span class="ruby-comment"># ctime=Mon Oct 27 11:20:27 CST 2003,</span>
<span class="ruby-comment"># birthtime=Mon Aug 04 08:13:49 CDT 2003>"</span>
</pre>
<div class="method-source-code" id="inspect-source">
<pre>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;
}</pre>
</div>
</div>
</div>
<div id="method-i-mode" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
mode → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns an integer representing the permission bits of <em>stat</em>. The meaning of the bits is platform dependent; on Unix systems, see <code>stat(2)</code>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">chmod</span>(<span class="ruby-value">0644</span>, <span class="ruby-string">"testfile"</span>) <span class="ruby-comment">#=> 1</span>
<span class="ruby-identifier">s</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>)
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">"%o"</span>, <span class="ruby-identifier">s</span>.<span class="ruby-identifier">mode</span>) <span class="ruby-comment">#=> "100644"</span>
</pre>
<div class="method-source-code" id="mode-source">
<pre>static VALUE
rb_stat_mode(VALUE self)
{
return UINT2NUM(ST2UINT(get_stat(self)->st_mode));
}</pre>
</div>
</div>
</div>
<div id="method-i-mtime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
mtime → aTime
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the modification time of <em>stat</em>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">mtime</span> <span class="ruby-comment">#=> Wed Apr 09 08:53:14 CDT 2003</span>
</pre>
<div class="method-source-code" id="mtime-source">
<pre>static VALUE
rb_stat_mtime(VALUE self)
{
return stat_mtime(get_stat(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-nlink" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
nlink → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the number of hard links to <em>stat</em>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">nlink</span> <span class="ruby-comment">#=> 1</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">link</span>(<span class="ruby-string">"testfile"</span>, <span class="ruby-string">"testfile.bak"</span>) <span class="ruby-comment">#=> 0</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">nlink</span> <span class="ruby-comment">#=> 2</span>
</pre>
<div class="method-source-code" id="nlink-source">
<pre>static VALUE
rb_stat_nlink(VALUE self)
{
return UINT2NUM(get_stat(self)->st_nlink);
}</pre>
</div>
</div>
</div>
<div id="method-i-owned-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
owned? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if the effective user id of the process is the same as the owner of <em>stat</em>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">owned?</span> <span class="ruby-comment">#=> true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/etc/passwd"</span>).<span class="ruby-identifier">owned?</span> <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="owned-3F-source">
<pre>static VALUE
rb_stat_owned(VALUE obj)
{
if (get_stat(obj)->st_uid == geteuid()) return Qtrue;
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-pipe-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
pipe? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if the operating system supports pipes and <em>stat</em> is a pipe; <code>false</code> otherwise.</p>
<div class="method-source-code" id="pipe-3F-source">
<pre>static VALUE
rb_stat_p(VALUE obj)
{
#ifdef S_IFIFO
if (S_ISFIFO(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-rdev" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rdev → integer or nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns an integer representing the device type on which <em>stat</em> resides. Returns <code>nil</code> if the operating system doesn't support this feature.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/fd1"</span>).<span class="ruby-identifier">rdev</span> <span class="ruby-comment">#=> 513</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/tty"</span>).<span class="ruby-identifier">rdev</span> <span class="ruby-comment">#=> 1280</span>
</pre>
<div class="method-source-code" id="rdev-source">
<pre>static VALUE
rb_stat_rdev(VALUE self)
{
#ifdef HAVE_STRUCT_STAT_ST_RDEV
return DEVT2NUM(get_stat(self)->st_rdev);
#else
return Qnil;
#endif
}</pre>
</div>
</div>
</div>
<div id="method-i-rdev_major" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rdev_major → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the major part of <code>File_Stat#rdev</code> or <code>nil</code>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/fd1"</span>).<span class="ruby-identifier">rdev_major</span> <span class="ruby-comment">#=> 2</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/tty"</span>).<span class="ruby-identifier">rdev_major</span> <span class="ruby-comment">#=> 5</span>
</pre>
<div class="method-source-code" id="rdev_major-source">
<pre>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
}</pre>
</div>
</div>
</div>
<div id="method-i-rdev_minor" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
rdev_minor → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the minor part of <code>File_Stat#rdev</code> or <code>nil</code>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/fd1"</span>).<span class="ruby-identifier">rdev_minor</span> <span class="ruby-comment">#=> 1</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/dev/tty"</span>).<span class="ruby-identifier">rdev_minor</span> <span class="ruby-comment">#=> 0</span>
</pre>
<div class="method-source-code" id="rdev_minor-source">
<pre>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
}</pre>
</div>
</div>
</div>
<div id="method-i-readable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
readable? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is readable by the effective user id of this process.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">readable?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="readable-3F-source">
<pre>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;
}</pre>
</div>
</div>
</div>
<div id="method-i-readable_real-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
readable_real? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is readable by the real user id of this process.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">readable_real?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="readable_real-3F-source">
<pre>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;
}</pre>
</div>
</div>
</div>
<div id="method-i-setgid-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
setgid? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> has the set-group-id permission bit set, <code>false</code> if it doesn't or if the operating system doesn't support this feature.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/usr/sbin/lpc"</span>).<span class="ruby-identifier">setgid?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="setgid-3F-source">
<pre>static VALUE
rb_stat_sgid(VALUE obj)
{
#ifdef S_ISGID
if (get_stat(obj)->st_mode & S_ISGID) return Qtrue;
#endif
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-setuid-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
setuid? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> has the set-user-id permission bit set, <code>false</code> if it doesn't or if the operating system doesn't support this feature.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/bin/su"</span>).<span class="ruby-identifier">setuid?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="setuid-3F-source">
<pre>static VALUE
rb_stat_suid(VALUE obj)
{
#ifdef S_ISUID
if (get_stat(obj)->st_mode & S_ISUID) return Qtrue;
#endif
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-size" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
size → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the size of <em>stat</em> in bytes.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">size</span> <span class="ruby-comment">#=> 66</span>
</pre>
<div class="method-source-code" id="size-source">
<pre>static VALUE
rb_stat_size(VALUE self)
{
return OFFT2NUM(get_stat(self)->st_size);
}</pre>
</div>
</div>
</div>
<div id="method-i-size-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
size → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the size of <em>stat</em> in bytes.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">size</span> <span class="ruby-comment">#=> 66</span>
</pre>
<div class="method-source-code" id="size-3F-source">
<pre>static VALUE
rb_stat_s(VALUE obj)
{
off_t size = get_stat(obj)->st_size;
if (size == 0) return Qnil;
return OFFT2NUM(size);
}</pre>
</div>
</div>
</div>
<div id="method-i-socket-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
socket? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is a socket, <code>false</code> if it isn't or if the operating system doesn't support this feature.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">socket?</span> <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="socket-3F-source">
<pre>static VALUE
rb_stat_S(VALUE obj)
{
#ifdef S_ISSOCK
if (S_ISSOCK(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-sticky-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
sticky? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> has its sticky bit set, <code>false</code> if it doesn't or if the operating system doesn't support this feature.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">sticky?</span> <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="sticky-3F-source">
<pre>static VALUE
rb_stat_sticky(VALUE obj)
{
#ifdef S_ISVTX
if (get_stat(obj)->st_mode & S_ISVTX) return Qtrue;
#endif
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-symlink-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
symlink? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is a symbolic link, <code>false</code> if it isn't or if the operating system doesn't support this feature. As <a href="../File.html#method-c-stat"><code>File::stat</code></a> automatically follows symbolic links, <a href="Stat.html#method-i-symlink-3F"><code>symlink?</code></a> will always be <code>false</code> for an object returned by <a href="../File.html#method-c-stat"><code>File::stat</code></a>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">"testfile"</span>, <span class="ruby-string">"alink"</span>) <span class="ruby-comment">#=> 0</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"alink"</span>).<span class="ruby-identifier">symlink?</span> <span class="ruby-comment">#=> false</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">lstat</span>(<span class="ruby-string">"alink"</span>).<span class="ruby-identifier">symlink?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="symlink-3F-source">
<pre>static VALUE
rb_stat_l(VALUE obj)
{
#ifdef S_ISLNK
if (S_ISLNK(get_stat(obj)->st_mode)) return Qtrue;
#endif
return Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-i-uid" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
uid → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the numeric user id of the owner of <em>stat</em>.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">uid</span> <span class="ruby-comment">#=> 501</span>
</pre>
<div class="method-source-code" id="uid-source">
<pre>static VALUE
rb_stat_uid(VALUE self)
{
return UIDT2NUM(get_stat(self)->st_uid);
}</pre>
</div>
</div>
</div>
<div id="method-i-world_readable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
world_readable? → integer or nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>If <em>stat</em> is readable by others, returns an integer representing the file permission bits of <em>stat</em>. Returns <code>nil</code> otherwise. The meaning of the bits is platform dependent; on Unix systems, see <code>stat(2)</code>.</p>
<pre class="ruby"><span class="ruby-identifier">m</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/etc/passwd"</span>).<span class="ruby-identifier">world_readable?</span> <span class="ruby-comment">#=> 420</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">"%o"</span>, <span class="ruby-identifier">m</span>) <span class="ruby-comment">#=> "644"</span>
</pre>
<div class="method-source-code" id="world_readable-3F-source">
<pre>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
}</pre>
</div>
</div>
</div>
<div id="method-i-world_writable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
world_writable? → integer or nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>If <em>stat</em> is writable by others, returns an integer representing the file permission bits of <em>stat</em>. Returns <code>nil</code> otherwise. The meaning of the bits is platform dependent; on Unix systems, see <code>stat(2)</code>.</p>
<pre class="ruby"><span class="ruby-identifier">m</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"/tmp"</span>).<span class="ruby-identifier">world_writable?</span> <span class="ruby-comment">#=> 511</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">"%o"</span>, <span class="ruby-identifier">m</span>) <span class="ruby-comment">#=> "777"</span>
</pre>
<div class="method-source-code" id="world_writable-3F-source">
<pre>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
}</pre>
</div>
</div>
</div>
<div id="method-i-writable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
writable? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is writable by the effective user id of this process.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">writable?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="writable-3F-source">
<pre>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;
}</pre>
</div>
</div>
</div>
<div id="method-i-writable_real-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
writable_real? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is writable by the real user id of this process.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">writable_real?</span> <span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="writable_real-3F-source">
<pre>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;
}</pre>
</div>
</div>
</div>
<div id="method-i-zero-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
zero? → true or false
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <em>stat</em> is a zero-length file; <code>false</code> otherwise.</p>
<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">"testfile"</span>).<span class="ruby-identifier">zero?</span> <span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="zero-3F-source">
<pre>static VALUE
rb_stat_z(VALUE obj)
{
if (get_stat(obj)->st_size == 0) return Qtrue;
return Qfalse;
}</pre>
</div>
</div>
</div>
</section>
</section>
</main>
<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>