Proposal: cpuinfo(1)

Manoj Srivastava srivasta at acm.org
Thu Jan 10 15:29:51 PST 2002


Hi,

	First, a nit:
======================================================================
static void
grep_cputypes(const char *prefix, int len)
======================================================================

Should be
======================================================================
static void
grep_cputypes(const char *prefix, size_t len)
======================================================================

	Just a nit, but it silences the warning:
======================================================================
cc -ansi -pedantic -Wall -W -Wtraditional -Wconversion -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -fshort-enums -fno-common -Dgets=DONT_USE_GETS -Dlint -Woverloaded-virtual -Wnested-externs -Winline -O2 -D_XOPEN_SOURCE=600   -c -o arch_i386.o arch_i386.c
arch_i386.c: In function `grep_cputypes':
arch_i386.c:23: warning: passing arg 3 of `strncmp' as unsigned due to prototype
======================================================================

	Secondly, why are you passing the length explicitly in the
 call to grep_cputypes? The following implementation removes the
 requirement (and I often miscount, in my old age.
======================================================================
static void
grep_cputypes(const char *prefix)
{
        FILE *f;
        char buf[LINE_MAX];
        int n = 0;

        f = fopen(_PATH_CPUINFO, "r");
        if (f) {
                while (fgets(buf, sizeof(buf), f)) {
                        if (!strncmp(buf, prefix, strlen(prefix))) {
                                printf("cpu%d: %s", n++, (buf+len+3));
                        }
                }
                fclose(f);
        }
        if (!n) {
                printf("unknown\n");
        }
}
======================================================================


	Am I missing a reason to allow the caller to specify a subset
 of the prefix as relevant for comparison?

	manoj
        
-- 
 You should never wear your best trousers when you go out to fight for
 freedom and liberty. Henrik Ibsen
Manoj Srivastava   <srivasta at acm.org>  <http://www.datasync.com/%7Esrivasta/>
1024R/C7261095 print CB D9 F4 12 68 07 E4 05  CC 2D 27 12 1D F5 E8 6E
1024D/BF24424C print 4966 F272 D093 B493 410B  924B 21BA DABB BF24 424C




More information about the lsb-discuss mailing list