14 #include <sys/types.h> 29 #ifdef HAVE_SYS_UTSNAME_H 30 #include <sys/utsname.h> 33 #ifdef HAVE_SCHED_GETAFFINITY 44 #ifndef CSIDL_COMMON_APPDATA 45 #define CSIDL_COMMON_APPDATA 35 73 etc_getlogin(
VALUE obj)
79 if (!login) login =
getenv(
"USER");
96 #if defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT) 98 safe_setup_str(
const char *str)
100 if (str == 0) str =
"";
105 safe_setup_locale_str(
const char *str)
107 if (str == 0) str =
"";
112 safe_setup_filesystem_str(
const char *str)
114 if (str == 0) str =
"";
121 setup_passwd(
struct passwd *pwd)
125 safe_setup_locale_str(pwd->pw_name),
126 #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
127 safe_setup_str(pwd->pw_passwd),
131 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
132 safe_setup_locale_str(pwd->pw_gecos),
134 safe_setup_filesystem_str(pwd->pw_dir),
135 safe_setup_filesystem_str(pwd->pw_shell),
136 #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
139 #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
142 #ifdef HAVE_STRUCT_PASSWD_PW_AGE
143 PW_AGE2VAL(pwd->pw_age),
145 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
146 safe_setup_locale_str(pwd->pw_class),
148 #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
149 safe_setup_locale_str(pwd->pw_comment),
151 #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
179 #if defined(HAVE_GETPWENT) 192 return setup_passwd(pwd);
223 return setup_passwd(pwd);
230 static int passwd_blocking = 0;
235 passwd_blocking = (int)
Qfalse;
245 while ((pw = getpwent()) != 0) {
254 if (passwd_blocking) {
257 passwd_blocking = (int)
Qtrue;
258 rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
283 etc_passwd(
VALUE obj)
291 else if ((pw = getpwent()) != 0) {
292 return setup_passwd(pw);
323 etc_each_passwd(
VALUE obj)
336 etc_setpwent(
VALUE obj)
348 etc_endpwent(
VALUE obj)
368 etc_getpwent(
VALUE obj)
373 if ((pw = getpwent()) != 0) {
374 return setup_passwd(pw);
382 setup_group(
struct group *grp)
394 safe_setup_locale_str(grp->gr_name),
395 #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
396 safe_setup_str(grp->gr_passwd),
420 etc_getgrgid(
int argc,
VALUE *argv,
VALUE obj)
435 return setup_group(grp);
467 return setup_group(grp);
474 static int group_blocking = 0;
479 group_blocking = (int)
Qfalse;
490 while ((pw = getgrent()) != 0) {
499 if (group_blocking) {
502 group_blocking = (int)
Qtrue;
503 rb_ensure(group_iterate, 0, group_ensure, 0);
532 else if ((grp = getgrent()) != 0) {
533 return setup_group(grp);
563 etc_each_group(
VALUE obj)
575 etc_setgrent(
VALUE obj)
587 etc_endgrent(
VALUE obj)
606 etc_getgrent(
VALUE obj)
611 if ((gr = getgrent()) != 0) {
612 return setup_group(gr);
618 #define numberof(array) (sizeof(array) / sizeof(*(array))) 635 etc_sysconfdir(
VALUE obj)
652 WCHAR path[_MAX_PATH];
654 if (!len)
return Qnil;
657 const char default_tmp[] =
"/tmp";
658 const char *tmpstr = default_tmp;
659 size_t tmplen =
strlen(default_tmp);
660 # if defined _CS_DARWIN_USER_TEMP_DIR 662 #define MAXPATHLEN 1024 666 len = confstr(_CS_DARWIN_USER_TEMP_DIR, path,
sizeof(path));
670 if (len >
sizeof(path)) tmpstr = 0;
674 # if defined _CS_DARWIN_USER_TEMP_DIR 676 confstr(_CS_DARWIN_USER_TEMP_DIR,
RSTRING_PTR(tmpdir), len);
710 const char *sysname, *mach;
711 VALUE result, release, version;
716 v.dwOSVersionInfoSize =
sizeof(v);
717 if (!GetVersionExW(&v))
721 switch (v.dwPlatformId) {
722 case VER_PLATFORM_WIN32s:
725 case VER_PLATFORM_WIN32_NT:
726 sysname =
"Windows_NT";
728 case VER_PLATFORM_WIN32_WINDOWS:
734 release =
rb_sprintf(
"%lu.%lu.%lu", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
740 # if defined _MSC_VER && _MSC_VER < 1300 741 # define GET_COMPUTER_NAME(ptr, plen) GetComputerNameW(ptr, plen) 743 # define GET_COMPUTER_NAME(ptr, plen) GetComputerNameExW(ComputerNameDnsFullyQualified, ptr, plen) 745 GET_COMPUTER_NAME(
NULL, &len);
747 if (GET_COMPUTER_NAME(buf, &len)) {
754 # ifndef PROCESSOR_ARCHITECTURE_AMD64 755 # define PROCESSOR_ARCHITECTURE_AMD64 9 757 # ifndef PROCESSOR_ARCHITECTURE_IA64 758 # define PROCESSOR_ARCHITECTURE_IA64 6 760 # ifndef PROCESSOR_ARCHITECTURE_INTEL 761 # define PROCESSOR_ARCHITECTURE_INTEL 0 764 switch (s.wProcessorArchitecture) {
765 case PROCESSOR_ARCHITECTURE_AMD64:
768 case PROCESSOR_ARCHITECTURE_ARM:
771 case PROCESSOR_ARCHITECTURE_IA64:
774 case PROCESSOR_ARCHITECTURE_INTEL:
803 #define etc_uname rb_f_notimplement 837 #define etc_sysconf rb_f_notimplement 860 char localbuf[128], *buf = localbuf;
861 size_t bufsize =
sizeof(localbuf), ret;
867 ret = confstr(name, buf, bufsize);
872 ret = confstr(name, buf, bufsize);
875 rb_bug(
"required buffer size for confstr() changed dynamically.");
884 #define etc_confstr rb_f_notimplement 887 #ifdef HAVE_FPATHCONF 914 ret = fpathconf(fptr->
fd, name);
923 #define io_pathconf rb_f_notimplement 926 #if (defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)) || defined(_WIN32) 928 #if defined(HAVE_SCHED_GETAFFINITY) && defined(CPU_ALLOC) 930 etc_nprocessors_affin(
void)
953 for (n=64; n <= 16384; n *= 2) {
954 size = CPU_ALLOC_SIZE(n);
961 CPU_ZERO_S(size, cpuset);
964 ret = sched_getaffinity(0, size, cpuset);
967 ret = CPU_COUNT_S(size, cpuset);
1011 #if !defined(_WIN32) 1013 #if defined(HAVE_SCHED_GETAFFINITY) && defined(CPU_ALLOC) 1016 ncpus = etc_nprocessors_affin();
1024 ret = sysconf(_SC_NPROCESSORS_ONLN);
1031 ret = (long)si.dwNumberOfProcessors;
1036 #define etc_nprocessors rb_f_notimplement 1071 init_constants(mEtc);
1098 #ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
1103 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
1108 #ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
1111 #ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
1114 #ifdef HAVE_STRUCT_PASSWD_PW_AGE
1117 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
1120 #ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
1123 #ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
1173 #ifdef HAVE_GETGRENT 1175 #ifdef HAVE_STRUCT_GROUP_GR_PASSWD
1178 "gid",
"mem", NULL);
void rb_bug(const char *fmt,...)
size_t strlen(const char *)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *)
VALUE rb_struct_new(VALUE,...)
VALUE rb_ary_push(VALUE ary, VALUE item)
#define CSIDL_COMMON_APPDATA
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
An equivalent to ensure clause.
rb_encoding * rb_utf8_encoding(void)
#define GetOpenFile(obj, fp)
VALUE rb_struct_define_under(VALUE, const char *,...)
VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
void rb_define_const(VALUE, const char *, VALUE)
#define ALLOCV_N(type, v, n)
UINT rb_w32_system_tmpdir(WCHAR *path, UINT len)
void rb_sys_fail(const char *mesg)
VALUE rb_locale_str_new_cstr(const char *)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
VALUE rb_sprintf(const char *format,...)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
unsigned char buf[MIME_BUF_SIZE]
rb_encoding * rb_locale_encoding(void)
VALUE rb_str_new_cstr(const char *)
#define rb_tainted_str_new2
register unsigned int len
#define StringValueCStr(v)
RUBY_EXTERN VALUE rb_cStruct
VALUE rb_w32_special_folder(int type)
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
void rb_check_safe_obj(VALUE)
rb_encoding * rb_filesystem_encoding(void)
#define RETURN_ENUMERATOR(obj, argc, argv)
VALUE rb_filesystem_str_new_cstr(const char *)
RUBY_SYMBOL_EXPORT_BEGIN void * alloca()
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_filesystem_str_new(const char *, long)
VALUE rb_str_new(const char *, long)