HEX
Server: Apache
System: Windows NT MAGNETO-ARM 10.0 build 22000 (Windows 10) AMD64
User: Michel (0)
PHP: 7.4.7
Disabled: NONE
Upload Files
File: C:/Ruby27-x64/share/doc/ruby/html/Etc.html
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>module Etc - 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="module">
<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">
    
    
    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-confstr">::confstr</a>
    
    <li ><a href="#method-c-endgrent">::endgrent</a>
    
    <li ><a href="#method-c-endpwent">::endpwent</a>
    
    <li ><a href="#method-c-getgrent">::getgrent</a>
    
    <li ><a href="#method-c-getgrgid">::getgrgid</a>
    
    <li ><a href="#method-c-getgrnam">::getgrnam</a>
    
    <li ><a href="#method-c-getlogin">::getlogin</a>
    
    <li ><a href="#method-c-getpwent">::getpwent</a>
    
    <li ><a href="#method-c-getpwnam">::getpwnam</a>
    
    <li ><a href="#method-c-getpwuid">::getpwuid</a>
    
    <li ><a href="#method-c-group">::group</a>
    
    <li ><a href="#method-c-nprocessors">::nprocessors</a>
    
    <li ><a href="#method-c-passwd">::passwd</a>
    
    <li ><a href="#method-c-setgrent">::setgrent</a>
    
    <li ><a href="#method-c-setpwent">::setpwent</a>
    
    <li ><a href="#method-c-sysconf">::sysconf</a>
    
    <li ><a href="#method-c-sysconfdir">::sysconfdir</a>
    
    <li ><a href="#method-c-systmpdir">::systmpdir</a>
    
    <li ><a href="#method-c-uname">::uname</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="module-Etc">
  <h1 id="module-Etc" class="module">
    module Etc
  </h1>

  <section class="description">
    
<p>The <a href="Etc.html"><code>Etc</code></a> module provides access to information typically stored in files in the /etc directory on Unix systems.</p>

<p>The information accessible consists of the information found in the /etc/passwd and /etc/group files, plus information about the system&#39;s temporary directory (/tmp) and configuration directory (/etc).</p>

<p>The <a href="Etc.html"><code>Etc</code></a> module provides a more reliable way to access information about the logged in user than environment variables such as +$USER+.</p>

<h2 id="module-Etc-label-Example-3A">Example:<span><a href="#module-Etc-label-Example-3A">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;etc&#39;</span>

<span class="ruby-identifier">login</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getlogin</span>
<span class="ruby-identifier">info</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwnam</span>(<span class="ruby-identifier">login</span>)
<span class="ruby-identifier">username</span> = <span class="ruby-identifier">info</span>.<span class="ruby-identifier">gecos</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">/,/</span>).<span class="ruby-identifier">first</span>
<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Hello #{username}, I see your login name is #{login}&quot;</span>
</pre>

<p>Note that the methods provided by this module are not always secure. It should be used for informational purposes, and not for security.</p>

<p>All operations defined in this module are class methods, so that you can include the <a href="Etc.html"><code>Etc</code></a> module into your class.</p>

  </section>

  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="Group">Group
        
        <dd><p><a href="Etc.html#Group"><code>Group</code></a></p>

<p><a href="Etc.html#Group"><code>Group</code></a> is a <a href="Struct.html"><code>Struct</code></a> that is only available when compiled with <code>HAVE_GETGRENT</code>.</p>

<p>The struct contains the following members:</p>
<dl class="rdoc-list note-list"><dt>name
<dd>
<p>contains the name of the group as a <a href="String.html"><code>String</code></a>.</p>
</dd><dt>passwd
<dd>
<p>contains the encrypted password as a <a href="String.html"><code>String</code></a>. An &#39;x&#39; is returned if password access to the group is not available; an empty string is returned if no password is needed to obtain membership of the group.</p>

