vapier      15/08/05 07:05:37

  Modified:             uname-test.c
  Log:
  pull procinfo init out of __linux_procinfo to try and minimize differences 
with real file (so it is eaiser to compare)

Revision  Changes    Path
1.6                  src/patchsets/coreutils/uname-test/uname-test.c

file : 
http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.6&view=markup
plain: 
http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?rev=1.6&content-type=text/plain
diff : 
http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/coreutils/uname-test/uname-test.c?r1=1.5&r2=1.6

Index: uname-test.c
===================================================================
RCS file: /var/cvsroot/gentoo/src/patchsets/coreutils/uname-test/uname-test.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- uname-test.c        5 Aug 2015 07:00:11 -0000       1.5
+++ uname-test.c        5 Aug 2015 07:05:37 -0000       1.6
@@ -30,6 +30,7 @@
 #  define CPUINFO_FORMAT  "%64[^\t:]\t:%256[^\n]%c"
 # endif
 
+const char *procinfo_processor, *procinfo_platform;
 const char *filename = CPUINFO_FILE;
 #undef CPUINFO_FILE
 #define CPUINFO_FILE filename
@@ -64,39 +65,10 @@
 {
        FILE *fp;
 
-       static struct {
-               const char *arch;
-               const char *processor;
-               const char *platform;
-       } procinfo_keys_all[] = {
-               /* cpuname     --processor     --hardware-platform */
-               { "alpha",     "cpu model",    "system type" },
-               { "amd64",     "model name",   "vendor_id" },
-               { "arm",       "Processor",    "Hardware" },
-               { "bfin",      "CPU",          "BOARD Name" },
-               { "cris",      "cpu",          "cpu model" },
-               { "frv",       "CPU-Core",     "System" },
-               { "i386",      "model name",   "vendor_id" },
-               { "ia64",      "family",       "vendor" },
-               { "hppa",      "cpu",          "model" },
-               { "m68k",      "CPU",          "MMU" },
-               { "mips",      "cpu model",    "system type" },
-               { "powerpc",   "cpu",          "machine" },
-               { "powerpc64", "cpu",          "machine" },
-               { "s390",      "Type",         "Manufacturer" },
-               { "s390x",     "Type",         "Manufacturer" },
-               { "sh",        "cpu type",     "machine" },
-               { "sparc",     "type",         "cpu" },
-               { "vax",       "cpu type",     "cpu" },
+       const char * const procinfo_keys[] = {
+               /* --processor --hardware-platform */
+               procinfo_processor, procinfo_platform,
        };
-       const char *procinfo_keys[] = { "", "" };
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(procinfo_keys_all); ++i)
-               if (!strncmp(filename, procinfo_keys_all[i].arch, 
strlen(procinfo_keys_all[i].arch))) {
-                       procinfo_keys[PROCINFO_PROCESSOR] = 
procinfo_keys_all[i].processor;
-                       procinfo_keys[PROCINFO_HARDWARE_PLATFORM] = 
procinfo_keys_all[i].platform;
-               }
 
        if (verbose)
                printf("### Looking for '%s':\n", procinfo_keys[x]);
@@ -135,6 +107,50 @@
 
 #endif
 
+static bool startswith(const char *s, const char *prefix)
+{
+       return strncmp(s, prefix, strlen(prefix)) == 0 ? true : false;
+}
+
+static bool procinfo_init(void)
+{
+       static const struct {
+               const char *arch;
+               const char *processor;
+               const char *platform;
+       } procinfo_keys_all[] = {
+               /* cpuname     --processor     --hardware-platform */
+               { "alpha",     "cpu model",    "system type" },
+               { "amd64",     "model name",   "vendor_id" },
+               { "arm",       "Processor",    "Hardware" },
+               { "bfin",      "CPU",          "BOARD Name" },
+               { "cris",      "cpu",          "cpu model" },
+               { "frv",       "CPU-Core",     "System" },
+               { "i386",      "model name",   "vendor_id" },
+               { "ia64",      "family",       "vendor" },
+               { "hppa",      "cpu",          "model" },
+               { "m68k",      "CPU",          "MMU" },
+               { "mips",      "cpu model",    "system type" },
+               { "powerpc",   "cpu",          "machine" },
+               { "powerpc64", "cpu",          "machine" },
+               { "s390",      "Type",         "Manufacturer" },
+               { "s390x",     "Type",         "Manufacturer" },
+               { "sh",        "cpu type",     "machine" },
+               { "sparc",     "type",         "cpu" },
+               { "vax",       "cpu type",     "cpu" },
+       };
+
+       size_t i;
+       for (i = 0; i < ARRAY_SIZE(procinfo_keys_all); ++i)
+               if (startswith(filename, procinfo_keys_all[i].arch)) {
+                       procinfo_processor = procinfo_keys_all[i].processor;
+                       procinfo_platform = procinfo_keys_all[i].platform;
+                       return true;
+               }
+
+       warnx("could not detect arch with %s", filename);
+       return false;
+}
 
 int main(int argc, char *argv[])
 {
@@ -157,6 +173,10 @@
 
        filename = argv[optind];
        printf(">>> Parsing data out of %s\n", filename);
+
+       if (!procinfo_init())
+               return 1;
+
        i = 0;
 
        if (0 > __linux_procinfo (PROCINFO_PROCESSOR, processor, sizeof 
processor)) {




Reply via email to