OS_NS_sys_utsname.cpp

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

Generated on Sun Jan 27 12:05:33 2008 for ACE by doxygen 1.3.6