<p>Must be compiled with <code>HAVE_STRUCT_GROUP_GR_PASSWD</code>.</p>
</dd><dt>gid
<dd>
<p>contains the group&#39;s numeric ID as an integer.</p>
</dd><dt>mem
<dd>
<p>is an <a href="Array.html"><code>Array</code></a> of Strings containing the short login names of the members of the group.</p>
</dd></dl>
        
      
        <dt id="Passwd">Passwd
        
        <dd><p><a href="Etc.html#Passwd"><code>Passwd</code></a></p>

<p><a href="Etc.html#Passwd"><code>Passwd</code></a> is a <a href="Struct.html"><code>Struct</code></a> that contains the following members:</p>
<dl class="rdoc-list note-list"><dt>name
<dd>
<p>contains the short login name of the user as a <a href="String.html"><code>String</code></a>.</p>
</dd><dt>passwd
<dd>
<p>contains the encrypted password of the user as a <a href="String.html"><code>String</code></a>. an &#39;x&#39; is returned if shadow passwords are in use. An &#39;*&#39; is returned if the user cannot log in using a password.</p>
</dd><dt>uid
<dd>
<p>contains the integer user ID (uid) of the user.</p>
</dd><dt>gid
<dd>
<p>contains the integer group ID (gid) of the user&#39;s primary group.</p>
</dd><dt>dir
<dd>
<p>contains the path to the home directory of the user as a <a href="String.html"><code>String</code></a>.</p>
</dd><dt>shell
<dd>
<p>contains the path to the login shell of the user as a <a href="String.html"><code>String</code></a>.</p>
</dd></dl>

<h3 id="label-The+following+members+below+are+optional-2C+and+must+be+compiled+with+special+flags-3A">The following members below are optional, and must be compiled with special flags:<span><a href="#label-The+following+members+below+are+optional-2C+and+must+be+compiled+with+special+flags-3A">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt>gecos
<dd>
<p>contains a longer <a href="String.html"><code>String</code></a> description of the user, such as a full name. Some Unix systems provide structured information in the gecos field, but this is system-dependent. must be compiled with <code>HAVE_STRUCT_PASSWD_PW_GECOS</code></p>
</dd><dt>change
<dd>
<p>password change time(integer) must be compiled with <code>HAVE_STRUCT_PASSWD_PW_CHANGE</code></p>
</dd><dt>quota
<dd>
<p>quota value(integer) must be compiled with <code>HAVE_STRUCT_PASSWD_PW_QUOTA</code></p>
</dd><dt>age
<dd>
<p>password age(integer) must be compiled with <code>HAVE_STRUCT_PASSWD_PW_AGE</code></p>
</dd><dt>class
<dd>
<p>user access class(string) must be compiled with <code>HAVE_STRUCT_PASSWD_PW_CLASS</code></p>
</dd><dt>comment
<dd>
<p>comment(string) must be compiled with <code>HAVE_STRUCT_PASSWD_PW_COMMENT</code></p>
</dd><dt>expire
<dd>
<p>account expiration time(integer) must be compiled with <code>HAVE_STRUCT_PASSWD_PW_EXPIRE</code></p>
</dd></dl>
        
      
        <dt id="VERSION">VERSION
        
        <dd>
        
      
      </dl>
    </section>
    

    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-confstr" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">confstr</span><span
            class="method-args">(p1)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Returns system configuration variable using confstr().</p>

<p><em>name</em> should be a constant under <code>Etc</code> which begins with <code>CS_</code>.</p>

<p>The return value is a string or nil. nil means no configuration-defined value.  (confstr() returns 0 but errno is not set.)</p>

<pre class="ruby"><span class="ruby-constant">Etc</span>.<span class="ruby-identifier">confstr</span>(<span class="ruby-constant">Etc</span><span class="ruby-operator">::</span><span class="ruby-constant">CS_PATH</span>) <span class="ruby-comment">#=&gt; &quot;/bin:/usr/bin&quot;</span>

