Exemplo n.º 1
0
void vm_sys_info_get_cpu_name(vm_char *cpu_name)
{
    FILE *pFile = NULL;
    vm_char buf[_MAX_LEN];
    vm_char tmp_buf[_MAX_LEN] = { 0 };
    size_t len;

    /* check error(s) */
    if (NULL == cpu_name)
        return;

    pFile = vm_file_fopen(VM_STRING("/proc/cpuinfo"), "r");
    if (!pFile)
        return;

    while ((vm_file_fgets(buf, _MAX_LEN, pFile)))
    {
        if (!vm_string_strncmp(buf, VM_STRING("vendor_id"), 9))
        {
            vm_string_strncpy_s(tmp_buf, _MAX_LEN, (vm_char*)(buf + 12), vm_string_strnlen_s(buf, _MAX_LEN) - 13);
        }
        else if (!vm_string_strncmp(buf, VM_STRING("model name"), 10))
        {
            if ((len = vm_string_strnlen_s(buf, _MAX_LEN) - 14) > 8)
                vm_string_strncpy_s(cpu_name, _MAX_LEN, (vm_char *)(buf + 13), len);
            else
                vm_string_snprintf(cpu_name, PATH_MAX, VM_STRING("%s"), tmp_buf);
        }
    }
    fclose(pFile);
} /* void vm_sys_info_get_cpu_name(vm_char *cpu_name) */
Exemplo n.º 2
0
uint32_t vm_sys_info_get_cpu_speed(void)
{
    double ret = 0;
    FILE *pFile = NULL;
    vm_char buf[PATH_MAX];

    pFile = vm_file_fopen(VM_STRING("/proc/cpuinfo"), "r" );
    if (!pFile)
        return 1000;

    while ((vm_file_fgets(buf, PATH_MAX, pFile)))
    {
        if (!vm_string_strncmp(buf, VM_STRING("cpu MHz"), 7))
        {
            ret = vm_string_atol((vm_char *)(buf + 10));
            break;
        }
    }
    fclose(pFile);
    return ((uint32_t) ret);
} /* uint32_t vm_sys_info_get_cpu_speed(void) */
Exemplo n.º 3
0
vm_char* vm_file_fgets_cvt(vm_char *str, int nchar, vm_file *fd, CVT_DESTINATION dst)
{
    return vm_file_fgets(str, nchar, fd);
}