Skip to content

Commit b03e6f9

Browse files
lazkadscho
authored andcommitted
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 8023549 commit b03e6f9

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 */
@@ -37,12 +55,9 @@ uname_x (struct utsname *name)
3755

3856
memset (name, 0, sizeof (*name));
3957
/* sysname */
40-
char* msystem = getenv("MSYSTEM");
41-
const char* msystem_sysname = "MSYS";
42-
if (msystem != NULL && *msystem && strcmp(msystem, "MSYS") != 0)
43-
msystem_sysname = (strstr(msystem, "32") != NULL) ? "MINGW32" : "MINGW64";;
58+
const char* sysname = get_sysname();
4459
n = __small_sprintf (name->sysname, "%s_%s-%u",
45-
msystem_sysname,
60+
sysname,
4661
wincap.osname (), wincap.build_number ());
4762
if (wincap.host_machine () != wincap.cygwin_machine ())
4863
{
@@ -123,15 +138,8 @@ uname (struct utsname *in_name)
123138
__try
124139
{
125140
memset (name, 0, sizeof (*name));
126-
#ifdef __MSYS__
127-
char* msystem = getenv("MSYSTEM");
128-
const char* msystem_sysname = "MSYS";
129-
if (msystem != NULL && *msystem && strcmp(msystem, "MSYS") != 0)
130-
msystem_sysname = (strstr(msystem, "32") != NULL) ? "MINGW32" : "MINGW64";
131-
__small_sprintf (name->sysname, "%s_%s", msystem_sysname, wincap.osname ());
132-
#else
133-
__small_sprintf (name->sysname, "CYGWIN_%s", wincap.osname ());
134-
#endif
141+
const char* sysname = get_sysname();
142+
__small_sprintf (name->sysname, "%s_%s", sysname, wincap.osname ());
135143

136144
/* Computer name */
137145
cygwin_gethostname (name->nodename, sizeof (name->nodename) - 1);

0 commit comments

Comments
 (0)