Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Etc.confstr
(::Integer p1) -> ::String?
confstr(name) → String
ext/etc/etc.c
View on GitHub ↗
static VALUE
etc_confstr(VALUE obj, VALUE arg)
{
int name;
char localbuf[128], *buf = localbuf;
size_t bufsize = sizeof(localbuf), ret;
VALUE tmp = 0, str;
name = NUM2INT(arg);
errno = 0;
ret = confstr(name, buf, bufsize);
if (bufsize < ret) {
bufsize = ret;
buf = ALLOCV_N(char, tmp, bufsize);
errno = 0;
ret = confstr(name, buf, bufsize);
}
if (bufsize < ret)
rb_bug("required buffer size for confstr() changed dynamically.");
if (ret == 0) {
int e = errno;
ALLOCV_END(tmp);
if (e == 0) /* no configuration-defined value */
return Qnil;
rb_syserr_fail(e, "confstr");
}
str = rb_str_new_cstr(buf);
ALLOCV_END(tmp);
return str;
}
Returns system configuration variable using confstr().
name should be a constant under Etc which begins with CS_.
The return value is a string or nil. nil means no configuration-defined value. (confstr() returns 0 but errno is not set.)
Example
Etc.confstr(Etc::CS_PATH) #=> "/bin:/usr/bin" # GNU/Linux Etc.confstr(Etc::CS_GNU_LIBC_VERSION) #=> "glibc 2.18" Etc.confstr(Etc::CS_GNU_LIBPTHREAD_VERSION) #=> "NPTL 2.18"