<span class="ruby-comment"># GNU/Linux</span>
<span class="ruby-constant">Etc</span>.<span class="ruby-identifier">confstr</span>(<span class="ruby-constant">Etc</span><span class="ruby-operator">::</span><span class="ruby-constant">CS_GNU_LIBC_VERSION</span>) <span class="ruby-comment">#=&gt; &quot;glibc 2.18&quot;</span>
<span class="ruby-constant">Etc</span>.<span class="ruby-identifier">confstr</span>(<span class="ruby-constant">Etc</span><span class="ruby-operator">::</span><span class="ruby-constant">CS_GNU_LIBPTHREAD_VERSION</span>) <span class="ruby-comment">#=&gt; &quot;NPTL 2.18&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="confstr-source">
            <pre>static VALUE
etc_confstr(VALUE obj, VALUE arg)
{
    int name;
    char localbuf[128], *buf = localbuf;
    size_t bufsize = sizeof(localbuf), ret;
    VALUE tmp;

    name = NUM2INT(arg);

    errno = 0;
    ret = confstr(name, buf, bufsize);
    if (bufsize &lt; ret) {
        bufsize = ret;
        buf = ALLOCV_N(char, tmp, bufsize);
        errno = 0;
        ret = confstr(name, buf, bufsize);
    }
    if (bufsize &lt; ret)
        rb_bug(&quot;required buffer size for confstr() changed dynamically.&quot;);
    if (ret == 0) {
        if (errno == 0) /* no configuration-defined value */
            return Qnil;
        rb_sys_fail(&quot;confstr&quot;);
    }
    return rb_str_new_cstr(buf);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-endgrent" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">endgrent</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Ends the process of scanning through the /etc/group file begun by <a href="Etc.html#method-c-getgrent"><code>::getgrent</code></a>, and closes the file.</p>
          
          

          
          <div class="method-source-code" id="endgrent-source">
            <pre>static VALUE
etc_endgrent(VALUE obj)
{
#ifdef HAVE_GETGRENT
    endgrent();
#endif
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-endpwent" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">endpwent</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Ends the process of scanning through the /etc/passwd file begun with <a href="Etc.html#method-c-getpwent"><code>::getpwent</code></a>, and closes the file.</p>
          
          

          
          <div class="method-source-code" id="endpwent-source">
            <pre>static VALUE
etc_endpwent(VALUE obj)
{
#ifdef HAVE_GETPWENT
    endpwent();
#endif
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-getgrent" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">getgrent</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Returns an entry from the /etc/group file.</p>

<p>The first time it is called it opens the file and returns the first entry; each successive call returns the next entry, or <code>nil</code> if the end of the file has been reached.</p>

<p>To close the file when processing is complete, call <a href="Etc.html#method-c-endgrent"><code>::endgrent</code></a>.</p>

<p>Each entry is returned as a <a href="Etc.html#Group"><code>Group</code></a> struct</p>
          
          

          
          <div class="method-source-code" id="getgrent-source">
            <pre>static VALUE
etc_getgrent(VALUE obj)
{
#ifdef HAVE_GETGRENT
    struct group *gr;

    if ((gr = getgrent()) != 0) {
        return setup_group(gr);
    }
#endif
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-getgrgid" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            getgrgid(group_id)  &rarr;       Group
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns information about the group with specified integer <code>group_id</code>, as found in /etc/group.</p>

<p>The information is returned as a <a href="Etc.html#Group"><code>Group</code></a> struct.</p>

<p>See the unix manpage for <code>getgrgid(3)</code> for more detail.</p>

<h3 id="method-c-getgrgid-label-Example-3A">Example:<span><a href="#method-c-getgrgid-label-Example-3A">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrgid</span>(<span class="ruby-value">100</span>)
<span class="ruby-comment">#=&gt; #&lt;struct Etc::Group name=&quot;users&quot;, passwd=&quot;x&quot;, gid=100, mem=[&quot;meta&quot;, &quot;root&quot;]&gt;</span>
</pre>
          
          

          
          <div class="method-source-code" id="getgrgid-source">
            <pre>static VALUE
etc_getgrgid(int argc, VALUE *argv, VALUE obj)
{
#ifdef HAVE_GETGRENT
    VALUE id;
    gid_t gid;
    struct group *grp;

    if (rb_scan_args(argc, argv, &quot;01&quot;, &amp;id) == 1) {
        gid = NUM2GIDT(id);
    }
    else {
        gid = getgid();
    }
    grp = getgrgid(gid);
    if (grp == 0) rb_raise(rb_eArgError, &quot;can&#39;t find group for %d&quot;, (int)gid);
    return setup_group(grp);
#else
    return Qnil;
#endif
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-getgrnam" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            getgrnam(name)       &rarr;  Group
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns information about the group with specified <code>name</code>, as found in /etc/group.</p>

<p>The information is returned as a <a href="Etc.html#Group"><code>Group</code></a> struct.</p>

<p>See the unix manpage for <code>getgrnam(3)</code> for more detail.</p>

<h3 id="method-c-getgrnam-label-Example-3A">Example:<span><a href="#method-c-getgrnam-label-Example-3A">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrnam</span>(<span class="ruby-string">&#39;users&#39;</span>)
<span class="ruby-comment">#=&gt; #&lt;struct Etc::Group name=&quot;users&quot;, passwd=&quot;x&quot;, gid=100, mem=[&quot;meta&quot;, &quot;root&quot;]&gt;</span>
</pre>
          
          

          
          <div class="method-source-code" id="getgrnam-source">
            <pre>static VALUE
etc_getgrnam(VALUE obj, VALUE nam)
{
#ifdef HAVE_GETGRENT
    struct group *grp;
    const char *p = StringValueCStr(nam);

    grp = getgrnam(p);
    if (grp == 0) rb_raise(rb_eArgError, &quot;can&#39;t find group for %&quot;PRIsVALUE, nam);
    return setup_group(grp);
#else
    return Qnil;
#endif
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-getlogin" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            getlogin     &rarr;  String
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the short user name of the currently logged in user. Unfortunately, it is often rather easy to fool <a href="Etc.html#method-c-getlogin"><code>::getlogin</code></a>.</p>

<p>Avoid <a href="Etc.html#method-c-getlogin"><code>::getlogin</code></a> for security-related purposes.</p>

<p>If <a href="Etc.html#method-c-getlogin"><code>::getlogin</code></a> fails, try <a href="Etc.html#method-c-getpwuid"><code>::getpwuid</code></a>.</p>

<p>See the unix manpage for <code>getpwuid(3)</code> for more detail.</p>

<p>e.g.</p>

<pre>Etc.getlogin -&gt; &#39;guest&#39;</pre>
          
          

          
          <div class="method-source-code" id="getlogin-source">
            <pre>static VALUE
etc_getlogin(VALUE obj)
{
    char *login;

#ifdef HAVE_GETLOGIN
    login = getlogin();
    if (!login) login = getenv(&quot;USER&quot;);
#else
    login = getenv(&quot;USER&quot;);
#endif

    if (login) {
#ifdef _WIN32
        rb_encoding *extenc = rb_utf8_encoding();
#else
        rb_encoding *extenc = rb_locale_encoding();
#endif
        return rb_external_str_new_with_enc(login, strlen(login), extenc);
    }

    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-getpwent" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">getpwent</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Returns an entry from the /etc/passwd file.</p>

<p>The first time it is called it opens the file and returns the first entry; each successive call returns the next entry, or <code>nil</code> if the end of the file has been reached.</p>

<p>To close the file when processing is complete, call <a href="Etc.html#method-c-endpwent"><code>::endpwent</code></a>.</p>

<p>Each entry is returned as a <a href="Etc.html#Passwd"><code>Passwd</code></a> struct.</p>
          
          

          
          <div class="method-source-code" id="getpwent-source">
            <pre>static VALUE
etc_getpwent(VALUE obj)
{
#ifdef HAVE_GETPWENT
    struct passwd *pw;

    if ((pw = getpwent()) != 0) {
        return setup_passwd(pw);
    }
#endif
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-getpwnam" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            getpwnam(name)       &rarr;  Passwd
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the /etc/passwd information for the user with specified login <code>name</code>.</p>

<p>The information is returned as a <a href="Etc.html#Passwd"><code>Passwd</code></a> struct.</p>

<p>See the unix manpage for <code>getpwnam(3)</code> for more detail.</p>

<h3 id="method-c-getpwnam-label-Example-3A">Example:<span><a href="#method-c-getpwnam-label-Example-3A">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwnam</span>(<span class="ruby-string">&#39;root&#39;</span>)
<span class="ruby-comment">#=&gt; #&lt;struct Etc::Passwd name=&quot;root&quot;, passwd=&quot;x&quot;, uid=0, gid=0, gecos=&quot;root&quot;,dir=&quot;/root&quot;, shell=&quot;/bin/bash&quot;&gt;</span>
</pre>
          
          

          
          <div class="method-source-code" id="getpwnam-source">
            <pre>static VALUE
etc_getpwnam(VALUE obj, VALUE nam)
{
#ifdef HAVE_GETPWENT
    struct passwd *pwd;
    const char *p = StringValueCStr(nam);

    pwd = getpwnam(p);
    if (pwd == 0) rb_raise(rb_eArgError, &quot;can&#39;t find user for %&quot;PRIsVALUE, nam);
    return setup_passwd(pwd);
#else
    return Qnil;
#endif
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-getpwuid" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            getpwuid(uid)        &rarr;  Passwd
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the /etc/passwd information for the user with the given integer <code>uid</code>.</p>

<p>The information is returned as a <a href="Etc.html#Passwd"><code>Passwd</code></a> struct.</p>

<p>If <code>uid</code> is omitted, the value from <code>Passwd[:uid]</code> is returned instead.</p>

<p>See the unix manpage for <code>getpwuid(3)</code> for more detail.</p>

<h3 id="method-c-getpwuid-label-Example-3A">Example:<span><a href="#method-c-getpwuid-label-Example-3A">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwuid</span>(<span class="ruby-value">0</span>)
<span class="ruby-comment">#=&gt; #&lt;struct Etc::Passwd name=&quot;root&quot;, passwd=&quot;x&quot;, uid=0, gid=0, gecos=&quot;root&quot;,dir=&quot;/root&quot;, shell=&quot;/bin/bash&quot;&gt;</span>
</pre>
          
          

          
          <div class="method-source-code" id="getpwuid-source">
            <pre>static VALUE
etc_getpwuid(int argc, VALUE *argv, VALUE obj)
{
#if defined(HAVE_GETPWENT)
    VALUE id;
    rb_uid_t uid;
    struct passwd *pwd;

    if (rb_scan_args(argc, argv, &quot;01&quot;, &amp;id) == 1) {
        uid = NUM2UIDT(id);
    }
    else {
        uid = getuid();
    }
    pwd = getpwuid(uid);
    if (pwd == 0) rb_raise(rb_eArgError, &quot;can&#39;t find user for %d&quot;, (int)uid);
    return setup_passwd(pwd);
#else
    return Qnil;
#endif
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-group" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">group</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Provides a convenient Ruby iterator which executes a block for each entry in the /etc/group file.</p>

<p>The code block is passed an <a href="Etc.html#Group"><code>Group</code></a> struct.</p>

<p>See <a href="Etc.html#method-c-getgrent"><code>::getgrent</code></a> above for details.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;etc&#39;</span>

<span class="ruby-constant">Etc</span>.<span class="ruby-identifier">group</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">g</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-identifier">g</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">+</span> <span class="ruby-string">&quot;: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">g</span>.<span class="ruby-identifier">mem</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&#39;, &#39;</span>)
}
</pre>
          
          

          
          <div class="method-source-code" id="group-source">
            <pre>static VALUE
etc_group(VALUE obj)
{
#ifdef HAVE_GETGRENT
    struct group *grp;

    if (rb_block_given_p()) {
        each_group();
    }
    else if ((grp = getgrent()) != 0) {
        return setup_group(grp);
    }
#endif
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-nprocessors" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">nprocessors</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Returns the number of online processors.</p>

<p>The result is intended as the number of processes to use all available processors.</p>

<p>This method is implemented using:</p>
<ul><li>
<p>sched_getaffinity(): Linux</p>
</li><li>
<p>sysconf(_SC_NPROCESSORS_ONLN): GNU/Linux, NetBSD, FreeBSD, OpenBSD, DragonFly BSD, OpenIndiana, Mac OS X, AIX</p>
</li></ul>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;etc&#39;</span>
<span class="ruby-identifier">p</span> <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">nprocessors</span> <span class="ruby-comment">#=&gt; 4</span>
</pre>

<p>The result might be smaller number than physical cpus especially when ruby process is bound to specific cpus. This is intended for getting better parallel processing.</p>

<p>Example: (Linux)</p>

<pre>linux$ taskset 0x3 ./ruby -retc -e &quot;p Etc.nprocessors&quot;  #=&gt; 2</pre>
          
          

          
          <div class="method-source-code" id="nprocessors-source">
            <pre>static VALUE
etc_nprocessors(VALUE obj)
{
    long ret;

#if !defined(_WIN32)

#if defined(HAVE_SCHED_GETAFFINITY) &amp;&amp; defined(CPU_ALLOC)
    int ncpus;

    ncpus = etc_nprocessors_affin();
    if (ncpus != -1) {
        return INT2NUM(ncpus);
    }
    /* fallback to _SC_NPROCESSORS_ONLN */
#endif

    errno = 0;
    ret = sysconf(_SC_NPROCESSORS_ONLN);
    if (ret == -1) {
        rb_sys_fail(&quot;sysconf(_SC_NPROCESSORS_ONLN)&quot;);
    }
#else
    SYSTEM_INFO si;
    GetSystemInfo(&amp;si);
    ret = (long)si.dwNumberOfProcessors;
#endif
    return LONG2NUM(ret);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-passwd" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            passwd { |struct| block }        &rarr;  Passwd
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            passwd                   &rarr;  Passwd
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Provides a convenient Ruby iterator which executes a block for each entry in the /etc/passwd file.</p>

<p>The code block is passed an <a href="Etc.html#Passwd"><code>Passwd</code></a> struct.</p>

<p>See <a href="Etc.html#method-c-getpwent"><code>::getpwent</code></a> above for details.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;etc&#39;</span>

<span class="ruby-constant">Etc</span>.<span class="ruby-identifier">passwd</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">u</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-identifier">u</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">+</span> <span class="ruby-string">&quot; = &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">u</span>.<span class="ruby-identifier">gecos</span>
}
</pre>
          
          

          
          <div class="method-source-code" id="passwd-source">
            <pre>static VALUE
etc_passwd(VALUE obj)
{
#ifdef HAVE_GETPWENT
    struct passwd *pw;

    if (rb_block_given_p()) {
        each_passwd();
    }
    else if ((pw = getpwent()) != 0) {
        return setup_passwd(pw);
    }
#endif
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-setgrent" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">setgrent</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Resets the process of reading the /etc/group file, so that the next call to <a href="Etc.html#method-c-getgrent"><code>::getgrent</code></a> will return the first entry again.</p>
          
          

          
          <div class="method-source-code" id="setgrent-source">
            <pre>static VALUE
etc_setgrent(VALUE obj)
{
#ifdef HAVE_GETGRENT
    setgrent();
#endif
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-setpwent" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">setpwent</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Resets the process of reading the /etc/passwd file, so that the next call to <a href="Etc.html#method-c-getpwent"><code>::getpwent</code></a> will return the first entry again.</p>
          
          

          
          <div class="method-source-code" id="setpwent-source">
            <pre>static VALUE
etc_setpwent(VALUE obj)
{
#ifdef HAVE_GETPWENT
    setpwent();
#endif
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-sysconf" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">sysconf</span><span
            class="method-args">(p1)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Returns system configuration variable using sysconf().</p>

<p><em>name</em> should be a constant under <code>Etc</code> which begins with <code>SC_</code>.</p>

<p>The return value is an integer or nil. nil means indefinite limit.  (sysconf() returns -1 but errno is not set.)</p>

<pre class="ruby"><span class="ruby-constant">Etc</span>.<span class="ruby-identifier">sysconf</span>(<span class="ruby-constant">Etc</span><span class="ruby-operator">::</span><span class="ruby-constant">SC_ARG_MAX</span>) <span class="ruby-comment">#=&gt; 2097152</span>
<span class="ruby-constant">Etc</span>.<span class="ruby-identifier">sysconf</span>(<span class="ruby-constant">Etc</span><span class="ruby-operator">::</span><span class="ruby-constant">SC_LOGIN_NAME_MAX</span>) <span class="ruby-comment">#=&gt; 256</span>
</pre>
          
          

          
          <div class="method-source-code" id="sysconf-source">
            <pre>static VALUE
etc_sysconf(VALUE obj, VALUE arg)
{
    int name;
    long ret;

    name = NUM2INT(arg);

    errno = 0;
    ret = sysconf(name);
    if (ret == -1) {
        if (errno == 0) /* no limit */
            return Qnil;
        rb_sys_fail(&quot;sysconf&quot;);
    }
    return LONG2NUM(ret);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-sysconfdir" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">sysconfdir</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Returns system configuration directory.</p>

<p>This is typically “/etc”, but is modified by the prefix used when Ruby was compiled. For example, if Ruby is built and installed in /usr/local, returns “/usr/local/etc” on other platforms than Windows. On Windows, this always returns the directory provided by the system.</p>
          
          

          
          <div class="method-source-code" id="sysconfdir-source">
            <pre>static VALUE
etc_sysconfdir(VALUE obj)
{
#ifdef _WIN32
    return rb_w32_special_folder(CSIDL_COMMON_APPDATA);
#else
    return rb_filesystem_str_new_cstr(SYSCONFDIR);
#endif
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-systmpdir" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">systmpdir</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Returns system temporary directory; typically “/tmp”.</p>
          
          

          
          <div class="method-source-code" id="systmpdir-source">
            <pre>static VALUE
etc_systmpdir(VALUE _)
{
    VALUE tmpdir;
#ifdef _WIN32
    WCHAR path[_MAX_PATH];
    UINT len = rb_w32_system_tmpdir(path, numberof(path));
    if (!len) return Qnil;
    tmpdir = rb_w32_conv_from_wchar(path, rb_filesystem_encoding());
#else
    const char default_tmp[] = &quot;/tmp&quot;;
    const char *tmpstr = default_tmp;
    size_t tmplen = strlen(default_tmp);
# if defined _CS_DARWIN_USER_TEMP_DIR
    #ifndef MAXPATHLEN
    #define MAXPATHLEN 1024
    #endif
    char path[MAXPATHLEN];
    size_t len;
    len = confstr(_CS_DARWIN_USER_TEMP_DIR, path, sizeof(path));
    if (len &gt; 0) {
        tmpstr = path;
        tmplen = len - 1;
        if (len &gt; sizeof(path)) tmpstr = 0;
    }
# endif
    tmpdir = rb_filesystem_str_new(tmpstr, tmplen);
# if defined _CS_DARWIN_USER_TEMP_DIR
    if (!tmpstr) {
        confstr(_CS_DARWIN_USER_TEMP_DIR, RSTRING_PTR(tmpdir), len);
    }
# endif
#endif
#ifndef RB_PASS_KEYWORDS
    /* untaint on Ruby &lt; 2.7 */
    FL_UNSET(tmpdir, FL_TAINT);
#endif
    return tmpdir;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-uname" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">uname</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Returns the system information obtained by uname system call.</p>

<p>The return value is a hash which has 5 keys at least:</p>

<pre>:sysname, :nodename, :release, :version, :machine</pre>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;etc&#39;</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">&#39;pp&#39;</span>

<span class="ruby-identifier">pp</span> <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">uname</span>
<span class="ruby-comment">#=&gt; {:sysname=&gt;&quot;Linux&quot;,</span>
<span class="ruby-comment">#    :nodename=&gt;&quot;boron&quot;,</span>
<span class="ruby-comment">#    :release=&gt;&quot;2.6.18-6-xen-686&quot;,</span>
<span class="ruby-comment">#    :version=&gt;&quot;#1 SMP Thu Nov 5 19:54:42 UTC 2009&quot;,</span>
<span class="ruby-comment">#    :machine=&gt;&quot;i686&quot;}</span>
</pre>
          
          

          
          <div class="method-source-code" id="uname-source">
            <pre>static VALUE
etc_uname(VALUE obj)
{
#ifdef _WIN32
    OSVERSIONINFOW v;
    SYSTEM_INFO s;
    const char *sysname, *mach;
    VALUE result, release, version;
    VALUE vbuf, nodename = Qnil;
    DWORD len = 0;
    WCHAR *buf;

    v.dwOSVersionInfoSize = sizeof(v);
    if (!GetVersionExW(&amp;v))
        rb_sys_fail(&quot;GetVersionEx&quot;);

    result = rb_hash_new();
    switch (v.dwPlatformId) {
      case VER_PLATFORM_WIN32s:
        sysname = &quot;Win32s&quot;;
        break;
      case VER_PLATFORM_WIN32_NT:
        sysname = &quot;Windows_NT&quot;;
        break;
      case VER_PLATFORM_WIN32_WINDOWS:
      default:
        sysname = &quot;Windows&quot;;
        break;
    }
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;sysname&quot;)), rb_str_new_cstr(sysname));
    release = rb_sprintf(&quot;%lu.%lu.%lu&quot;, v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;release&quot;)), release);
    version = rb_sprintf(&quot;%s Version %&quot;PRIsVALUE&quot;: %&quot;PRIsVALUE, sysname, release,
                         rb_w32_conv_from_wchar(v.szCSDVersion, rb_utf8_encoding()));
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;version&quot;)), version);

# if defined _MSC_VER &amp;&amp; _MSC_VER &lt; 1300
#   define GET_COMPUTER_NAME(ptr, plen) GetComputerNameW(ptr, plen)
# else
#   define GET_COMPUTER_NAME(ptr, plen) GetComputerNameExW(ComputerNameDnsFullyQualified, ptr, plen)
# endif
    GET_COMPUTER_NAME(NULL, &amp;len);
    buf = ALLOCV_N(WCHAR, vbuf, len);
    if (GET_COMPUTER_NAME(buf, &amp;len)) {
        nodename = rb_w32_conv_from_wchar(buf, rb_utf8_encoding());
    }
    ALLOCV_END(vbuf);
    if (NIL_P(nodename)) nodename = rb_str_new(0, 0);
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;nodename&quot;)), nodename);

# ifndef PROCESSOR_ARCHITECTURE_AMD64
#   define PROCESSOR_ARCHITECTURE_AMD64 9
# endif
# ifndef PROCESSOR_ARCHITECTURE_INTEL
#   define PROCESSOR_ARCHITECTURE_INTEL 0
# endif
    GetSystemInfo(&amp;s);
    switch (s.wProcessorArchitecture) {
      case PROCESSOR_ARCHITECTURE_AMD64:
        mach = &quot;x64&quot;;
        break;
      case PROCESSOR_ARCHITECTURE_ARM:
        mach = &quot;ARM&quot;;
        break;
      case PROCESSOR_ARCHITECTURE_INTEL:
        mach = &quot;x86&quot;;
        break;
      default:
        mach = &quot;unknown&quot;;
        break;
    }

    rb_hash_aset(result, ID2SYM(rb_intern(&quot;machine&quot;)), rb_str_new_cstr(mach));
#else
    struct utsname u;
    int ret;
    VALUE result;

    ret = uname(&amp;u);
    if (ret == -1)
        rb_sys_fail(&quot;uname&quot;);

    result = rb_hash_new();
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;sysname&quot;)), rb_str_new_cstr(u.sysname));
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;nodename&quot;)), rb_str_new_cstr(u.nodename));
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;release&quot;)), rb_str_new_cstr(u.release));
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;version&quot;)), rb_str_new_cstr(u.version));
    rb_hash_aset(result, ID2SYM(rb_intern(&quot;machine&quot;)), rb_str_new_cstr(u.machine));
#endif

    return result;
}</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>