public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH 1/2] Cygwin: add compile warning if ENOSHARE or ECASECLASH is used
@ 2024-02-27 12:16 Christian Franke
  2024-02-27 12:18 ` [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from _sys_errlist[] Christian Franke
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Franke @ 2024-02-27 12:16 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 271 bytes --]

A suggestion for a first (possibly polite) step to get rid of ENOSHARE 
or ECASECLASH. Would also work with clang.

The internally used ENMFILE is not included yet. In theory, it may be 
returned to outside world as it still appears in errmap[].

-- 
Regards,
Christian


[-- Attachment #2: 0001-Cygwin-add-compile-warning-if-ENOSHARE-or-ECASECLASH.patch --]
[-- Type: text/plain, Size: 1343 bytes --]

From f3ad1912a9c7fa4cd28ade5dc7c95134be759615 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Tue, 27 Feb 2024 13:03:08 +0100
Subject: [PATCH 1/2] Cygwin: add compile warning if ENOSHARE or ECASECLASH is
 used

These errno values are no longer used by Cygwin.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 newlib/libc/include/sys/errno.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/newlib/libc/include/sys/errno.h b/newlib/libc/include/sys/errno.h
index f1509712e..7199db0d2 100644
--- a/newlib/libc/include/sys/errno.h
+++ b/newlib/libc/include/sys/errno.h
@@ -176,9 +176,9 @@ extern __IMPORT char *program_invocation_short_name;
 #ifdef __LINUX_ERRNO_EXTENSIONS__
 #define ENOMEDIUM 135   /* No medium (in tape drive) */
 #endif
-#ifdef __CYGWIN__
-#define ENOSHARE 136    /* No such host or network path */
-#define ECASECLASH 137  /* Filename exists with different case */
+#if defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
+#define ENOSHARE (_Pragma("GCC warning \"'ENOSHARE' is no longer used by Cygwin\"") 136)
+#define ECASECLASH (_Pragma("GCC warning \"'ECASECLASH' is no longer used by Cygwin\"") 137)
 #endif
 #define EILSEQ 138		/* Illegal byte sequence */
 #define EOVERFLOW 139	/* Value too large for defined data type */
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from _sys_errlist[]
  2024-02-27 12:16 [PATCH 1/2] Cygwin: add compile warning if ENOSHARE or ECASECLASH is used Christian Franke
@ 2024-02-27 12:18 ` Christian Franke
  2024-02-27 14:59   ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Franke @ 2024-02-27 12:18 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0002-Cygwin-remove-ENOSHARE-and-ECASECLASH-from-_sys_errl.patch --]
[-- Type: text/plain, Size: 1511 bytes --]

From f495fb0e7c2bd3a42f16f81af18c64ffaba9a860 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Tue, 27 Feb 2024 13:05:36 +0100
Subject: [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from
 _sys_errlist[]

These errno values are no longer used by Cygwin.  Also add a
static_assert check for _sys_errlist[] size.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 winsup/cygwin/errno.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc
index 7d58e62ec..d8c057e51 100644
--- a/winsup/cygwin/errno.cc
+++ b/winsup/cygwin/errno.cc
@@ -167,8 +167,8 @@ const char *_sys_errlist[] =
 /* ESTALE 133 */	  "Stale NFS file handle",
 /* ENOTSUP 134 */	  "Not supported",
 /* ENOMEDIUM 135 */	  "No medium found",
-/* ENOSHARE 136 */	  "No such host or network path",
-/* ECASECLASH 137 */	  "Filename exists with different case",
+			  NULL, /* Was ENOSHARE 136, no longer used. */
+			  NULL, /* Was ECASECLASH 137, no longer used. */
 /* EILSEQ 138 */	  "Invalid or incomplete multibyte or wide character",
 /* EOVERFLOW 139 */	  "Value too large for defined data type",
 /* ECANCELED 140 */	  "Operation canceled",
@@ -177,6 +177,8 @@ const char *_sys_errlist[] =
 /* ESTRPIPE 143 */	  "Streams pipe error"
 };
 
