Ruby  2.1.4p265(2014-10-27revision48166)
etc.c
Go to the documentation of this file.
1 /************************************************
2 
3  etc.c -
4 
5  $Author: nobu $
6  created at: Tue Mar 22 18:39:19 JST 1994
7 
8 ************************************************/
9 
10 #include "ruby.h"
11 #include "ruby/encoding.h"
12 
13 #include <sys/types.h>
14 #ifdef HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17 
18 #ifdef HAVE_GETPWENT
19 #include <pwd.h>
20 #endif
21 
22 #ifdef HAVE_GETGRENT
23 #include <grp.h>
24 #endif
25 
26 static VALUE sPasswd;
27 #ifdef HAVE_GETGRENT
28 static VALUE sGroup;
29 #endif
30 
31 #ifdef _WIN32
32 #include <shlobj.h>
33 #ifndef CSIDL_COMMON_APPDATA
34 #define CSIDL_COMMON_APPDATA 35
35 #endif
36 #endif
37 
38 #ifndef _WIN32
39 char *getenv();
40 #endif
41 char *getlogin();
42 
43 /* call-seq:
44  * getlogin -> String
45  *
46  * Returns the short user name of the currently logged in user.
47  * Unfortunately, it is often rather easy to fool ::getlogin.
48  *
49  * Avoid ::getlogin for security-related purposes.
50  *
51  * If ::getlogin fails, try ::getpwuid.
52  *
53  * See the unix manpage for <code>getpwuid(3)</code> for more detail.
54  *
55  * e.g.
56  * Etc.getlogin -> 'guest'
57  */
58 static VALUE
60 {
61  char *login;
62 
63 #ifdef HAVE_GETLOGIN
64  login = getlogin();
65  if (!login) login = getenv("USER");
66 #else
67  login = getenv("USER");
68 #endif
69 
70  if (login)
71  return rb_tainted_str_new2(login);
72  return Qnil;
73 }
74 
75 #if defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT)
76 static VALUE
77 safe_setup_str(const char *str)
78 {
79  if (str == 0) str = "";
80  return rb_tainted_str_new2(str);
81 }
82 
83 static VALUE
84 safe_setup_locale_str(const char *str)
85 {
86  if (str == 0) str = "";
87  return rb_locale_str_new_cstr(str);
88 }
89 
90 static VALUE
91 safe_setup_filesystem_str(const char *str)
92 {
93  if (str == 0) str = "";
94  return rb_filesystem_str_new_cstr(str);
95 }
96 #endif
97 
98 #ifdef HAVE_GETPWENT
99 static VALUE
100 setup_passwd(struct passwd *pwd)
101 {
102  if (pwd == 0) rb_sys_fail("/etc/passwd");
103  return rb_struct_new(sPasswd,
104  safe_setup_locale_str(pwd->pw_name),
105 #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
106  safe_setup_str(pwd->pw_passwd),
107 #endif
108  UIDT2NUM(pwd->pw_uid),
109  GIDT2NUM(pwd->pw_gid),
110 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
111  safe_setup_locale_str(pwd->pw_gecos),
112 #endif
113  safe_setup_filesystem_str(pwd->pw_dir),
114  safe_setup_filesystem_str(pwd->pw_shell),
115 #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
116  INT2NUM(pwd->pw_change),
117 #endif
118 #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
119  INT2NUM(pwd->pw_quota),
120 #endif
121 #ifdef HAVE_STRUCT_PASSWD_PW_AGE
122  PW_AGE2VAL(pwd->pw_age),
123 #endif
124 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
125  safe_setup_locale_str(pwd->pw_class),
126 #endif
127 #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
128  safe_setup_locale_str(pwd->pw_comment),
129 #endif
130 #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
131  INT2NUM(pwd->pw_expire),
132 #endif
133  0 /*dummy*/
134  );
135 }
136 #endif
137 
138 /* call-seq:
139  * getpwuid(uid) -> Passwd
140  *
141  * Returns the /etc/passwd information for the user with the given integer +uid+.
142  *
143  * The information is returned as a Passwd struct.
144  *
145  * If +uid+ is omitted, the value from <code>Passwd[:uid]</code> is returned
146  * instead.
147  *
148  * See the unix manpage for <code>getpwuid(3)</code> for more detail.
149  *
150  * === Example:
151  *
152  * Etc.getpwuid(0)
153  * #=> #<struct Etc::Passwd name="root", passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
154  */
155 static VALUE
157 {
158 #if defined(HAVE_GETPWENT)
159  VALUE id;
160  rb_uid_t uid;
161  struct passwd *pwd;
162 
163  if (rb_scan_args(argc, argv, "01", &id) == 1) {
164  uid = NUM2UIDT(id);
165  }
166  else {
167  uid = getuid();
168  }
169  pwd = getpwuid(uid);
170  if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %d", (int)uid);
171  return setup_passwd(pwd);
172 #else
173  return Qnil;
174 #endif
175 }
176 
177 /* call-seq:
178  * getpwnam(name) -> Passwd
179  *
180  * Returns the /etc/passwd information for the user with specified login
181  * +name+.
182  *
183  * The information is returned as a Passwd struct.
184  *
185  * See the unix manpage for <code>getpwnam(3)</code> for more detail.
186  *
187  * === Example:
188  *
189  * Etc.getpwnam('root')
190  * #=> #<struct Etc::Passwd name="root", passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
191  */
192 static VALUE
194 {
195 #ifdef HAVE_GETPWENT
196  struct passwd *pwd;
197 
198  SafeStringValue(nam);
199  pwd = getpwnam(RSTRING_PTR(nam));
200  if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, nam);
201  return setup_passwd(pwd);
202 #else
203  return Qnil;
204 #endif
205 }
206 
207 #ifdef HAVE_GETPWENT
208 static int passwd_blocking = 0;
209 static VALUE
210 passwd_ensure(void)
211 {
212  endpwent();
213  passwd_blocking = (int)Qfalse;
214  return Qnil;
215 }
216 
217 static VALUE
218 passwd_iterate(void)
219 {
220  struct passwd *pw;
221 
222  setpwent();
223  while (pw = getpwent()) {
224  rb_yield(setup_passwd(pw));
225  }
226  return Qnil;
227 }
228 
229 static void
230 each_passwd(void)
231 {
232  if (passwd_blocking) {
233  rb_raise(rb_eRuntimeError, "parallel passwd iteration");
234  }
235  passwd_blocking = (int)Qtrue;
236  rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
237 }
238 #endif
239 
240 /* call-seq:
241  * Etc.passwd { |struct| block } -> Passwd
242  * Etc.passwd -> Passwd
243  *
244  * Provides a convenient Ruby iterator which executes a block for each entry
245  * in the /etc/passwd file.
246  *
247  * The code block is passed an Passwd struct.
248  *
249  * See ::getpwent above for details.
250  *
251  * Example:
252  *
253  * require 'etc'
254  *
255  * Etc.passwd {|u|
256  * puts u.name + " = " + u.gecos
257  * }
258  *
259  */
260 static VALUE
262 {
263 #ifdef HAVE_GETPWENT
264  struct passwd *pw;
265 
266  if (rb_block_given_p()) {
267  each_passwd();
268  }
269  else if (pw = getpwent()) {
270  return setup_passwd(pw);
271  }
272 #endif
273  return Qnil;
274 }
275 
276 /* call-seq:
277  * Etc::Passwd.each { |struct| block } -> Passwd
278  * Etc::Passwd.each -> Enumerator
279  *
280  * Iterates for each entry in the /etc/passwd file if a block is given.
281  *
282  * If no block is given, returns the Enumerator.
283  *
284  * The code block is passed an Passwd struct.
285  *
286  * See ::getpwent above for details.
287  *
288  * Example:
289  *
290  * require 'etc'
291  *
292  * Etc::Passwd.each {|u|
293  * puts u.name + " = " + u.gecos
294  * }
295  *
296  * Etc::Passwd.collect {|u| u.gecos}
297  * Etc::Passwd.collect {|u| u.gecos}
298  *
299  */
300 static VALUE
302 {
303 #ifdef HAVE_GETPWENT
304  RETURN_ENUMERATOR(obj, 0, 0);
305  each_passwd();
306 #endif
307  return obj;
308 }
309 
310 /* Resets the process of reading the /etc/passwd file, so that the next call
311  * to ::getpwent will return the first entry again.
312  */
313 static VALUE
315 {
316 #ifdef HAVE_GETPWENT
317  setpwent();
318 #endif
319  return Qnil;
320 }
321 
322 /* Ends the process of scanning through the /etc/passwd file begun with
323  * ::getpwent, and closes the file.
324  */
325 static VALUE
327 {
328 #ifdef HAVE_GETPWENT
329  endpwent();
330 #endif
331  return Qnil;
332 }
333 
334 /* Returns an entry from the /etc/passwd file.
335  *
336  * The first time it is called it opens the file and returns the first entry;
337  * each successive call returns the next entry, or +nil+ if the end of the file
338  * has been reached.
339  *
340  * To close the file when processing is complete, call ::endpwent.
341  *
342  * Each entry is returned as a Passwd struct.
343  *
344  */
345 static VALUE
347 {
348 #ifdef HAVE_GETPWENT
349  struct passwd *pw;
350 
351  if (pw = getpwent()) {
352  return setup_passwd(pw);
353  }
354 #endif
355  return Qnil;
356 }
357 
358 #ifdef HAVE_GETGRENT
359 static VALUE
360 setup_group(struct group *grp)
361 {
362  VALUE mem;
363  char **tbl;
364 
365  mem = rb_ary_new();
366  tbl = grp->gr_mem;
367  while (*tbl) {
368  rb_ary_push(mem, safe_setup_locale_str(*tbl));
369  tbl++;
370  }
371  return rb_struct_new(sGroup,
372  safe_setup_locale_str(grp->gr_name),
373 #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
374  safe_setup_str(grp->gr_passwd),
375 #endif
376  GIDT2NUM(grp->gr_gid),
377  mem);
378 }
379 #endif
380 
381 /* call-seq:
382  * getgrgid(group_id) -> Group
383  *
384  * Returns information about the group with specified integer +group_id+,
385  * as found in /etc/group.
386  *
387  * The information is returned as a Group struct.
388  *
389  * See the unix manpage for <code>getgrgid(3)</code> for more detail.
390  *
391  * === Example:
392  *
393  * Etc.getgrgid(100)
394  * #=> #<struct Etc::Group name="users", passwd="x", gid=100, mem=["meta", "root"]>
395  *
396  */
397 static VALUE
399 {
400 #ifdef HAVE_GETGRENT
401  VALUE id;
402  gid_t gid;
403  struct group *grp;
404 
405  if (rb_scan_args(argc, argv, "01", &id) == 1) {
406  gid = NUM2GIDT(id);
407  }
408  else {
409  gid = getgid();
410  }
411  grp = getgrgid(gid);
412  if (grp == 0) rb_raise(rb_eArgError, "can't find group for %d", (int)gid);
413  return setup_group(grp);
414 #else
415  return Qnil;
416 #endif
417 }
418 
419 /* call-seq:
420  * getgrnam(name) -> Group
421  *
422  * Returns information about the group with specified +name+, as found in
423  * /etc/group.
424  *
425  * The information is returned as a Group struct.
426  *
427  * See the unix manpage for <code>getgrnam(3)</code> for more detail.
428  *
429  * === Example:
430  *
431  * Etc.getgrnam('users')
432  * #=> #<struct Etc::Group name="users", passwd="x", gid=100, mem=["meta", "root"]>
433  *
434  */
435 static VALUE
437 {
438 #ifdef HAVE_GETGRENT
439  struct group *grp;
440 
441  SafeStringValue(nam);
442  grp = getgrnam(RSTRING_PTR(nam));
443  if (grp == 0) rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, nam);
444  return setup_group(grp);
445 #else
446  return Qnil;
447 #endif
448 }
449 
450 #ifdef HAVE_GETGRENT
451 static int group_blocking = 0;
452 static VALUE
453 group_ensure(void)
454 {
455  endgrent();
456  group_blocking = (int)Qfalse;
457  return Qnil;
458 }
459 
460 
461 static VALUE
462 group_iterate(void)
463 {
464  struct group *pw;
465 
466  setgrent();
467  while (pw = getgrent()) {
468  rb_yield(setup_group(pw));
469  }
470  return Qnil;
471 }
472 
473 static void
474 each_group(void)
475 {
476  if (group_blocking) {
477  rb_raise(rb_eRuntimeError, "parallel group iteration");
478  }
479  group_blocking = (int)Qtrue;
480  rb_ensure(group_iterate, 0, group_ensure, 0);
481 }
482 #endif
483 
484 /* Provides a convenient Ruby iterator which executes a block for each entry
485  * in the /etc/group file.
486  *
487  * The code block is passed an Group struct.
488  *
489  * See ::getgrent above for details.
490  *
491  * Example:
492  *
493  * require 'etc'
494  *
495  * Etc.group {|g|
496  * puts g.name + ": " + g.mem.join(', ')
497  * }
498  *
499  */
500 static VALUE
502 {
503 #ifdef HAVE_GETGRENT
504  struct group *grp;
505 
506  if (rb_block_given_p()) {
507  each_group();
508  }
509  else if (grp = getgrent()) {
510  return setup_group(grp);
511  }
512 #endif
513  return Qnil;
514 }
515 
516 #ifdef HAVE_GETGRENT
517 /* call-seq:
518  * Etc::Group.each { |group| block } -> obj
519  * Etc::Group.each -> Enumerator
520  *
521  * Iterates for each entry in the /etc/group file if a block is given.
522  *
523  * If no block is given, returns the Enumerator.
524  *
525  * The code block is passed a Group struct.
526  *
527  * Example:
528  *
529  * require 'etc'
530  *
531  * Etc::Group.each {|g|
532  * puts g.name + ": " + g.mem.join(', ')
533  * }
534  *
535  * Etc::Group.collect {|g| g.name}
536  * Etc::Group.select {|g| !g.mem.empty?}
537  *
538  */
539 static VALUE
540 etc_each_group(VALUE obj)
541 {
542  RETURN_ENUMERATOR(obj, 0, 0);
543  each_group();
544  return obj;
545 }
546 #endif
547 
548 /* Resets the process of reading the /etc/group file, so that the next call
549  * to ::getgrent will return the first entry again.
550  */
551 static VALUE
553 {
554 #ifdef HAVE_GETGRENT
555  setgrent();
556 #endif
557  return Qnil;
558 }
559 
560 /* Ends the process of scanning through the /etc/group file begun by
561  * ::getgrent, and closes the file.
562  */
563 static VALUE
565 {
566 #ifdef HAVE_GETGRENT
567  endgrent();
568 #endif
569  return Qnil;
570 }
571 
572 /* Returns an entry from the /etc/group file.
573  *
574  * The first time it is called it opens the file and returns the first entry;
575  * each successive call returns the next entry, or +nil+ if the end of the file
576  * has been reached.
577  *
578  * To close the file when processing is complete, call ::endgrent.
579  *
580  * Each entry is returned as a Group struct
581  */
582 static VALUE
584 {
585 #ifdef HAVE_GETGRENT
586  struct group *gr;
587 
588  if (gr = getgrent()) {
589  return setup_group(gr);
590  }
591 #endif
592  return Qnil;
593 }
594 
595 #define numberof(array) (sizeof(array) / sizeof(*(array)))
596 
597 #ifdef _WIN32
599 UINT rb_w32_system_tmpdir(WCHAR *path, UINT len);
600 VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
601 #endif
602 
603 /*
604  * Returns system configuration directory.
605  *
606  * This is typically "/etc", but is modified by the prefix used when Ruby was
607  * compiled. For example, if Ruby is built and installed in /usr/local, returns
608  * "/usr/local/etc".
609  */
610 static VALUE
612 {
613 #ifdef _WIN32
615 #else
616  return rb_filesystem_str_new_cstr(SYSCONFDIR);
617 #endif
618 }
619 
620 /*
621  * Returns system temporary directory; typically "/tmp".
622  */
623 static VALUE
625 {
626  VALUE tmpdir;
627 #ifdef _WIN32
628  WCHAR path[_MAX_PATH];
629  UINT len = rb_w32_system_tmpdir(path, numberof(path));
630  if (!len) return Qnil;
632 #else
633  tmpdir = rb_filesystem_str_new_cstr("/tmp");
634 #endif
635  FL_UNSET(tmpdir, FL_TAINT);
636  return tmpdir;
637 }
638 
639 /*
640  * The Etc module provides access to information typically stored in
641  * files in the /etc directory on Unix systems.
642  *
643  * The information accessible consists of the information found in the
644  * /etc/passwd and /etc/group files, plus information about the system's
645  * temporary directory (/tmp) and configuration directory (/etc).
646  *
647  * The Etc module provides a more reliable way to access information about
648  * the logged in user than environment variables such as +$USER+.
649  *
650  * == Example:
651  *
652  * require 'etc'
653  *
654  * login = Etc.getlogin
655  * info = Etc.getpwnam(login)
656  * username = info.gecos.split(/,/).first
657  * puts "Hello #{username}, I see your login name is #{login}"
658  *
659  * Note that the methods provided by this module are not always secure.
660  * It should be used for informational purposes, and not for security.
661  *
662  * All operations defined in this module are class methods, so that you can
663  * include the Etc module into your class.
664  */
665 void
666 Init_etc(void)
667 {
668  VALUE mEtc;
669 
670  mEtc = rb_define_module("Etc");
671  rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0);
672 
673  rb_define_module_function(mEtc, "getpwuid", etc_getpwuid, -1);
674  rb_define_module_function(mEtc, "getpwnam", etc_getpwnam, 1);
675  rb_define_module_function(mEtc, "setpwent", etc_setpwent, 0);
676  rb_define_module_function(mEtc, "endpwent", etc_endpwent, 0);
677  rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0);
678  rb_define_module_function(mEtc, "passwd", etc_passwd, 0);
679 
680  rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1);
681  rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1);
682  rb_define_module_function(mEtc, "group", etc_group, 0);
683  rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0);
684  rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0);
685  rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0);
686  rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
687  rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);
688 
689  sPasswd = rb_struct_define_under(mEtc, "Passwd",
690  "name",
691 #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
692  "passwd",
693 #endif
694  "uid",
695  "gid",
696 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
697  "gecos",
698 #endif
699  "dir",
700  "shell",
701 #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
702  "change",
703 #endif
704 #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
705  "quota",
706 #endif
707 #ifdef HAVE_STRUCT_PASSWD_PW_AGE
708  "age",
709 #endif
710 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
711  "uclass",
712 #endif
713 #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
714  "comment",
715 #endif
716 #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
717  "expire",
718 #endif
719  NULL);
720 #if 0
721  /* Define-const: Passwd
722  *
723  * Passwd is a Struct that contains the following members:
724  *
725  * name::
726  * contains the short login name of the user as a String.
727  * passwd::
728  * contains the encrypted password of the user as a String.
729  * an 'x' is returned if shadow passwords are in use. An '*' is returned
730  * if the user cannot log in using a password.
731  * uid::
732  * contains the integer user ID (uid) of the user.
733  * gid::
734  * contains the integer group ID (gid) of the user's primary group.
735  * dir::
736  * contains the path to the home directory of the user as a String.
737  * shell::
738  * contains the path to the login shell of the user as a String.
739  *
740  * === The following members below are optional, and must be compiled with special flags:
741  *
742  * gecos::
743  * contains a longer String description of the user, such as
744  * a full name. Some Unix systems provide structured information in the
745  * gecos field, but this is system-dependent.
746  * must be compiled with +HAVE_STRUCT_PASSWD_PW_GECOS+
747  * change::
748  * password change time(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_CHANGE+
749  * quota::
750  * quota value(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_QUOTA+
751  * age::
752  * password age(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_AGE+
753  * class::
754  * user access class(string) must be compiled with +HAVE_STRUCT_PASSWD_PW_CLASS+
755  * comment::
756  * comment(string) must be compiled with +HAVE_STRUCT_PASSWD_PW_COMMENT+
757  * expire::
758  * account expiration time(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_EXPIRE+
759  */
760  rb_define_const(mEtc, "Passwd", sPasswd);
761 #endif
762  rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */
765 
766 #ifdef HAVE_GETGRENT
767  sGroup = rb_struct_define_under(mEtc, "Group", "name",
768 #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
769  "passwd",
770 #endif
771  "gid", "mem", NULL);
772 
773 #if 0
774  /* Define-const: Group
775  *
776  * Group is a Struct that is only available when compiled with +HAVE_GETGRENT+.
777  *
778  * The struct contains the following members:
779  *
780  * name::
781  * contains the name of the group as a String.
782  * passwd::
783  * contains the encrypted password as a String. An 'x' is
784  * returned if password access to the group is not available; an empty
785  * string is returned if no password is needed to obtain membership of
786  * the group.
787  *
788  * Must be compiled with +HAVE_STRUCT_GROUP_GR_PASSWD+.
789  * gid::
790  * contains the group's numeric ID as an integer.
791  * mem::
792  * is an Array of Strings containing the short login names of the
793  * members of the group.
794  */
795  rb_define_const(mEtc, "Group", sGroup);
796 #endif
797  rb_define_const(rb_cStruct, "Group", sGroup); /* deprecated name */
799  rb_define_singleton_method(sGroup, "each", etc_each_group, 0);
800 #endif
801 }
#define NUM2UIDT(v)
Definition: ruby.h:330
static VALUE sPasswd
Definition: etc.c:26
static VALUE etc_getpwnam(VALUE obj, VALUE nam)
Definition: etc.c:193
static VALUE etc_endgrent(VALUE obj)
Definition: etc.c:564
#define INT2NUM(x)
Definition: ruby.h:1288
static VALUE etc_group(VALUE obj)
Definition: etc.c:501
rb_uid_t getuid(void)
Definition: win32.c:2494
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1655
#define FL_TAINT
Definition: ruby.h:1137
static VALUE etc_setpwent(VALUE obj)
Definition: etc.c:314
static VALUE etc_getpwent(VALUE obj)
Definition: etc.c:346
#define Qtrue
Definition: ruby.h:426
static VALUE etc_setgrent(VALUE obj)
Definition: etc.c:552
const int id
Definition: nkf.c:209
VALUE rb_struct_new(VALUE,...)
Definition: struct.c:500
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:896
static VALUE etc_getgrnam(VALUE obj, VALUE nam)
Definition: etc.c:436
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
static VALUE etc_systmpdir(void)
Definition: etc.c:624
#define CSIDL_COMMON_APPDATA
Definition: win32.c:397
static VALUE etc_getpwuid(int argc, VALUE *argv, VALUE obj)
Definition: etc.c:156
VALUE rb_struct_define_under(VALUE, const char *,...)
Definition: struct.c:327
char * getenv()
static VALUE etc_passwd(VALUE obj)
Definition: etc.c:261
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)
Definition: win32.c:2044
void Init_etc(void)
Definition: etc.c:666
int rb_block_given_p(void)
Definition: eval.c:712
VALUE rb_eRuntimeError
Definition: error.c:547
VALUE rb_ary_new(void)
Definition: array.c:495
static VALUE etc_getgrgid(int argc, VALUE *argv, VALUE obj)
Definition: etc.c:398
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2225
int argc
Definition: ruby.c:131
#define Qfalse
Definition: ruby.h:425
UINT rb_w32_system_tmpdir(WCHAR *path, UINT len)
Definition: win32.c:485
#define numberof(array)
Definition: etc.c:595
VALUE rb_locale_str_new_cstr(const char *)
Definition: string.c:725
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1670
VALUE rb_yield(VALUE)
Definition: vm_eval.c:942
VALUE rb_mEnumerable
Definition: enum.c:20
static VALUE etc_getlogin(VALUE obj)
Definition: etc.c:59
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1728
#define PRIsVALUE
Definition: ruby.h:137
#define Qnil
Definition: ruby.h:427
int type
Definition: tcltklib.c:112
unsigned long VALUE
Definition: ruby.h:88
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1305
#define NUM2GIDT(v)
Definition: ruby.h:336
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
Definition: eval.c:839
#define rb_tainted_str_new2
Definition: intern.h:844
void rb_sys_fail(const char *mesg)
Definition: error.c:1976
#define FL_UNSET(x, f)
Definition: ruby.h:1173
#define RSTRING_PTR(str)
Definition: ruby.h:845
char * getlogin()
Definition: win32.c:788
static VALUE etc_each_passwd(VALUE obj)
Definition: etc.c:301
RUBY_EXTERN VALUE rb_cStruct
Definition: ruby.h:1584
VALUE rb_w32_special_folder(int type)
Definition: win32.c:474
static VALUE etc_endpwent(VALUE obj)
Definition: etc.c:326
#define GIDT2NUM(v)
Definition: ruby.h:333
rb_encoding * rb_filesystem_encoding(void)
Definition: encoding.c:1309
#define RETURN_ENUMERATOR(obj, argc, argv)
Definition: intern.h:242
#define SafeStringValue(v)
Definition: ruby.h:545
VALUE rb_filesystem_str_new_cstr(const char *)
Definition: string.c:737
#define UIDT2NUM(v)
Definition: ruby.h:327
rb_gid_t getgid(void)
Definition: win32.c:2508
VALUE rb_define_module(const char *name)
Definition: class.c:746
#define NULL
Definition: _sdbm.c:103
static VALUE etc_sysconfdir(VALUE obj)
Definition: etc.c:611
VALUE rb_eArgError
Definition: error.c:549
static VALUE etc_getgrent(VALUE obj)
Definition: etc.c:583
char ** argv
Definition: ruby.c:132