summaryrefslogtreecommitdiff
path: root/ACE/ace/OS_NS_sys_utsname.cpp
blob: 8d4da8dbddd846810a9e1a9898653961b20b6633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "ace/OS_NS_sys_utsname.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_NS_errno.h"

#if defined (ACE_VXWORKS) && defined (ACE_LACKS_UNAME) && !defined (__RTP__)
// for sysBspRev(), sysModel()
#  include /**/ <sysLib.h>
// for kernelVersion()
#  include /**/ <kernelLib.h>
#endif /* ACE_VXWORKS && ACE_LACKS_UNAME */

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

int
ACE_OS::uname (ACE_utsname *name)
{
  ACE_OS_TRACE ("ACE_OS::uname");
#if !defined (ACE_LACKS_UNAME)
  return ::uname (name);
#elif defined (ACE_WIN32)
  size_t maxnamelen = sizeof name->nodename;
  ACE_OS::strcpy (name->sysname, "Win32");

# if defined (ACE_HAS_WIN32_GETVERSION)
  /* Since MS found it necessary to deprecate these. */
#   pragma warning(push)
#   pragma warning(disable:4996)
#   if defined(__clang__)
#     pragma clang diagnostic push
#     pragma clang diagnostic ignored "-Wdeprecated-declarations"
#   endif /* __clang__ */
  ACE_TEXT_OSVERSIONINFO vinfo;
  vinfo.dwOSVersionInfoSize = sizeof(ACE_TEXT_OSVERSIONINFO);
  ACE_TEXT_GetVersionEx (&vinfo);
#   if defined(__clang__)
#     pragma clang diagnostic pop
#   endif /* __clang__ */
#   pragma warning(pop)
# endif

  SYSTEM_INFO sinfo;
  ::GetSystemInfo(&sinfo);

  const char* unknown = "???";

# if defined (ACE_HAS_WIN32_GETVERSION)
  if (
      vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT
#   if defined (VER_PLATFORM_WIN32_CE)
      || vinfo.dwPlatformId == VER_PLATFORM_WIN32_CE
#   endif
      )
    {
      // Get information from the two structures
      const char *os = 0;
      if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
        os = "Windows NT %d.%d";
      else
        os = "Windows CE %d.%d";
      ACE_OS::snprintf (name->release, maxnamelen,
                        os,
                        (int) vinfo.dwMajorVersion,
                        (int) vinfo.dwMinorVersion);
      ACE_OS::snprintf (name->version, maxnamelen,
                        "Build %d %s",
                        (int) vinfo.dwBuildNumber,
                        ACE_TEXT_ALWAYS_CHAR (vinfo.szCSDVersion));

      // We have to make sure that the size of (processor + subtype)
      // is not greater than the size of name->machine.  So we give
      // half the space to the processor and half the space to
      // subtype.  The -1 is necessary for because of the space
      // between processor and subtype in the machine name.
      int const bufsize = (sizeof (name->machine) / 2) - 1;
      char processor[bufsize] = "Unknown";
      char subtype[bufsize] = "Unknown";

      WORD arch = sinfo.wProcessorArchitecture;

      switch (arch)
        {
        case PROCESSOR_ARCHITECTURE_INTEL:
          ACE_OS::strcpy (processor, "Intel");
          if (sinfo.wProcessorLevel == 3)
            ACE_OS::strcpy (subtype, "80386");
          else if (sinfo.wProcessorLevel == 4)
            ACE_OS::strcpy (subtype, "80486");
          else if (sinfo.wProcessorLevel == 5)
            ACE_OS::strcpy (subtype, "Pentium");
          else if (sinfo.wProcessorLevel == 6)
            ACE_OS::strcpy (subtype, "Pentium Pro");
          else if (sinfo.wProcessorLevel == 7)  // I'm guessing here
            ACE_OS::strcpy (subtype, "Pentium II");
          else
            ACE_OS::snprintf (subtype, bufsize, "%d", sinfo.wProcessorLevel);
          break;
        case PROCESSOR_ARCHITECTURE_MIPS:
          ACE_OS::strcpy (processor, "MIPS");
          if (sinfo.wProcessorLevel == 3)
            ACE_OS::strcpy (subtype, "R3000");
          else if (sinfo.wProcessorLevel == 4)
            ACE_OS::strcpy (subtype, "R4000");
          else
            ACE_OS::snprintf (subtype, bufsize, "%d", sinfo.wProcessorLevel);
          break;
        case PROCESSOR_ARCHITECTURE_ALPHA:
          ACE_OS::strcpy (processor, "Alpha");
          ACE_OS::snprintf (subtype, bufsize, "%d", sinfo.wProcessorLevel);
          break;
        case PROCESSOR_ARCHITECTURE_PPC:
          ACE_OS::strcpy (processor, "PPC");
          if (sinfo.wProcessorLevel == 1)
            ACE_OS::strcpy (subtype, "601");
          else if (sinfo.wProcessorLevel == 3)
            ACE_OS::strcpy (subtype, "603");
          else if (sinfo.wProcessorLevel == 4)
            ACE_OS::strcpy (subtype, "604");
          else if (sinfo.wProcessorLevel == 6)
            ACE_OS::strcpy (subtype, "603+");
          else if (sinfo.wProcessorLevel == 9)
            ACE_OS::strcpy (subtype, "804+");
          else if (sinfo.wProcessorLevel == 20)
            ACE_OS::strcpy (subtype, "620");
          break;
#     if defined PROCESSOR_ARCHITECTURE_IA64
        case PROCESSOR_ARCHITECTURE_IA64:
          ACE_OS::strcpy (processor, "Itanium");
          ACE_OS::snprintf (subtype, bufsize, "%d", sinfo.wProcessorLevel);
          break;
#     endif
#     if defined PROCESSOR_ARCHITECTURE_AMD64
        case PROCESSOR_ARCHITECTURE_AMD64:
          ACE_OS::strcpy (processor, "x64");
          ACE_OS::snprintf (subtype, bufsize, "%d", sinfo.wProcessorLevel);
          break;
#     endif
#     if defined PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
        case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
          ACE_OS::strcpy (processor, "WOW64");
          ACE_OS::snprintf (subtype, bufsize, "%d", sinfo.wProcessorLevel);
          break;
#     endif
#     if defined PROCESSOR_ARCHITECTURE_ARM
        case PROCESSOR_ARCHITECTURE_ARM:
          ACE_OS::strcpy (processor, "ARM");
          ACE_OS::snprintf (subtype, bufsize, "%d", sinfo.wProcessorLevel);
          break;
#     endif
        case PROCESSOR_ARCHITECTURE_UNKNOWN:
        default:
          ACE_OS::strcpy (processor, "Unknown");
          break;
        }
      ACE_OS::snprintf (name->machine, maxnamelen, "%s %s", processor, subtype);
    }
  else if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
    {
      if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 0)
        {
          ACE_OS::strcpy (name->release, "Windows 95");
          if (vinfo.szCSDVersion[1] == ACE_TEXT('C'))
            ACE_OS::strcat (name->release, " OSR2");
        }
      else if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 10)
        {
          ACE_OS::strcpy (name->release, "Windows 98");
          if (vinfo.szCSDVersion[1] == ACE_TEXT('A'))
            ACE_OS::strcat (name->release, " SE");
        }
      else if (vinfo.dwMajorVersion == 4 && vinfo.dwMinorVersion == 90)
        {
          ACE_OS::strcpy (name->release, "Windows Me");
        }
      else
        {
          ACE_OS::strcpy (name->release, unknown);
        }

      ACE_OS::snprintf (name->version, maxnamelen, "%d",
                        LOWORD (vinfo.dwBuildNumber));
      if (sinfo.dwProcessorType == PROCESSOR_INTEL_386)
        ACE_OS::strcpy (name->machine, "Intel 80386");
      else if (sinfo.dwProcessorType == PROCESSOR_INTEL_486)
        ACE_OS::strcpy (name->machine, "Intel 80486");
      else if (sinfo.dwProcessorType == PROCESSOR_INTEL_PENTIUM)
        ACE_OS::strcpy (name->machine, "Intel Pentium");
      else
        ACE_OS::strcpy (name->machine, unknown);
    }
  else
