--- uname.c Fri Oct 13 02:49:49 2000 +++ uname.c Fri Oct 13 02:51:24 2000 @@ -112,13 +112,77 @@ exit (status); } +/* Hack to get processor model name from /proc/cpuinfo on linux machines */ +int +linux_get_processor(char* processor) +{ + FILE* fd; + char buff[256]; + char* buffwalk; + + fd = fopen("/proc/cpuinfo", "r"); + + if (!fd) + return 0; + + while (!feof(fd)) + { + if (!fgets(buff, 256, fd)) + { + fclose(fd); + return 0; + } + + /* check for the line beginning with "model name" or "cpu\t\t:" + * "model name" is sufficient for x86 machines, and "cpu\t\t:" + * works for ppc machines. Other architectures haven't been + * tested + */ + if (!strncmp(buff, "model name", strlen("model name")) + || !strncmp(buff, "cpu\t\t:", strlen("cpu\t\t:"))) + { + buffwalk = buff; + while (*buffwalk != ':' && *buffwalk != '\0') + buffwalk++; + + if (*buffwalk == '\0') + { + fclose(fd); + return 0; + } + + /* get past the ':' and the following space */ + buffwalk += 2; + + /* now copy the resulting string into *processor */ + strncpy(processor, buffwalk, strlen(buffwalk) + 1); + + buffwalk = processor; + while (*buffwalk != '\n' && *buffwalk != '\0') + buffwalk++; + + *buffwalk = '\0'; + + /* sanity check */ + buffwalk = NULL; + + fclose(fd); + return 1; + } + } + + fclose(fd); + return 0; +} + int main (int argc, char **argv) { struct utsname name; int c; char processor[256]; - + + program_name = argv[0]; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); @@ -184,7 +248,16 @@ if (sysinfo (SI_ARCHITECTURE, processor, sizeof (processor)) == -1) error (1, errno, _("cannot get processor type")); #else - strcpy (processor, "unknown"); + /* If this is a linux machine and does not have SI_ARCHITECTURE, then try + * to get processor from /proc/cpuinfo + */ + if (!strncmp(name.sysname, "Linux", strlen("Linux"))) + { + if (!linux_get_processor(processor)) + strcpy(processor, "unknown"); + } + else + strcpy (processor, "unknown"); #endif print_element (PRINT_SYSNAME, name.sysname);