Re: [PATCH] nvptx: Add _ssize_t as _READ_WRITE_RETURN_TYPE in newlib/libc/include/sys/config.h

Arijit Kumar Das <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CALDPgrttr_cE+S3K6v2rUmJGxe5Cn4s_cg4w-O+s10sGgt0uNg@mail.gmail.com>
Hi Thomas!

Here's the final commit. I hope it's okay :-)

Best regards,
Arijit


From 3089acec0f3b5606bffcbca3b6864023ccd2afa3 Mon Sep 17 00:00:00 2001
From: Arijit Kumar Das <[email protected]>
Date: Thu, 17 Jul 2025 01:01:03 +0530
Subject: [PATCH] [nvptx]: Use _READ_WRITE_RETURN_TYPE for return type and
 _READ_WRITE_BUFSIZE_TYPE for count in read() and write()

- Changed the return type of read() from int to
_READ_WRITE_RETURN_TYPE as per conventions.
- Changed the 'count' parameter of read() and write() to
_READ_WRITE_BUFSIZE_TYPE.
- Defined both of the above macros in libc/include/sys/config.h under __nvptx__.
- _READ_WRITE_RETURN_TYPE defined as _ssize_t (ssize_t).
- _READ_WRITE_BUFSIZE_TYPE defined as __size_t (size_t).

Signed-off-by: Arijit Kumar Das <[email protected]>
---
 newlib/libc/include/sys/config.h  | 5 +++++
 newlib/libc/machine/nvptx/misc.c  | 4 ++--
 newlib/libc/machine/nvptx/write.c | 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 4c9acc55c..c3cd51e86 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -12,6 +12,11 @@
 #define __DYNAMIC_REENT__
 #endif

+#ifdef __nvptx__
+#define _READ_WRITE_RETURN_TYPE _ssize_t
+#define _READ_WRITE_BUFSIZE_TYPE __size_t
+#endif
+
 /* exceptions first */
 #if defined(__H8500__) || defined(__W65__)
 #define __SMALL_BITFIELDS
diff --git a/newlib/libc/machine/nvptx/misc.c b/newlib/libc/machine/nvptx/misc.c
index 56e66b9f3..329804f88 100644
--- a/newlib/libc/machine/nvptx/misc.c
+++ b/newlib/libc/machine/nvptx/misc.c
@@ -62,8 +62,8 @@ open (const char *pathname, int flags, ...) {
   return -1;
 }

-int
-read(int fd, void *buf, size_t count) {
+_READ_WRITE_RETURN_TYPE
+read(int fd, void *buf, _READ_WRITE_BUFSIZE_TYPE count) {
   return 0;
 }

diff --git a/newlib/libc/machine/nvptx/write.c
b/newlib/libc/machine/nvptx/write.c
index 0544dd05e..49fb65944 100644
--- a/newlib/libc/machine/nvptx/write.c
+++ b/newlib/libc/machine/nvptx/write.c
@@ -18,7 +18,8 @@
 #include <unistd.h>
 #include <errno.h>

-_READ_WRITE_RETURN_TYPE write (int fd, const void *buf, size_t count)
+_READ_WRITE_RETURN_TYPE
+write (int fd, const void *buf, _READ_WRITE_BUFSIZE_TYPE count)
 {
   size_t i;
   char *b = (char *)buf;
-- 
2.39.5
0001-nvptx-Use-_READ_WRITE_RETURN_TYPE-for-return-type-an.patch (text/x-patch, 2.2 KB)
From 3089acec0f3b5606bffcbca3b6864023ccd2afa3 Mon Sep 17 00:00:00 2001
From: Arijit Kumar Das <[email protected]>
Date: Thu, 17 Jul 2025 01:01:03 +0530
Subject: [PATCH] [nvptx]: Use _READ_WRITE_RETURN_TYPE for return type and
 _READ_WRITE_BUFSIZE_TYPE for count in read() and write()

- Changed the return type of read() from int to _READ_WRITE_RETURN_TYPE as per conventions.
- Changed the 'count' parameter of read() and write() to _READ_WRITE_BUFSIZE_TYPE.
- Defined both of the above macros in libc/include/sys/config.h under __nvptx__.
- _READ_WRITE_RETURN_TYPE defined as _ssize_t (ssize_t).
- _READ_WRITE_BUFSIZE_TYPE defined as __size_t (size_t).

Signed-off-by: Arijit Kumar Das <[email protected]>
---
 newlib/libc/include/sys/config.h  | 5 +++++
 newlib/libc/machine/nvptx/misc.c  | 4 ++--
 newlib/libc/machine/nvptx/write.c | 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 4c9acc55c..c3cd51e86 100644
--- a/newlib/libc/include/sys/config.h
+++ b/newlib/libc/include/sys/config.h
@@ -12,6 +12,11 @@
 #define __DYNAMIC_REENT__
 #endif
 
+#ifdef __nvptx__
+#define _READ_WRITE_RETURN_TYPE _ssize_t
+#define _READ_WRITE_BUFSIZE_TYPE __size_t
+#endif
+
 /* exceptions first */
 #if defined(__H8500__) || defined(__W65__)
 #define __SMALL_BITFIELDS
diff --git a/newlib/libc/machine/nvptx/misc.c b/newlib/libc/machine/nvptx/misc.c
index 56e66b9f3..329804f88 100644
--- a/newlib/libc/machine/nvptx/misc.c
+++ b/newlib/libc/machine/nvptx/misc.c
@@ -62,8 +62,8 @@ open (const char *pathname, int flags, ...) {
   return -1;
 }
 
-int
-read(int fd, void *buf, size_t count) {
+_READ_WRITE_RETURN_TYPE
+read(int fd, void *buf, _READ_WRITE_BUFSIZE_TYPE count) {
   return 0;
 }
 
diff --git a/newlib/libc/machine/nvptx/write.c b/newlib/libc/machine/nvptx/write.c
index 0544dd05e..49fb65944 100644
--- a/newlib/libc/machine/nvptx/write.c
+++ b/newlib/libc/machine/nvptx/write.c
@@ -18,7 +18,8 @@
 #include <unistd.h>
 #include <errno.h>
 
-_READ_WRITE_RETURN_TYPE write (int fd, const void *buf, size_t count)
+_READ_WRITE_RETURN_TYPE
+write (int fd, const void *buf, _READ_WRITE_BUFSIZE_TYPE count)
 {
   size_t i;
   char *b = (char *)buf;
-- 
2.39.5
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.