On Tue, May 26, 2015 at 12:06:51PM +0100, Dominik Vogt wrote: > + f = fopen ("/proc/cpuinfo", "r"); > + if (f == NULL) > + return NULL; > + > + while (fgets (buf, sizeof (buf), f) != NULL) > + if (strncmp (buf, "processor", sizeof ("processor") - 1) == 0) > + { > + if (strstr (buf, "machine = 9672") != NULL) > + cpu = "g5"; > + else if (strstr (buf, "machine = 2064") != NULL > + || strstr (buf, "machine = 2066") != NULL) > + cpu = "z900"; > + else if (strstr (buf, "machine = 2084") != NULL > + || strstr (buf, "machine = 2086") != NULL) > + cpu = "z990"; > + else if (strstr (buf, "machine = 2094") != NULL > + || strstr (buf, "machine = 2096") != NULL) > + cpu = "z9-109"; > + else if (strstr (buf, "machine = 2097") != NULL > + || strstr (buf, "machine = 2098") != NULL) > + cpu = "z10"; > + else if (strstr (buf, "machine = 2817") != NULL > + || strstr (buf, "machine = 2818") != NULL) > + cpu = "z196"; > + else if (strstr (buf, "machine = 2827") != NULL > + || strstr (buf, "machine = 2828") != NULL) > + cpu = "zEC12"; > + else if (strstr (buf, "machine = 2964") != NULL) > + cpu = "z13";
Wouldn't it be better to just use const char *p = strstr (buf, "machine = "); and then either strtoul the number after it and switch on it, or strcmp it, rather than using up to 13 strstr calls that all need to skip over the "processor" (you could even start after the matched keyword), version and identification stuff? Jakub