MSYS2-packages/msys2-runtime/0032-uname-allow-setting-the-system-name-to-CYGWIN.patch
2025-06-08 07:56:29 +02:00

83 lines
2.9 KiB
Diff

From 5f01a6f359f1ad9af7bec6fa393b2e2bbe3f7617 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Sun, 3 Jul 2022 22:39:32 +0200
Subject: [PATCH 32/N] 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.
---
winsup/cygwin/uname.cc | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/winsup/cygwin/uname.cc b/winsup/cygwin/uname.cc
index ed4c9c5..cca66be 100644
--- a/winsup/cygwin/uname.cc
+++ b/winsup/cygwin/uname.cc
@@ -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 */
@@ -37,12 +55,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();
n = __small_sprintf (name->sysname, "%s_%s-%u",
- msystem_sysname,
+ sysname,
wincap.osname (), wincap.build_number ());
if (wincap.host_machine () != wincap.cygwin_machine ())
{
@@ -123,15 +138,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);