[PATCH] Fixes compile failure if REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES defined

Markus Eisenmann <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <PAVPR10MB686294D1DE898DAF7D10EDAA991A2@PAVPR10MB6862.EURPRD10.PROD.OUTLOOK.COM>
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
0001-Fixes-compile-failure-if-REENTRANT_SYSCALLS_PROVIDED.patch (text/plain, 2 KB)
From 020ef623fa0e49cf3c346ff0df53376c29a65f33 Mon Sep 17 00:00:00 2001
From: Markus Eisenmann <[email protected]>
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(-)

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
-- 
2.47.1.windows.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.