+static_assert(143 + 1 == sizeof (_sys_errlist) / sizeof (_sys_errlist[0]));
+
 int NO_COPY_INIT _sys_nerr = sizeof (_sys_errlist) / sizeof (_sys_errlist[0]);
 };
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from _sys_errlist[]
  2024-02-27 12:18 ` [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from _sys_errlist[] Christian Franke
@ 2024-02-27 14:59   ` Corinna Vinschen
  2024-02-27 16:26     ` Christian Franke
  0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2024-02-27 14:59 UTC (permalink / raw)
  To: cygwin-patches

Hi Christian,

On Feb 27 13:18, Christian Franke wrote:
> From f495fb0e7c2bd3a42f16f81af18c64ffaba9a860 Mon Sep 17 00:00:00 2001
> From: Christian Franke <christian.franke@t-online.de>
> Date: Tue, 27 Feb 2024 13:05:36 +0100
> Subject: [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from
>  _sys_errlist[]
> 
> These errno values are no longer used by Cygwin.  Also add a
> static_assert check for _sys_errlist[] size.
> 
> Signed-off-by: Christian Franke <christian.franke@t-online.de>
> ---
>  winsup/cygwin/errno.cc | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc
> index 7d58e62ec..d8c057e51 100644
> --- a/winsup/cygwin/errno.cc
> +++ b/winsup/cygwin/errno.cc
> @@ -167,8 +167,8 @@ const char *_sys_errlist[] =
>  /* ESTALE 133 */	  "Stale NFS file handle",
>  /* ENOTSUP 134 */	  "Not supported",
>  /* ENOMEDIUM 135 */	  "No medium found",
> -/* ENOSHARE 136 */	  "No such host or network path",
> -/* ECASECLASH 137 */	  "Filename exists with different case",
> +			  NULL, /* Was ENOSHARE 136, no longer used. */
> +			  NULL, /* Was ECASECLASH 137, no longer used. */

In terms of politenness, wouldn't it be better to define them as
empty strings?  This may be one crash less in already existing
binaries...


Corinna

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from _sys_errlist[]
  2024-02-27 14:59   ` Corinna Vinschen
@ 2024-02-27 16:26     ` Christian Franke
  2024-02-28  9:01       ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Franke @ 2024-02-27 16:26 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 882 bytes --]

Hi Corinna,

Corinna Vinschen wrote:
> On Feb 27 13:18, Christian Franke wrote:
>> ...
>>
>> diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc
>> index 7d58e62ec..d8c057e51 100644
>> --- a/winsup/cygwin/errno.cc
>> +++ b/winsup/cygwin/errno.cc
>> @@ -167,8 +167,8 @@ const char *_sys_errlist[] =
>>   /* ESTALE 133 */	  "Stale NFS file handle",
>>   /* ENOTSUP 134 */	  "Not supported",
>>   /* ENOMEDIUM 135 */	  "No medium found",
>> -/* ENOSHARE 136 */	  "No such host or network path",
>> -/* ECASECLASH 137 */	  "Filename exists with different case",
>> +			  NULL, /* Was ENOSHARE 136, no longer used. */
>> +			  NULL, /* Was ECASECLASH 137, no longer used. */
> In terms of politenness, wouldn't it be better to define them as
> empty strings?  This may be one crash less in already existing
> binaries...

Indeed, I missed that case. Patch attached.

Christian


[-- Attachment #2: 0002-Cygwin-set-ENOSHARE-and-ECASECLASH-_sys_errlist-entr.patch --]
[-- Type: text/plain, Size: 2033 bytes --]

From 151da4ef76f84cd0343e6f49aa23de398ca73d1c Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Tue, 27 Feb 2024 17:21:45 +0100
Subject: [PATCH 2/2] Cygwin: set ENOSHARE and ECASECLASH _sys_errlist[]
 entries to empty

These errno values are no longer used by Cygwin.  Change the entries
to empty strings instead of NULL to avoid crashes in existing
binaries directly accessing the table.  Enhance strerror_worker()
such that empty strings also result in "Unknown error ..." messages.
Also add a static_assert check for the _sys_errlist[] size.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 winsup/cygwin/errno.cc | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc
index 7d58e62ec..004a4021e 100644
--- a/winsup/cygwin/errno.cc
+++ b/winsup/cygwin/errno.cc
@@ -167,8 +167,8 @@ const char *_sys_errlist[] =
 /* ESTALE 133 */	  "Stale NFS file handle",
 /* ENOTSUP 134 */	  "Not supported",
 /* ENOMEDIUM 135 */	  "No medium found",
-/* ENOSHARE 136 */	  "No such host or network path",
-/* ECASECLASH 137 */	  "Filename exists with different case",
+			  "", /* Was ENOSHARE 136, no longer used. */
+			  "", /* Was ECASECLASH 137, no longer used. */
 /* EILSEQ 138 */	  "Invalid or incomplete multibyte or wide character",
 /* EOVERFLOW 139 */	  "Value too large for defined data type",
 /* ECANCELED 140 */	  "Operation canceled",
@@ -177,6 +177,8 @@ const char *_sys_errlist[] =
 /* ESTRPIPE 143 */	  "Streams pipe error"
 };
 
+static_assert(143 + 1 == sizeof (_sys_errlist) / sizeof (_sys_errlist[0]));
+
 int NO_COPY_INIT _sys_nerr = sizeof (_sys_errlist) / sizeof (_sys_errlist[0]);
 };
 
@@ -228,7 +230,11 @@ strerror_worker (int errnum)
 {
   char *res;
   if (errnum >= 0 && errnum < _sys_nerr)
-    res = (char *) _sys_errlist [errnum];
+    {
+      res = (char *) _sys_errlist [errnum];
+      if (res && !*res)
+	res = NULL;
+    }
   else
     res = NULL;
   return res;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from _sys_errlist[]
  2024-02-27 16:26     ` Christian Franke
