Fixes compile failure if REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES defined

Message ID PAVPR10MB686294D1DE898DAF7D10EDAA991A2@PAVPR10MB6862.EURPRD10.PROD.OUTLOOK.COM
State New
Headers
Series Fixes compile failure if REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES defined |

Commit Message

Markus Eisenmann Jan. 16, 2025, 3 p.m. UTC
  Hi!

The attached patch will fix some compiler issues if the macros REENTRANT_SYSCALLS_PROVIDED and  MISSING_SYSCALL_NAMES ...

In case of stdio/fopen.c and stdio64/fopen64.c compiling with a newer compiler like GCC 14.2 will
abort with an error like "implicit declaration of ...", because the open() - as replacement of _open_r (see reent.h) -
isn't declared; I.e., including <fcntl.h> unconditionaly fixes this compile-issue.
Note: Older GCC's are more "relaxed" and - for example GCC 11.3 - does not warn about this implicit declaration ?!

Another similar issue was replacing _rename_r by rename() in stdio/rename.c whitch caused a "forever-
loop" or stack-overflow by recursion - depending on the optimization level.

Best regards from Austria,
Markus
From 020ef623fa0e49cf3c346ff0df53376c29a65f33 Mon Sep 17 00:00:00 2001
From: Markus Eisenmann <markus.eisenmann@outlook.com>
Date: Thu, 16 Jan 2025 15:13:54 +0100
Subject: [PATCH] Fixes compile failure if REENTRANT_SYSCALLS_PROVIDED and
 MISSING_SYSCALL_NAMES defined

If the macros REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES are defined some
_reent_*-functions are replaced by the system-call and this leads to compile-warning
or a runtime-failure.

 * newlib/libc/stdio/fopen.c _open_r is replaces by open(), declared in <fcntl.h>
 * newlib/libc/stdio64/fopen64.c ditto
 * newlib/libc/stdio/rename.c _rename_r is rename() itself; i.e, fix recursion
---
 newlib/libc/stdio/fopen.c     | 2 --
 newlib/libc/stdio/rename.c    | 3 ++-
 newlib/libc/stdio64/fopen64.c | 2 --
 3 files changed, 2 insertions(+), 5 deletions(-)
  

Comments

Corinna Vinschen Jan. 17, 2025, 1:09 p.m. UTC | #1
On Jan 16 15:00, Markus Eisenmann wrote:
> Hi!
> 
> The attached patch will fix some compiler issues if the macros REENTRANT_SYSCALLS_PROVIDED and  MISSING_SYSCALL_NAMES ...
> 
> In case of stdio/fopen.c and stdio64/fopen64.c compiling with a newer compiler like GCC 14.2 will
> abort with an error like "implicit declaration of ...", because the open() - as replacement of _open_r (see reent.h) -
> isn't declared; I.e., including <fcntl.h> unconditionaly fixes this compile-issue.
> Note: Older GCC's are more "relaxed" and - for example GCC 11.3 - does not warn about this implicit declaration ?!
> 
> Another similar issue was replacing _rename_r by rename() in stdio/rename.c whitch caused a "forever-
> loop" or stack-overflow by recursion - depending on the optimization level.
> 
> Best regards from Austria,
> Markus

> From 020ef623fa0e49cf3c346ff0df53376c29a65f33 Mon Sep 17 00:00:00 2001
> From: Markus Eisenmann <markus.eisenmann@outlook.com>
> Date: Thu, 16 Jan 2025 15:13:54 +0100
> Subject: [PATCH] Fixes compile failure if REENTRANT_SYSCALLS_PROVIDED and
>  MISSING_SYSCALL_NAMES defined
> 
> If the macros REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES are defined some
> _reent_*-functions are replaced by the system-call and this leads to compile-warning
> or a runtime-failure.
> 
>  * newlib/libc/stdio/fopen.c _open_r is replaces by open(), declared in <fcntl.h>
>  * newlib/libc/stdio64/fopen64.c ditto
>  * newlib/libc/stdio/rename.c _rename_r is rename() itself; i.e, fix recursion
> ---
>  newlib/libc/stdio/fopen.c     | 2 --
>  newlib/libc/stdio/rename.c    | 3 ++-
>  newlib/libc/stdio64/fopen64.c | 2 --
>  3 files changed, 2 insertions(+), 5 deletions(-)

Pushed.

Thanks,
Corinna
  

Patch

diff --git a/newlib/libc/stdio/fopen.c b/newlib/libc/stdio/fopen.c
index 1ac551fed..8239fd6b6 100644
--- a/newlib/libc/stdio/fopen.c
+++ b/newlib/libc/stdio/fopen.c
@@ -107,9 +107,7 @@  static char sccsid[] = "%W% (Berkeley) %G%";
 #include <stdio.h>
 #include <errno.h>
 #include <sys/lock.h>
-#ifdef __CYGWIN__
 #include <fcntl.h>
-#endif
 #include "local.h"
 
 FILE *
diff --git a/newlib/libc/stdio/rename.c b/newlib/libc/stdio/rename.c
index 16ef3e351..9abc0d39b 100644
--- a/newlib/libc/stdio/rename.c
+++ b/newlib/libc/stdio/rename.c
@@ -51,7 +51,8 @@  Supporting OS subroutines required: <<link>>, <<unlink>>, or <<rename>>.
 #include <stdio.h>
 #include <sys/unistd.h>
 
-#ifndef _REENT_ONLY
+#if !defined(_REENT_ONLY) && !( \
+    defined(REENTRANT_SYSCALLS_PROVIDED) && defined(MISSING_SYSCALL_NAMES))
 
 int
 rename (const char *old,
diff --git a/newlib/libc/stdio64/fopen64.c b/newlib/libc/stdio64/fopen64.c
index 75d2c2c41..4eee1f273 100644
--- a/newlib/libc/stdio64/fopen64.c
+++ b/newlib/libc/stdio64/fopen64.c
@@ -56,9 +56,7 @@  static char sccsid[] = "%W% (Berkeley) %G%";
 #include <stdio.h>
 #include <errno.h>
 #include "local.h"
-#ifdef __CYGWIN__
 #include <fcntl.h>
-#endif
 #include <sys/lock.h>
 
 #ifdef __LARGE64_FILES