[4/6] libgloss: i386: move profil_write() from cygmon-salib.c to cygmon-gmon.c

Message ID 20251029-fix-libgloss-i386-compile-issues-v1-4-26edcb02f69c@kernel.org
State New
Headers
Series libgloss: i386: fix compilation issues |

Commit Message

Vincent Mailhol Oct. 29, 2025, 6:58 a.m. UTC
  _mcleanup() uses profil_write(). However, there is no prior
declaration of profil_write() in cygmon-gmon.c leading to below GCC
error:

  cygmon-gmon.c: In function '_mcleanup':
  cygmon-gmon.c:203:3: error: implicit declaration of function 'profil_write' [-Wimplicit-function-declaration]
    203 |   profil_write (1, sbuf, ssiz);
        |   ^~~~~~~~~~~~

As a matter of facts, profil_write() is never used elsewhere than
cygmon-gmon.c. Move profil_write() from cygmon-salib.c to
cygmon-gmon.c. Add the required fcntl.h include. Also, change the
type of profil_write()'s buffer parameter from char * to void * to
prevent an incompatible pointer type warning. Finally, mark
profil_write() as being a static function to make it clear that it is
not used outside of the translation unit.

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
 libgloss/i386/cygmon-gmon.c  | 20 ++++++++++++++++++++
 libgloss/i386/cygmon-salib.c | 19 -------------------
 2 files changed, 20 insertions(+), 19 deletions(-)
  

Patch

diff --git a/libgloss/i386/cygmon-gmon.c b/libgloss/i386/cygmon-gmon.c
index 88bdf251c..778dbd76d 100644
--- a/libgloss/i386/cygmon-gmon.c
+++ b/libgloss/i386/cygmon-gmon.c
@@ -62,6 +62,7 @@  static char sccsid[] = "@(#)gmon.c	5.3 (Berkeley) 5/22/91";
 #include <stdio.h>
 #endif
 
+#include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -193,6 +194,25 @@  monstartup(lowpc, highpc)
   moncontrol (1);
 }
 
+static void
+profil_write (int type, void *buffer, int len)
+{
+  static int des = -1;
+
+  if (des < 0)
+    {
+      des = open ("gmon.out", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+    }
+  if (len == 0)
+    {
+      close (des);
+    }
+  else
+    {
+      write (des, buffer, len);
+    }
+}
+
 void
 _mcleanup()
 {
diff --git a/libgloss/i386/cygmon-salib.c b/libgloss/i386/cygmon-salib.c
index b4a4d34b3..734afe9d6 100644
--- a/libgloss/i386/cygmon-salib.c
+++ b/libgloss/i386/cygmon-salib.c
@@ -161,22 +161,3 @@  __do_global_dtors ()
     }
 }
 #endif
-
-void
-profil_write (int type, char *buffer, int len)
-{
-  static int des = -1;
-
-  if (des < 0)
-    {
-      des = open ("gmon.out", O_WRONLY | O_CREAT | O_TRUNC, 0644);
-    }
-  if (len == 0)
-    {
-      close (des);
-    }
-  else
-    {
-      write (des, buffer, len);
-    }
-}