@ 2024-02-28  9:01       ` Corinna Vinschen
  0 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2024-02-28  9:01 UTC (permalink / raw)
  To: cygwin-patches

On Feb 27 17:26, Christian Franke wrote:
> Hi Corinna,
> 
> Corinna Vinschen wrote:
> > On Feb 27 13:18, Christian Franke wrote:
> > > ...
> > > 
> > > diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc
> > > index 7d58e62ec..d8c057e51 100644
> > > --- a/winsup/cygwin/errno.cc
> > > +++ b/winsup/cygwin/errno.cc
> > > @@ -167,8 +167,8 @@ const char *_sys_errlist[] =
> > >   /* ESTALE 133 */	  "Stale NFS file handle",
> > >   /* ENOTSUP 134 */	  "Not supported",
> > >   /* ENOMEDIUM 135 */	  "No medium found",
> > > -/* ENOSHARE 136 */	  "No such host or network path",
> > > -/* ECASECLASH 137 */	  "Filename exists with different case",
> > > +			  NULL, /* Was ENOSHARE 136, no longer used. */
> > > +			  NULL, /* Was ECASECLASH 137, no longer used. */
> > In terms of politenness, wouldn't it be better to define them as
> > empty strings?  This may be one crash less in already existing
> > binaries...
> 
> Indeed, I missed that case. Patch attached.
> 
> Christian
> 

> From 151da4ef76f84cd0343e6f49aa23de398ca73d1c Mon Sep 17 00:00:00 2001
> From: Christian Franke <christian.franke@t-online.de>
> Date: Tue, 27 Feb 2024 17:21:45 +0100
> Subject: [PATCH 2/2] Cygwin: set ENOSHARE and ECASECLASH _sys_errlist[]
>  entries to empty
> 
> These errno values are no longer used by Cygwin.  Change the entries
> to empty strings instead of NULL to avoid crashes in existing
> binaries directly accessing the table.  Enhance strerror_worker()
> such that empty strings also result in "Unknown error ..." messages.
> Also add a static_assert check for the _sys_errlist[] size.
> 
> Signed-off-by: Christian Franke <christian.franke@t-online.de>
> ---
>  winsup/cygwin/errno.cc | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)

Pushed.

Thanks,
Corinna


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-28  9:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 12:16 [PATCH 1/2] Cygwin: add compile warning if ENOSHARE or ECASECLASH is used Christian Franke
2024-02-27 12:18 ` [PATCH 2/2] Cygwin: remove ENOSHARE and ECASECLASH from _sys_errlist[] Christian Franke
2024-02-27 14:59   ` Corinna Vinschen
2024-02-27 16:26     ` Christian Franke
2024-02-28  9:01       ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).