Skip to content

Commit

Permalink
uname: allow setting the system name to CYGWIN
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lazka authored and dscho committed Aug 27, 2024
1 parent 9c758e8 commit 312f766
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions winsup/cygwin/uname.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ extern "C" int getdomainname (char *__name, size_t __len);
#define ATTRIBUTE_NONSTRING
#endif

static const char*
get_sysname()
{
#ifdef __MSYS__
char* msystem = getenv("MSYSTEM");
if (!msystem || strcmp(msystem, "MSYS") == 0)
return "MSYS";
else if (strcmp(msystem, "CYGWIN") == 0)
return "CYGWIN";
else if (strstr(msystem, "32") != NULL)
return "MINGW32";
else
return "MINGW64";
#else
return "CYGWIN";
#endif
}

/* uname: POSIX 4.4.1.1 */

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

memset (name, 0, sizeof (*name));
/* sysname */
char* msystem = getenv("MSYSTEM");
const char* msystem_sysname = "MSYS";
if (msystem != NULL && *msystem && strcmp(msystem, "MSYS") != 0)
msystem_sysname = (strstr(msystem, "32") != NULL) ? "MINGW32" : "MINGW64";;
const char* sysname = get_sysname();
__small_sprintf (name->sysname, "%s_%s-%u",
msystem_sysname,
sysname,
wincap.osname (), wincap.build_number ());
/* nodename */
memset (buf, 0, sizeof buf);
Expand Down Expand Up @@ -107,15 +122,8 @@ uname (struct utsname *in_name)
__try
{
memset (name, 0, sizeof (*name));
#ifdef __MSYS__
char* msystem = getenv("MSYSTEM");
const char* msystem_sysname = "MSYS";
if (msystem != NULL && *msystem && strcmp(msystem, "MSYS") != 0)
msystem_sysname = (strstr(msystem, "32") != NULL) ? "MINGW32" : "MINGW64";
__small_sprintf (name->sysname, "%s_%s", msystem_sysname, wincap.osname ());
#else
__small_sprintf (name->sysname, "CYGWIN_%s", wincap.osname ());
#endif
const char* sysname = get_sysname();
__small_sprintf (name->sysname, "%s_%s", sysname, wincap.osname ());

/* Computer name */
cygwin_gethostname (name->nodename, sizeof (name->nodename) - 1);
Expand Down

0 comments on commit 312f766

Please sign in to comment.