# endif /* !ACE_HAS_WIN32_GETVERSION */
    {
      // We don't know what this is!

      ACE_OS::strcpy (name->release, unknown);
      ACE_OS::strcpy (name->version, unknown);
      ACE_OS::strcpy (name->machine, unknown);
    }

# if defined (ACE_LACKS_HOSTNAME)
  return 0;
# else /* ACE_LACKS_HOSTNAME */
  return ACE_OS::hostname (name->nodename, maxnamelen);
# endif /* ACE_LACKS_HOSTNAME */

#elif defined (ACE_VXWORKS) && !defined (__RTP__)
  size_t const maxnamelen = sizeof name->nodename;
  ACE_OS::strcpy (name->sysname, "VxWorks");
  ACE_OS::strcpy (name->release, kernelVersion());
  ACE_OS::strcpy (name->version, sysBspRev ());
  ACE_OS::strcpy (name->machine, sysModel ());

  return ACE_OS::hostname (name->nodename, maxnamelen);
#elif defined (INTEGRITY)
  if(!name) {
    errno = EFAULT;
    return -1;
  }
  strcpy(name->sysname,"INTEGRITY");
  int status = gethostname(name->nodename,_SYS_NMLN);
  strcpy(name->release,"4.0");
  strcpy(name->version,"4.0.9");
  strcpy(name->machine,"a standard name");
  return status;
#else
  ACE_UNUSED_ARG (name);
  ACE_NOTSUP_RETURN (-1);
#endif /* ACE_WIN32 */
}

ACE_END_VERSIONED_NAMESPACE_DECL