On Tue, Nov 22, 2011 at 04:47:21PM +0100, Jakub Wilk wrote: > * Ben Hutchings <b...@decadent.org.uk>, 2011-11-20, 20:48: > >Use of CPUID is probably safe in practice since most 486 models do > >implement it, though userland should really read /proc/cpuinfo. > >The other uses may be conditional on a CPU feature test but may > >well be bugs. > > Is format of /proc/cpuinfo documented anywhere?
Sadly, it is not documented explicitly. > Does /proc/cpuinfo with the exist on non-Linux architectures? If > yes, do they use the same format? It is Linux-specific, but included in FreeBSD's Linux compatibility module. I don't know whether Debian kFreeBSD loads that by default. > Are the any ready-made libraries that can parse this file? Not that I know of. However, if you're looking for specific x86 feature flags (which is almost certainly what you need) you can use: bool x86_has_feature(const char *name) { FILE *cpuinfo; char *line = NULL, *p; size_t line_len = 0, name_len = strlen(name); bool found = false; cpuinfo = fopen("/proc/cpuinfo", "r"); if (!cpuinfo) return false; while (getline(&line, &line_len, cpuinfo) >= 0 && !found) { if (strncmp(line, "flags\t", 6)) continue; p = line; while ((p = strchr(p, ' ')) != NULL) { p++; if (strncmp(p, name, name_len) == 0 && isspace((unsigned char)p[name_len])) { found = true; break; } } } fclose(cpuinfo); return found; } Ben. -- Ben Hutchings We get into the habit of living before acquiring the habit of thinking. - Albert Camus -- To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20111122213747.gs3...@decadent.org.uk