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

Vincent Mailhol <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <20251029-fix-libgloss-i386-compile-issues-v1-4-26edcb02f69c@kernel.org>
_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 <[email protected]>
---
 libgloss/i386/cygmon-gmon.c  | 20 ++++++++++++++++++++
 libgloss/i386/cygmon-salib.c | 19 -------------------
 2 files changed, 20 insertions(+), 19 deletions(-)

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);
-    }
-}

-- 
2.51.0
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.