ext/etc/etc.c in etc-1.4.3 vs ext/etc/etc.c in etc-1.4.4
- old
+ new
@@ -54,11 +54,11 @@
# include <stdlib.h>
# endif
#endif
RUBY_EXTERN char *getlogin(void);
-#define RUBY_ETC_VERSION "1.4.3"
+#define RUBY_ETC_VERSION "1.4.4"
#ifdef HAVE_RB_DEPRECATE_CONSTANT
void rb_deprecate_constant(VALUE mod, const char *name);
#else
# define rb_deprecate_constant(mod,name) ((void)(mod),(void)(name))
@@ -201,11 +201,11 @@
);
}
#endif
/* call-seq:
- * getpwuid(uid) -> Passwd
+ * getpwuid(uid) -> Etc::Passwd
*
* Returns the <tt>/etc/passwd</tt> information for the user with the given
* integer +uid+.
*
* The information is returned as a Passwd struct.
@@ -213,11 +213,11 @@
* If +uid+ is omitted, the value from <code>Passwd[:uid]</code> is returned
* instead.
*
* See the unix manpage for <code>getpwuid(3)</code> for more detail.
*
- * === Example:
+ * *Example:*
*
* Etc.getpwuid(0)
* #=> #<struct Etc::Passwd name="root", passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
*/
static VALUE
@@ -241,20 +241,20 @@
return Qnil;
#endif
}
/* call-seq:
- * getpwnam(name) -> Passwd
+ * getpwnam(name) -> Etc::Passwd
*
* Returns the <tt>/etc/passwd</tt> information for the user with specified
* login +name+.
*
* The information is returned as a Passwd struct.
*
* See the unix manpage for <code>getpwnam(3)</code> for more detail.
*
- * === Example:
+ * *Example:*
*
* Etc.getpwnam('root')
* #=> #<struct Etc::Passwd name="root", passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
*/
static VALUE
@@ -305,21 +305,21 @@
rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
}
#endif
/* call-seq:
- * Etc.passwd { |struct| block } -> Passwd
- * Etc.passwd -> Passwd
+ * passwd { |struct| block }
+ * passwd -> Etc::Passwd
*
* Provides a convenient Ruby iterator which executes a block for each entry
* in the <tt>/etc/passwd</tt> file.
*
* The code block is passed an Passwd struct.
*
* See ::getpwent above for details.
*
- * Example:
+ * *Example:*
*
* require 'etc'
*
* Etc.passwd {|u|
* puts u.name + " = " + u.gecos
@@ -341,11 +341,11 @@
#endif
return Qnil;
}
/* call-seq:
- * Etc::Passwd.each { |struct| block } -> Passwd
+ * Etc::Passwd.each { |struct| block } -> Etc::Passwd
* Etc::Passwd.each -> Enumerator
*
* Iterates for each entry in the <tt>/etc/passwd</tt> file if a block is
* given.
*
@@ -353,11 +353,11 @@
*
* The code block is passed an Passwd struct.
*
* See Etc.getpwent above for details.
*
- * Example:
+ * *Example:*
*
* require 'etc'
*
* Etc::Passwd.each {|u|
* puts u.name + " = " + u.gecos
@@ -375,11 +375,14 @@
each_passwd();
#endif
return obj;
}
-/* Resets the process of reading the <tt>/etc/passwd</tt> file, so that the
+/* call-seq:
+ * setpwent
+ *
+ * Resets the process of reading the <tt>/etc/passwd</tt> file, so that the
* next call to ::getpwent will return the first entry again.
*/
static VALUE
etc_setpwent(VALUE obj)
{
@@ -387,11 +390,14 @@
setpwent();
#endif
return Qnil;
}
-/* Ends the process of scanning through the <tt>/etc/passwd</tt> file begun
+/* call-seq:
+ * endpwent
+ *
+ * Ends the process of scanning through the <tt>/etc/passwd</tt> file begun
* with ::getpwent, and closes the file.
*/
static VALUE
etc_endpwent(VALUE obj)
{
@@ -399,12 +405,15 @@
endpwent();
#endif
return Qnil;
}
-/* Returns an entry from the <tt>/etc/passwd</tt> file.
+/* call-seq:
+ * getpwent -> Etc::Passwd
*
+ * Returns an entry from the <tt>/etc/passwd</tt> file.
+ *
* The first time it is called it opens the file and returns the first entry;
* each successive call returns the next entry, or +nil+ if the end of the file
* has been reached.
*
* To close the file when processing is complete, call ::endpwent.
@@ -447,20 +456,20 @@
mem);
}
#endif
/* call-seq:
- * getgrgid(group_id) -> Group
+ * getgrgid(group_id) -> Etc::Group
*
* Returns information about the group with specified integer +group_id+,
* as found in <tt>/etc/group</tt>.
*
* The information is returned as a Group struct.
*
* See the unix manpage for <code>getgrgid(3)</code> for more detail.
*
- * === Example:
+ * *Example:*
*
* Etc.getgrgid(100)
* #=> #<struct Etc::Group name="users", passwd="x", gid=100, mem=["meta", "root"]>
*
*/
@@ -485,20 +494,20 @@
return Qnil;
#endif
}
/* call-seq:
- * getgrnam(name) -> Group
+ * getgrnam(name) -> Etc::Group
*
* Returns information about the group with specified +name+, as found in
* <tt>/etc/group</tt>.
*
* The information is returned as a Group struct.
*
* See the unix manpage for <code>getgrnam(3)</code> for more detail.
*
- * === Example:
+ * *Example:*
*
* Etc.getgrnam('users')
* #=> #<struct Etc::Group name="users", passwd="x", gid=100, mem=["meta", "root"]>
*
*/
@@ -527,11 +536,10 @@
rb_raise(rb_eRuntimeError, "unexpected group_blocking");
}
return Qnil;
}
-
static VALUE
group_iterate(VALUE _)
{
struct group *pw;
@@ -550,18 +558,22 @@
}
rb_ensure(group_iterate, 0, group_ensure, 0);
}
#endif
-/* Provides a convenient Ruby iterator which executes a block for each entry
+/* call-seq:
+ * group { |struct| block }
+ * group -> Etc::Group
+ *
+ * Provides a convenient Ruby iterator which executes a block for each entry
* in the <tt>/etc/group</tt> file.
*
* The code block is passed an Group struct.
*
* See ::getgrent above for details.
*
- * Example:
+ * *Example:*
*
* require 'etc'
*
* Etc.group {|g|
* puts g.name + ": " + g.mem.join(', ')
@@ -584,21 +596,21 @@
return Qnil;
}
#ifdef HAVE_GETGRENT
/* call-seq:
- * Etc::Group.each { |group| block } -> obj
+ * Etc::Group.each { |group| block } -> Etc::Group
* Etc::Group.each -> Enumerator
*
* Iterates for each entry in the <tt>/etc/group</tt> file if a block is
* given.
*
* If no block is given, returns the Enumerator.
*
* The code block is passed a Group struct.
*
- * Example:
+ * *Example:*
*
* require 'etc'
*
* Etc::Group.each {|g|
* puts g.name + ": " + g.mem.join(', ')
@@ -615,11 +627,14 @@
each_group();
return obj;
}
#endif
-/* Resets the process of reading the <tt>/etc/group</tt> file, so that the
+/* call-seq:
+ * setgrent
+ *
+ * Resets the process of reading the <tt>/etc/group</tt> file, so that the
* next call to ::getgrent will return the first entry again.
*/
static VALUE
etc_setgrent(VALUE obj)
{
@@ -627,11 +642,14 @@
setgrent();
#endif
return Qnil;
}
-/* Ends the process of scanning through the <tt>/etc/group</tt> file begun
+/* call-seq:
+ * endgrent
+ *
+ * Ends the process of scanning through the <tt>/etc/group</tt> file begun
* by ::getgrent, and closes the file.
*/
static VALUE
etc_endgrent(VALUE obj)
{
@@ -639,12 +657,15 @@
endgrent();
#endif
return Qnil;
}
-/* Returns an entry from the <tt>/etc/group</tt> file.
+/* call-seq:
+ * getgrent -> Etc::Group
*
+ * Returns an entry from the <tt>/etc/group</tt> file.
+ *
* The first time it is called it opens the file and returns the first entry;
* each successive call returns the next entry, or +nil+ if the end of the file
* has been reached.
*
* To close the file when processing is complete, call ::endgrent.
@@ -668,13 +689,25 @@
#ifdef _WIN32
VALUE rb_w32_special_folder(int type);
UINT rb_w32_system_tmpdir(WCHAR *path, UINT len);
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
+#elif defined(LOAD_RELATIVE)
+static inline VALUE
+rbconfig(void)
+{
+ VALUE config;
+ rb_require("rbconfig");
+ config = rb_const_get(rb_path2class("RbConfig"), rb_intern("CONFIG"));
+ Check_Type(config, T_HASH);
+ return config;
+}
#endif
-/*
+/* call-seq:
+ * sysconfdir -> String
+ *
* Returns system configuration directory.
*
* This is typically <code>"/etc"</code>, but is modified by the prefix used
* when Ruby was compiled. For example, if Ruby is built and installed in
* <tt>/usr/local</tt>, returns <code>"/usr/local/etc"</code> on other
@@ -685,16 +718,20 @@
static VALUE
etc_sysconfdir(VALUE obj)
{
#ifdef _WIN32
return rb_w32_special_folder(CSIDL_COMMON_APPDATA);
+#elif defined(LOAD_RELATIVE)
+ return rb_hash_aref(rbconfig(), rb_str_new_lit("sysconfdir"));
#else
return rb_filesystem_str_new_cstr(SYSCONFDIR);
#endif
}
-/*
+/* call-seq:
+ * systmpdir -> String
+ *
* Returns system temporary directory; typically "/tmp".
*/
static VALUE
etc_systmpdir(VALUE _)
{
@@ -734,17 +771,19 @@
#endif
return tmpdir;
}
#ifdef HAVE_UNAME
-/*
+/* call-seq:
+ * uname -> hash
+ *
* Returns the system information obtained by uname system call.
*
* The return value is a hash which has 5 keys at least:
* :sysname, :nodename, :release, :version, :machine
*
- * Example:
+ * *Example:*
*
* require 'etc'
* require 'pp'
*
* pp Etc.uname
@@ -850,11 +889,13 @@
#else
#define etc_uname rb_f_notimplement
#endif
#ifdef HAVE_SYSCONF
-/*
+/* call-seq:
+ * sysconf(name) -> Integer
+ *
* Returns system configuration variable using sysconf().
*
* _name_ should be a constant under <code>Etc</code> which begins with <code>SC_</code>.
*
* The return value is an integer or nil.
@@ -884,11 +925,13 @@
#else
#define etc_sysconf rb_f_notimplement
#endif
#ifdef HAVE_CONFSTR
-/*
+/* call-seq:
+ * confstr(name) -> String
+ *
* Returns system configuration variable using confstr().
*
* _name_ should be a constant under <code>Etc</code> which begins with <code>CS_</code>.
*
* The return value is a string or nil.
@@ -931,11 +974,13 @@
#else
#define etc_confstr rb_f_notimplement
#endif
#ifdef HAVE_FPATHCONF
-/*
+/* call-seq:
+ * pathconf(name) -> Integer
+ *
* Returns pathname configuration variable using fpathconf().
*
* _name_ should be a constant under <code>Etc</code> which begins with <code>PC_</code>.
*
* The return value is an integer or nil.
@@ -1023,30 +1068,32 @@
return ret;
}
#endif
-/*
+/* call-seq:
+ * nprocessors -> Integer
+ *
* Returns the number of online processors.
*
* The result is intended as the number of processes to
* use all available processors.
*
* This method is implemented using:
* - sched_getaffinity(): Linux
* - sysconf(_SC_NPROCESSORS_ONLN): GNU/Linux, NetBSD, FreeBSD, OpenBSD, DragonFly BSD, OpenIndiana, Mac OS X, AIX
*
- * Example:
+ * *Example:*
*
* require 'etc'
* p Etc.nprocessors #=> 4
*
* 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.
*
- * Example: (Linux)
+ * *Example:* (Linux)
*
* linux$ taskset 0x3 ./ruby -retc -e "p Etc.nprocessors" #=> 2
*
*/
static VALUE
@@ -1092,11 +1139,11 @@
* directory (<tt>/etc</tt>).
*
* The Etc module provides a more reliable way to access information about
* the logged in user than environment variables such as +$USER+.
*
- * == Example:
+ * *Example:*
*
* require 'etc'
*
* login = Etc.getlogin
* info = Etc.getpwnam(login)
@@ -1116,9 +1163,10 @@
#ifdef HAVE_RB_EXT_RACTOR_SAFE
RB_EXT_RACTOR_SAFE(true);
#endif
mEtc = rb_define_module("Etc");
+ /* The version */
rb_define_const(mEtc, "VERSION", rb_str_new_cstr(RUBY_ETC_VERSION));
init_constants(mEtc);
rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0);