Cygwin: add newgrp release notes
[newlib-cygwin.git] / winsup / cygwin / uname.cc
blobdd4160189c3a3b26c2d6655a456eb7714adeb8c2
1 /* uname.cc
2 Written by Steve Chamberlain of Cygnus Support, sac@cygnus.com
3 Rewritten by Geoffrey Noer of Cygnus Solutions, noer@cygnus.com
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 details. */
11 #include "winsup.h"
12 #include <stdio.h>
13 #include <sys/utsname.h>
14 #include <netdb.h>
15 #include "cygwin_version.h"
16 #include "cygtls.h"
18 extern "C" int cygwin_gethostname (char *__name, size_t __len);
19 extern "C" int getdomainname (char *__name, size_t __len);
21 #if __GNUC__ >= 8
22 #define ATTRIBUTE_NONSTRING __attribute__ ((nonstring))
23 #else
24 #define ATTRIBUTE_NONSTRING
25 #endif
27 /* uname: POSIX 4.4.1.1 */
29 /* New entrypoint for applications since API 335 */
30 extern "C" int
31 uname_x (struct utsname *name)
33 __try
35 char buf[NI_MAXHOST + 1] ATTRIBUTE_NONSTRING;
37 memset (name, 0, sizeof (*name));
38 /* sysname */
39 __small_sprintf (name->sysname, "CYGWIN_%s-%u",
40 wincap.osname (), wincap.build_number ());
41 /* nodename */
42 memset (buf, 0, sizeof buf);
43 cygwin_gethostname (buf, sizeof buf - 1);
44 strncat (name->nodename, buf, sizeof (name->nodename) - 1);
45 /* machine */
46 switch (wincap.cpu_arch ())
48 case PROCESSOR_ARCHITECTURE_AMD64:
49 strcpy (name->machine, "x86_64");
50 break;
51 default:
52 strcpy (name->machine, "unknown");
53 break;
55 /* release */
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wformat-truncation="
58 #ifdef CYGPORT_RELEASE_INFO
59 snprintf (name->release, _UTSNAME_LENGTH, "%s.%s",
60 __XSTRING (CYGPORT_RELEASE_INFO), name->machine);
61 #else
62 extern const char *uname_dev_version;
63 if (uname_dev_version && uname_dev_version[0])
64 snprintf (name->release, _UTSNAME_LENGTH, "%s.%s",
65 uname_dev_version, name->machine);
66 else
67 __small_sprintf (name->release, "%d.%d.%d-api-%d.%s",
68 cygwin_version.dll_major / 1000,
69 cygwin_version.dll_major % 1000,
70 cygwin_version.dll_minor,
71 cygwin_version.api_minor,
72 name->machine);
73 #endif
74 #pragma GCC diagnostic pop
75 /* version */
76 stpcpy (name->version, cygwin_version.dll_build_date);
77 strcat (name->version, " UTC");
78 /* domainame */
79 memset (buf, 0, sizeof buf);
80 getdomainname (buf, sizeof buf - 1);
81 strncat (name->domainname, buf, sizeof (name->domainname) - 1);
83 __except (EFAULT) { return -1; }
84 __endtry
85 return 0;
88 /* Old entrypoint for applications up to API 334 */
89 struct old_utsname
91 char sysname[20];
92 char nodename[20];
93 char release[20];
94 char version[20];
95 char machine[20];
98 extern "C" int
99 uname (struct utsname *in_name)
101 struct old_utsname *name = (struct old_utsname *) in_name;
102 __try
104 memset (name, 0, sizeof (*name));
105 __small_sprintf (name->sysname, "CYGWIN_%s", wincap.osname ());
107 /* Computer name */
108 cygwin_gethostname (name->nodename, sizeof (name->nodename) - 1);
110 /* Cygwin dll release */
111 __small_sprintf (name->release, "%d.%d.%d(%d.%d/%d/%d)",
112 cygwin_version.dll_major / 1000,
113 cygwin_version.dll_major % 1000,
114 cygwin_version.dll_minor,
115 cygwin_version.api_major,
116 cygwin_version.api_minor,
117 cygwin_version.shared_data,
118 cygwin_version.mount_registry);
120 /* Cygwin "version" aka build date */
121 strcpy (name->version, cygwin_version.dll_build_date);
123 /* CPU type */
124 switch (wincap.cpu_arch ())
126 case PROCESSOR_ARCHITECTURE_AMD64:
127 strcpy (name->machine, "x86_64");
128 break;
129 default:
130 strcpy (name->machine, "unknown");
131 break;
134 __except (EFAULT)
136 return -1;
138 __endtry
139 return 0;