home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / sysinfo-1.0 / part01 / os-mach.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-10  |  3.4 KB  |  158 lines

  1. /*
  2.  * Copyright (c) 1992 Michael A. Cooper.
  3.  * This software may be freely distributed provided it is not sold for 
  4.  * profit and the author is credited appropriately.
  5.  */
  6.  
  7. #ifndef lint
  8. static char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/os-mach.c,v 1.4 1992/04/26 23:32:06 mcooper Exp $";
  9. #endif
  10.  
  11. /*
  12.  * $Log: os-mach.c,v $
  13.  * Revision 1.4  1992/04/26  23:32:06  mcooper
  14.  * Add Copyright notice
  15.  *
  16.  * Revision 1.3  1992/04/17  01:07:59  mcooper
  17.  * More de-linting
  18.  *
  19.  * Revision 1.2  1992/03/22  01:05:09  mcooper
  20.  * Major cleanup and re-org.
  21.  *
  22.  * Revision 1.1  1992/03/01  23:28:16  mcooper
  23.  * Initial revision
  24.  *
  25.  */
  26.  
  27. /*
  28.  * Mach specific functions
  29.  */
  30.  
  31. #include <stdio.h>
  32. #include "system.h"
  33. #include "defs.h"
  34.  
  35. #if    defined(HAVE_HOST_INFO)
  36. #include <sys/host_info.h>
  37.  
  38. /*
  39.  * Use the host_info() call to obtain type of CPU.
  40.  */
  41. extern char *GetCpuTypeFromHostInfo()
  42. {
  43.     extern NAMETAB         CpuTypeTab[];
  44.     struct host_basic_info     basic_info;
  45.     unsigned int         count = HOST_BASIC_INFO_COUNT;
  46.     register int         i;
  47.  
  48.     if (host_info(host_self(), HOST_BASIC_INFO, 
  49.           (host_info_t) &basic_info, &count) != KERN_SUCCESS) {
  50.     return((char *)NULL);
  51.     }
  52.  
  53.     for (i = 0; CpuTypeTab[i].name; ++i) {
  54.     if (CpuTypeTab[i].value == basic_info.cpu_type)
  55.         return(CpuTypeTab[i].name);
  56.     }
  57.  
  58.     return((char *) NULL);
  59. }
  60.  
  61. /*
  62.  * Use the host_info() call to obtain the model of CPU.
  63.  */
  64. extern char *GetModelFromHostInfo()
  65. {
  66.     extern NAMETAB         ModelTabMach[];
  67.     struct host_basic_info     basic_info;
  68.     unsigned int         count = HOST_BASIC_INFO_COUNT;
  69.     register int         i;
  70.  
  71.     if (host_info(host_self(), HOST_BASIC_INFO, 
  72.           (host_info_t) &basic_info, &count) != KERN_SUCCESS) {
  73.     return((char *)NULL);
  74.     }
  75.  
  76.     for (i = 0; ModelTabMach[i].name; ++i) {
  77.     if (ModelTabMach[i].value == basic_info.cpu_subtype)
  78.         return(ModelTabMach[i].name);
  79.     }
  80.  
  81.     return((char *) NULL);
  82. }
  83.  
  84. /*
  85.  * Get our application architecture name.
  86.  */
  87. extern char *GetAppArchFromHostInfo()
  88. {
  89.     return(GetCpuTypeFromHostInfo());
  90. }
  91.  
  92. /*
  93.  * Get our kernel architecture name.
  94.  */
  95. extern char *GetKernArchFromHostInfo()
  96. {
  97.     return(GetCpuTypeFromHostInfo());
  98. }
  99.  
  100. /*
  101.  * Get amount of memory.
  102.  */
  103. extern char *GetMemoryFromHostInfo()
  104. {
  105.     struct host_basic_info     BasicInfo;
  106.     unsigned int         count = HOST_BASIC_INFO_COUNT;
  107.     static char            Buf[BUFSIZ];
  108.     int                Amount = -1;
  109.  
  110.     if (host_info(host_self(), HOST_BASIC_INFO, 
  111.           (host_info_t) &BasicInfo, &count) == KERN_SUCCESS) {
  112.     Amount = BasicInfo.memory_size / MBYTES;
  113.     (void) sprintf(Buf, "%d MB", Amount);
  114.     return(Buf);
  115.     } else
  116.     return((char *) NULL);
  117. }
  118.  
  119. /*
  120.  * Get kernel version string.
  121.  */
  122. extern char *GetKernelVersionFromHostInfo()
  123. {
  124.     static char         Version[BUFSIZ];
  125.     register char            *p;
  126.  
  127.     Version[0] = C_NULL;
  128.     if (host_kernel_version(host_self(), Version) != KERN_SUCCESS) {
  129.     if (Debug) Error("host_kernel_version() failed: %s.\n", SYSERR);
  130.     }
  131.  
  132. #if    defined(KERNSTR_END)
  133.     if (Version[0])
  134.     if ((p = index(Version, KERNSTR_END)) != NULL)
  135.         *p = C_NULL;
  136. #endif    /* KERNSTR_END */
  137.  
  138.     return((Version[0]) ? Version : (char *) NULL);
  139. }
  140.  
  141. /*
  142.  * Get OS version
  143.  */
  144. extern char *GetOSVersionFromHostInfo()
  145. {
  146.     static char            Buf[BUFSIZ];
  147.     struct machine_info     Info;
  148.  
  149.     if (xxx_host_info(host_self(), (machine_info_t) &Info) == KERN_SUCCESS) {
  150.     (void) sprintf(Buf, "%d.%d", Info.major_version, Info.minor_version);
  151.     return(Buf);
  152.     }
  153.  
  154.     return((char *) NULL);
  155. }
  156.  
  157. #endif    /* HAVE_HOST_INFO */
  158.