ext/sysconf/sysconf.c in linux_stat-1.1.1 vs ext/sysconf/sysconf.c in linux_stat-1.2.0
- old
+ new
@@ -117,10 +117,19 @@
static VALUE getEUID(VALUE obj) {
return INT2FIX(geteuid()) ;
}
+static VALUE getHostname(VALUE obj) {
+ int h_max = sysconf(_SC_HOST_NAME_MAX) + 1 ;
+ char hostname[h_max] ;
+
+ short int status = gethostname(hostname, h_max) ;
+
+ return (status < 0) ? rb_str_new_cstr("") : rb_str_new_cstr(hostname) ;
+}
+
void Init_sysconf() {
VALUE _linux_stat = rb_define_module("LinuxStat") ;
VALUE _sysconf = rb_define_module_under(_linux_stat, "Sysconf") ;
rb_define_module_function(_sysconf, "sc_clk_tck", getTick, 0) ;
@@ -142,6 +151,8 @@
rb_define_module_function(_sysconf, "get_gid", getGID, 0) ;
rb_define_module_function(_sysconf, "get_euid", getEUID, 0) ;
rb_define_module_function(_sysconf, "get_user", getUser, 0) ;
rb_define_module_function(_sysconf, "get_login", getUser, 0) ;
+
+ rb_define_module_function(_sysconf, "hostname", getHostname, 0) ;
}