[PATCH] libc: sh: Add missing declarations

Chris Packham <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Add declarations and return types to resolve the following build issues.

  newlib/libc/sys/sh/creat.c: In function 'creat':
  newlib/libc/sys/sh/creat.c:6:10: error: implicit declaration of function '_creat'; did you mean 'creat'? [-Wimplicit-function-declaration]

  newlib/libc/sys/sh/syscalls.c: In function '_read':
  newlib/libc/sys/sh/syscalls.c:16:10: error: implicit declaration of function '__trap34' [-Wimplicit-function-declaration]

  newlib/libc/sys/sh/syscalls.c: In function '_sbrk':
  newlib/libc/sys/sh/syscalls.c:62:7: error: implicit declaration of function 'abort' [-Wimplicit-function-declaration]

  newlib/libc/sys/sh/syscalls.c: At top level:
  newlib/libc/sys/sh/syscalls.c:96:1: error: return type defaults to 'int' [-Wimplicit-int]
       96 | isatty (fd)
          | ^~~~~~

  newlib/libc/sys/sh/syscalls.c: In function '_kill':
  newlib/libc/sys/sh/syscalls.c:114:1: error: type of 'n' defaults to 'int' [-Wimplicit-int]

  newlib/libc/sys/sh/syscalls.c: In function '__setup_argv_for_main':
  newlib/libc/sys/sh/syscalls.c:216:10: error: implicit declaration of function 'main' [-Wimplicit-function-declaration]
      216 |   return main (argc, argv);
          |          ^~~~

  newlib/libc/sys/sh/ftruncate.c: In function 'ftruncate':
  newlib/libc/sys/sh/ftruncate.c:8:10: error: implicit declaration of function '__trap34' [-Wimplicit-function-declaration]

Signed-off-by: Chris Packham <[email protected]>
---
 newlib/libc/sys/sh/creat.c     |  2 ++
 newlib/libc/sys/sh/ftruncate.c |  2 ++
 newlib/libc/sys/sh/syscalls.c  | 16 +++++++++++++---
 newlib/libc/sys/sh/truncate.c  |  2 ++
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/newlib/libc/sys/sh/creat.c b/newlib/libc/sys/sh/creat.c
index 62ec5ead8..b9f614e9e 100644
--- a/newlib/libc/sys/sh/creat.c
+++ b/newlib/libc/sys/sh/creat.c
@@ -1,3 +1,5 @@
+extern int _creat (const char *path, int mode);
+
 int
 creat(path, mode)
      const char *path;
diff --git a/newlib/libc/sys/sh/ftruncate.c b/newlib/libc/sys/sh/ftruncate.c
index 660377bf3..9f4d514a3 100644
--- a/newlib/libc/sys/sh/ftruncate.c
+++ b/newlib/libc/sys/sh/ftruncate.c
@@ -2,6 +2,8 @@
 #include <sys/types.h>
 #include "sys/syscall.h"
 
+extern int  __trap34(int func_no, ...);
+
 int
 ftruncate (int file, off_t length)
 {
diff --git a/newlib/libc/sys/sh/syscalls.c b/newlib/libc/sys/sh/syscalls.c
index 614b67e9e..879dfea92 100644
--- a/newlib/libc/sys/sh/syscalls.c
+++ b/newlib/libc/sys/sh/syscalls.c
@@ -5,6 +5,10 @@
 #include "sys/syscall.h"
 int errno;
 
+extern void abort (void);
+extern int  __trap34(int func_no, ...);
+extern int main (int, char **);
+
 /* This is used by _sbrk.  */
 register char *stack_ptr asm ("r15");
 
@@ -93,12 +97,14 @@ _unlink ()
   return -1;
 }
 
+int
 isatty (fd)
      int fd;
 {
   return 1;
 }
 
+int
 _isatty (fd)
      int fd;
 {
@@ -106,21 +112,25 @@ _isatty (fd)
 }
 
 
-_exit (n)
+int
+_exit (int n)
 {
   return __trap34 (SYS_exit, n, 0, 0);
 }
 
-_kill (n, m)
+int
+_kill (int n, int m)
 {
   return __trap34 (SYS_exit, 0xdead, 0, 0);
 }
 
-_getpid (n)
+int
+_getpid (int n)
 {
   return 1;
 }
 
+int
 _raise ()
 {
 }
diff --git a/newlib/libc/sys/sh/truncate.c b/newlib/libc/sys/sh/truncate.c
index 5ca48d3c6..2641c2cfb 100644
--- a/newlib/libc/sys/sh/truncate.c
+++ b/newlib/libc/sys/sh/truncate.c
@@ -2,6 +2,8 @@
 #include <sys/types.h>
 #include "sys/syscall.h"
 
+extern int  __trap34(int func_no, ...);
+
 int
 truncate (const char *path, off_t length)
 {
-- 
2.43.2
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.