OSDN Git Service

Initial checkin of text Corinna sent to cygwin-announce.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / uname.cc
1 /* uname.cc
2
3    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4    2005, 2006, 2007 Red Hat, Inc.
5    Written by Steve Chamberlain of Cygnus Support, sac@cygnus.com
6    Rewritten by Geoffrey Noer of Cygnus Solutions, noer@cygnus.com
7
8 This file is part of Cygwin.
9
10 This software is a copyrighted work licensed under the terms of the
11 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
12 details. */
13
14 #include "winsup.h"
15 #include <sys/utsname.h>
16 #include "cygwin_version.h"
17 #include "cygtls.h"
18
19 /* uname: POSIX 4.4.1.1 */
20 extern "C" int
21 uname (struct utsname *name)
22 {
23   SYSTEM_INFO sysinfo;
24
25   myfault efault;
26   if (efault.faulted (EFAULT))
27     return -1;
28
29   char *snp = strstr  (cygwin_version.dll_build_date, "SNP");
30
31   memset (name, 0, sizeof (*name));
32   __small_sprintf (name->sysname, "CYGWIN_%s", wincap.osname ());
33
34 #if 0
35   /* Recognition of the real 64 bit CPU inside of a WOW64 system, irritates
36      build systems which think the native system is a 64 bit system.  Since
37      we're actually running in a 32 bit environment, it looks more correct
38      just to use the CPU info given by WOW64. */
39   if (wincap.is_wow64 ())
40     GetNativeSystemInfo (&sysinfo);
41   else
42 #else
43   /* But it seems ok to add a hint to the sysname, that we're running under
44      WOW64.  This might give an early clue if somebody encounters problems. */
45   if (wincap.is_wow64 ())
46     strncat (name->sysname, "-WOW64",
47              sizeof name->sysname - strlen (name->sysname) - 1);
48 #endif
49     GetSystemInfo (&sysinfo);
50
51   /* Computer name */
52   cygwin_gethostname (name->nodename, sizeof (name->nodename) - 1);
53
54   /* Cygwin dll release */
55   __small_sprintf (name->release, "%d.%d.%d%s(%d.%d/%d/%d)",
56                    cygwin_version.dll_major / 1000,
57                    cygwin_version.dll_major % 1000,
58                    cygwin_version.dll_minor,
59                    snp ? "s" : "",
60                    cygwin_version.api_major,
61                    cygwin_version.api_minor,
62                    cygwin_version.shared_data,
63                    cygwin_version.mount_registry);
64
65   /* Cygwin "version" aka build date */
66   strcpy (name->version, cygwin_version.dll_build_date);
67   if (snp)
68     name->version[snp - cygwin_version.dll_build_date] = '\0';
69
70   /* CPU type */
71   switch (sysinfo.wProcessorArchitecture)
72     {
73       case PROCESSOR_ARCHITECTURE_INTEL:
74         unsigned int ptype;
75         if (sysinfo.wProcessorLevel < 3) /* Shouldn't happen. */
76           ptype = 3;
77         else if (sysinfo.wProcessorLevel > 9) /* P4 */
78           ptype = 6;
79         else
80           ptype = sysinfo.wProcessorLevel;
81         __small_sprintf (name->machine, "i%d86", ptype);
82         break;
83       case PROCESSOR_ARCHITECTURE_IA64:
84         strcpy (name->machine, "ia64");
85         break;
86       case PROCESSOR_ARCHITECTURE_AMD64:
87         strcpy (name->machine, "x86_64");
88         break;
89       case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
90         strcpy (name->machine, "ia32-win64");
91         break;
92       case PROCESSOR_ARCHITECTURE_ALPHA:
93         strcpy (name->machine, "alpha");
94         break;
95       case PROCESSOR_ARCHITECTURE_MIPS:
96         strcpy (name->machine, "mips");
97         break;
98       default:
99         strcpy (name->machine, "unknown");
100         break;
101     }
102
103   return 0;
104 }