]> TLD Linux GIT Repositories - packages/coreutils.git/blob - coreutils-uname-cpuinfo.patch
- merged 9.5 from PLD
[packages/coreutils.git] / coreutils-uname-cpuinfo.patch
1 diff -urNp -x '*.orig' coreutils-8.32.org/src/uname.c coreutils-8.32/src/uname.c
2 --- coreutils-8.32.org/src/uname.c      2020-02-04 20:27:08.000000000 +0100
3 +++ coreutils-8.32/src/uname.c  2021-03-21 00:28:54.006899186 +0100
4 @@ -86,6 +86,8 @@
5  /* Operating system.  */
6  #define PRINT_OPERATING_SYSTEM 128
7  
8 +void __sysinfo_processor_type(char*);
9 +
10  static struct option const uname_long_options[] =
11  {
12    {"all", no_argument, NULL, 'a'},
13 @@ -323,14 +323,12 @@
14        element = "powerpc";
15  # endif
16  #endif
17 -#if HAVE_SYSINFO && defined SI_ARCHITECTURE
18        if (element == unknown)
19          {
20 -          static char processor[257];
21 -          if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
22 -            element = processor;
23 +          char processor[BUFSIZ];
24 +          __sysinfo_processor_type(processor);
25 +          element = processor;
26          }
27 -#endif
28  #ifdef UNAME_PROCESSOR
29        if (element == unknown)
30          {
31 @@ -374,3 +372,38 @@ main (int argc, char **argv)
32  
33    return EXIT_SUCCESS;
34  }
35 +
36 +
37 +/* Carlos E. Gorges
38 +return vendor_id from proc cpuinfo
39 +*/
40 +
41 +void
42 +__sysinfo_processor_type (char* proc_info) {
43 + FILE *ffd;
44 + char *p,temp_string[BUFSIZ],final_string[BUFSIZ]="unknown";
45
46 + if ((ffd=fopen("/proc/cpuinfo", "r") )!=NULL) {
47 + while ( fscanf(ffd, "%s : ", temp_string) != EOF)
48 + #ifdef __PPC__
49 +       if (!(strcmp(temp_string, "machine"))) 
50 + #endif /* __PPC__ */
51 + #ifdef __sparc__
52 +       if (!(strcmp(temp_string, "cpu"))) 
53 + #endif /* __sparc__ */
54 + #if defined(__i386__) || defined(__x86_64__)
55 +       if (!(strcmp(temp_string, "name"))) 
56 + #endif /* __x86__ */
57 + #ifdef __alpha__
58 +       if (!(strcmp(temp_string, "model"))) 
59 + #endif /* __alpha__ */
60 + {
61 +         fgets(final_string, 64, ffd);
62 +         while (p=strchr(final_string, ' ')) *p='_';
63 +         while (p=strchr(final_string, '\n')) *p=0;
64 +        break;
65 + }
66 + fclose(ffd);
67 + }
68 + strncpy(proc_info,final_string,BUFSIZ);
69 +}