Functions

Subarchitecture detection
[System]

Functions

const char * di_system_subarch_analyze (void)
const char * di_system_subarch_analyze_guess (void)

Function Documentation

const char* di_system_subarch_analyze ( void   ) 

Returns a string describing the current subarchitecture, e.g. "powermac_newworld".

Referenced by di_system_subarch_analyze_guess().

{
        FILE *cpuinfo;
        char line[1024];
        char entry[256];
        char *pos;
        int i;

        cpuinfo = fopen("/proc/cpuinfo", "r");
        if (cpuinfo == NULL)
                return "unknown";

        while (fgets(line, sizeof(line), cpuinfo) != NULL)
        {
            if (strstr(line, "Hardware") == line)
            {
                pos = strchr(line, ':');
                if (pos == NULL)
                           continue;
                while (*++pos && (*pos == '\t' || *pos == ' '));

                strncpy(entry, pos, sizeof(entry));
                break;
            }
        }

        fclose(cpuinfo);

        for (i = 0; map_hardware[i].entry; i++)
        {
            if (!strncasecmp(map_hardware[i].entry, entry,
                        strlen(map_hardware[i].entry)))
            {
                return( map_hardware[i].ret );
            }
        }

        return "unknown";
}

const char* di_system_subarch_analyze_guess ( void   ) 

Return a string with a best-guess of the current subarchitecture

Only present on armel currently, and is a stub on all other architectures

References di_system_subarch_analyze().

{
        struct utsname sysinfo;
        size_t uname_release_len, i;

        /* Attempt to determine subarch based on kernel release version */
        uname(&sysinfo);
        uname_release_len = strlen(sysinfo.release);

        for (i = 0; supported_generic_subarches[i] != NULL; i++)
        {
                size_t subarch_len = strlen (supported_generic_subarches[i]);
                if (!strncmp(sysinfo.release+uname_release_len-subarch_len,
                        supported_generic_subarches[i],
                        subarch_len))
                {
                        return supported_generic_subarches[i];
                }
        }

        /* If we get here, try falling back on the normal detection method */
        return di_system_subarch_analyze();
}