static sigar_pid_t rb_sigar_pid_get(rb_sigar_t *rbsigar, VALUE obj) { SIGAR; if (TYPE(obj) == T_STRING) { char *pid = StringValuePtr(obj); if (sigar_isdigit(*pid)) { obj = rb_str2inum(obj, 10); /* fallthru */ } else if ((RSTRING_LEN(obj) == 2) && (*pid == '$') && (*(pid + 1) == '$')) { return sigar_pid_get(sigar); } else { /* XXX cache queries */ sigar_ptql_query_t *query; sigar_ptql_error_t error; int status = sigar_ptql_query_create(&query, (char *)pid, &error); if (status == SIGAR_OK) { sigar_pid_t qpid; sigar_ptql_re_impl_set(sigar, NULL, rbsigar_ptql_re_impl); status = sigar_ptql_query_find_process(sigar, query, &qpid); sigar_ptql_re_impl_set(sigar, NULL, NULL); sigar_ptql_query_destroy(query); if (status == SIGAR_OK) { return qpid; } else { RB_SIGAR_RAISE(sigar_strerror(sigar, status)); } } else { RB_SIGAR_RAISE(error.message); } } } return NUM2UINT(obj); }
VALUE string_spec_rb_str2inum(VALUE self, VALUE str, VALUE inum) { int num = FIX2INT(inum); return rb_str2inum(str, num); }