Skip to content

Commit 06ac3e1

Browse files
committed
uname: allow setting the system name to CYGWIN
We are currently trying to move our cygwin build environment closer to cygwin and some autotools/bash based build systems call "uname -s" to figure out the OS and in many cases only handle the cygwin case, so we have to patch them. With this instead of patching we can set MSYSTEM=CYGWIN and change uname output that way. The next step would be to always output CYGWIN in an msys env by default, but for now this allows us to get rid of all the patches without affecting users.
1 parent 78cf542 commit 06ac3e1

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

winsup/cygwin/uname.cc

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ extern "C" int getdomainname (char *__name, size_t __len);
2424
#define ATTRIBUTE_NONSTRING
2525
#endif
2626

27+
static const char*
28+
get_sysname()
29+
{
30+
#ifdef __MSYS__
31+
char* msystem = getenv("MSYSTEM");
32+
if (!msystem || strcmp(msystem, "MSYS") == 0)
33+
return "MSYS";
34+
else if (strcmp(msystem, "CYGWIN") == 0)
35+
return "CYGWIN";
36+
else if (strstr(msystem, "32") != NULL)
37+
return "MINGW32";
38+
else
39+
return "MINGW64";
40+
#else
41+
return "CYGWIN";
42+
#endif
43+
}
44+
2745
/* uname: POSIX 4.4.1.1 */
2846

2947
/* New entrypoint for applications since API 335 */
@@ -36,12 +54,9 @@ uname_x (struct utsname *name)
3654

3755
memset (name, 0, sizeof (*name));
3856
/* sysname */
39-
char* msystem = getenv("MSYSTEM");
40-
const char* msystem_sysname = "MSYS";
41-
if (msystem != NULL && *msystem && strcmp(msystem, "MSYS") != 0)
42-
msystem_sysname = (strstr(msystem, "32") != NULL) ? "MINGW32" : "MINGW64";;
57+
const char* sysname = get_sysname();
4358
__small_sprintf (name->sysname, "%s_%s-%u",
44-
msystem_sysname,
59+
sysname,
4560
wincap.osname (), wincap.build_number ());
4661
/* nodename */
4762
memset (buf, 0, sizeof buf);
@@ -107,15 +122,8 @@ uname (struct utsname *in_name)
107122
__try
108123
{
109124
memset (name, 0, sizeof (*name));
110-
#ifdef __MSYS__
111-
char* msystem = getenv("MSYSTEM");
112-
const char* msystem_sysname = "MSYS";
113-
if (msystem != NULL && *msystem && strcmp(msystem, "MSYS") != 0)
114-
msystem_sysname = (strstr(msystem, "32") != NULL) ? "MINGW32" : "MINGW64";
115-
__small_sprintf (name->sysname, "%s_%s", msystem_sysname, wincap.osname ());
116-
#else
117-
__small_sprintf (name->sysname, "CYGWIN_%s", wincap.osname ());
118-
#endif
125+
const char* sysname = get_sysname();
126+
__small_sprintf (name->sysname, "%s_%s", sysname, wincap.osname ());
119127

120128
/* Computer name */
121129
cygwin_gethostname (name->nodename, sizeof (name->nodename) - 1);

0 commit comments

Comments
 (0)