OS_NS_sys_utsname.cpp

Go to the documentation of this file.
00001 // $Id: OS_NS_sys_utsname.cpp 80826 2008-03-04 14:51:23Z wotte $
00002 
00003 #include "ace/OS_NS_sys_utsname.h"
00004 
00005 ACE_RCSID(ace, OS_NS_sys_utsname, "$Id: OS_NS_sys_utsname.cpp 80826 2008-03-04 14:51:23Z wotte $")
00006 
00007 #include "ace/OS_NS_string.h"
00008 #include "ace/OS_NS_stdio.h"
00009 #include "ace/OS_NS_unistd.h"
00010 
00011 #if defined (ACE_VXWORKS) && defined (ACE_LACKS_UNAME)
00012 // for sysBspRev(), sysModel()
00013 #  include /**/ <sysLib.h>
00014 // for kernelVersion()
00015 #  include /**/ <kernelLib.h>
00016 #endif /* ACE_VXWORKS && ACE_LACKS_UNAME */
00017 
00018 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 int
00021 ACE_OS::uname (ACE_utsname *name)
00022 {
00023   ACE_OS_TRACE ("ACE_OS::uname");
00024 #if !defined (ACE_LACKS_UNAME)
00025   ACE_OSCALL_RETURN (::uname (name), int, -1);
00026 #elif defined (ACE_WIN32)
00027   size_t maxnamelen = sizeof name->nodename;
00028   ACE_OS::strcpy (name->sysname, "Win32");
00029 
00030   ACE_TEXT_OSVERSIONINFO vinfo;
00031   vinfo.dwOSVersionInfoSize = sizeof(ACE_TEXT_OSVERSIONINFO);
00032   ACE_TEXT_GetVersionEx (&vinfo);
00033 
00034   SYSTEM_INFO sinfo;
00035 #   if defined (ACE_HAS_PHARLAP)
00036   // PharLap doesn't do GetSystemInfo.  What's really wanted is the
00037   // CPU architecture, so we can get that with EtsGetSystemInfo. Fill
00038   // in what's wanted in the SYSTEM_INFO structure, and carry on. Note
00039   // that the CPU type values in EK_KERNELINFO have the same values
00040   // are the ones defined for SYSTEM_INFO.
00041   EK_KERNELINFO ets_kern;
00042   EK_SYSTEMINFO ets_sys;
00043   EtsGetSystemInfo (&ets_kern, &ets_sys);
00044   sinfo.wProcessorLevel = static_cast<WORD> (ets_kern.CpuType);
00045   sinfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
00046   sinfo.dwProcessorType = ets_kern.CpuType * 100 + 86;
00047 #   else
00048   ::GetSystemInfo(&sinfo);
00049 #   endif /* ACE_HAS_PHARLAP */
00050 
00051   const char* unknown = "???";
00052 
00053   if (
00054       vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT
00055 #   if defined (VER_PLATFORM_WIN32_CE)
00056       || vinfo.dwPlatformId == VER_PLATFORM_WIN32_CE
00057 #   endif
00058       )
00059     {
00060       // Get information from the two structures
00061       const char *os;
00062       if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
00063         os = "Windows NT %d.%d";
00064       else
00065         os = "Windows CE %d.%d";
00066       ACE_OS::sprintf (name->release,
00067                        os,
00068                        (int) vinfo.dwMajorVersion,
00069                        (int) vinfo.dwMinorVersion);
00070       ACE_OS::sprintf (name->version,
00071                        "Build %d %s",
00072                        (int) vinfo.dwBuildNumber,
00073                        ACE_TEXT_ALWAYS_CHAR (vinfo.szCSDVersion));
00074 
00075       // We have to make sure that the size of (processor + subtype)
00076       // is not greater than the size of name->machine.  So we give
00077       // half the space to the processor and half the space to
00078       // subtype.  The -1 is necessary for because of the space
00079       // between processor and subtype in the machine name.
00080       const int bufsize = (sizeof (name->machine) / 2) - 1;
00081       char processor[bufsize] = "Unknown";
00082       char subtype[bufsize] = "Unknown";
00083 
00084 #   if defined (ghs)
00085     WORD arch = sinfo.u.s.wProcessorArchitecture;
00086 #   else
00087     WORD arch = sinfo.wProcessorArchitecture;
00088 #   endif
00089 
00090       switch (arch)
00091         {
00092         case PROCESSOR_ARCHITECTURE_INTEL:
00093           ACE_OS::strcpy (processor, "Intel");
00094           if (sinfo.wProcessorLevel == 3)
00095             ACE_OS::strcpy (subtype, "80386");
00096           else if (sinfo.wProcessorLevel == 4)
00097             ACE_OS::strcpy (subtype, "80486");
00098           else if (sinfo.wProcessorLevel == 5)
00099             ACE_OS::strcpy (subtype, "Pentium");
00100           else if (sinfo.wProcessorLevel == 6)
00101             ACE_OS::strcpy (subtype, "Pentium Pro");
00102           else if (sinfo.wProcessorLevel == 7)  // I'm guessing here
00103             ACE_OS::strcpy (subtype, "Pentium II");
00104           break;
00105         case PROCESSOR_ARCHITECTURE_MIPS:
00106           ACE_OS::strcpy (processor, "MIPS");
00107           ACE_OS::strcpy (subtype, "R4000");
00108           break;
00109         case PROCESSOR_ARCHITECTURE_ALPHA:
00110           ACE_OS::strcpy (processor, "Alpha");
00111           ACE_OS::sprintf (subtype, "%d", sinfo.wProcessorLevel);
00112           break;
00113         case PROCESSOR_ARCHITECTURE_PPC:
00114           ACE_OS::strcpy (processor, "PPC");
00115           if (sinfo.wProcessorLevel == 1)
00116             ACE_OS::strcpy (subtype, "601");
00117           else if (sinfo.wProcessorLevel == 3)
00118             ACE_OS::strcpy (subtype, "603");
00119           else if (sinfo.wProcessorLevel == 4)
00120             ACE_OS::strcpy (subtype, "604");
00121           else if (sinfo.wProcessorLevel == 6)
00122             ACE_OS::strcpy (subtype, "603+");
00123           else if (sinfo.wProcessorLevel == 9)
00124             ACE_OS::strcpy (subtype, "804+");
00125           else if (sinfo.wProcessorLevel == 20)
00126             ACE_OS::strcpy (subtype, "620");
00127           break;
00128 #     if defined PROCESSOR_ARCHITECTURE_IA64
00129         case PROCESSOR_ARCHITECTURE_IA64:
00130           ACE_OS::strcpy (processor, "Itanium");
00131           ACE_OS::sprintf (subtype, "%d",
00132                            sinfo.wProcessorLevel);
00133           break;
00134 #     endif
00135 #     if defined PROCESSOR_ARCHITECTURE_AMD64
00136         case PROCESSOR_ARCHITECTURE_AMD64:
00137           ACE_OS::strcpy (processor, "x64");
00138           ACE_OS::sprintf (subtype, "%d",
00139                            sinfo.wProcessorLevel);
00140           break;
00141 #     endif
00142 #     if defined PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
00143         case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
00144           ACE_OS::strcpy (processor, "WOW64");
00145           ACE_OS::sprintf (subtype, "%d",
00146                            sinfo.wProcessorLevel);
00147           break;
00148 #     endif
00149 #     if defined PROCESSOR_ARCHITECTURE_ARM
00150         case PROCESSOR_ARCHITECTURE_ARM:
00151           ACE_OS::strcpy (processor, "ARM");
00152           ACE_OS::sprintf (subtype, "%d",
00153                            sinfo.wProcessorLevel);
00154           break;
00155 #     endif
00156         case PROCESSOR_ARCHITECTURE_UNKNOWN:
00157         default:
00158           // @@ We could provide WinCE specific info here.  But let's
00159           //    defer that to some later point.
00160           ACE_OS::strcpy (processor, "Unknown");
00161           break;
00162         }
00163       ACE_OS::sprintf (name->machine,
00164                        "%s %s",
00165                        processor, subtype);
00166     }
00167   else if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
00168     {
00169       if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 0)
00170         {
00171           ACE_OS::strcpy (name->release, "Windows 95");
00172           if (vinfo.szCSDVersion[1] == ACE_TEXT('C'))
00173             ACE_OS::strcat (name->release, " OSR2");
00174         }
00175       else if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 10)
00176         {
00177           ACE_OS::strcpy (name->release, "Windows 98");
00178           if (vinfo.szCSDVersion[1] == ACE_TEXT('A'))
00179             ACE_OS::strcat (name->release, " SE");
00180         }
00181       else if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 90)
00182         {
00183           ACE_OS::strcpy (name->release, "Windows Me");
00184         }
00185       else
00186         {
00187           ACE_OS::strcpy (name->release, unknown);
00188         }
00189 
00190       ACE_OS::sprintf (name->version, "%d", LOWORD (vinfo.dwBuildNumber));
00191       if (sinfo.dwProcessorType == PROCESSOR_INTEL_386)
00192         ACE_OS::strcpy (name->machine, "Intel 80386");
00193       else if (sinfo.dwProcessorType == PROCESSOR_INTEL_486)
00194         ACE_OS::strcpy (name->machine, "Intel 80486");
00195       else if (sinfo.dwProcessorType == PROCESSOR_INTEL_PENTIUM)
00196         ACE_OS::strcpy (name->machine, "Intel Pentium");
00197       else
00198         ACE_OS::strcpy (name->machine, unknown);
00199     }
00200   else
00201     {
00202       // We don't know what this is!
00203 
00204       ACE_OS::strcpy (name->release, unknown);
00205       ACE_OS::strcpy (name->version, unknown);
00206       ACE_OS::strcpy (name->machine, unknown);
00207     }
00208 
00209 # if defined (ACE_LACKS_HOSTNAME)
00210   return 0;
00211 # else /* ACE_LACKS_HOSTNAME */
00212   return ACE_OS::hostname (name->nodename, maxnamelen);
00213 # endif /* ACE_LACKS_HOSTNAME */
00214 
00215 #elif defined (ACE_VXWORKS)
00216   size_t maxnamelen = sizeof name->nodename;
00217   ACE_OS::strcpy (name->sysname, "VxWorks");
00218   ACE_OS::strcpy (name->release, kernelVersion());
00219   ACE_OS::strcpy (name->version, sysBspRev ());
00220   ACE_OS::strcpy (name->machine, sysModel ());
00221 
00222   return ACE_OS::hostname (name->nodename, maxnamelen);
00223 #elif defined (INTEGRITY)
00224   if(!name) {
00225     errno = EFAULT;
00226     return -1;
00227   }
00228   strcpy(name->sysname,"INTEGRITY");
00229   int status = gethostname(name->nodename,_SYS_NMLN);
00230   strcpy(name->release,"4.0");
00231   strcpy(name->version,"4.0.9");
00232   strcpy(name->machine,"a standard name");
00233   return status;
00234 #endif /* ACE_WIN32 */
00235 }
00236 
00237 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:41 2010 for ACE by  doxygen 1.4.7