On 2026-05-08 00:40, Bruno Haible wrote:
The casts are there for platforms where mmap()
returns a 'caddr_t', i.e. 'char *', not 'void *'.

Even on those old platforms, it's not necessary to supply a cast in a declaration like 'void *p = mmap (...);', and to modern eyes it looks odd to see a cast there (why cast something to the same type?) and that makes the code slightly more confusing. That's why I'd rather remove the useless cast and remove the pragma that suppresses the warning about the cast.

As far as I know, among Gnulib-supported platforms only Solaris 10 still has this issue. I suppose we could wrap mmap on Solaris 10 so that mmap returns void *, but given that the workaround is so simple it's probably not worth the trouble for such a niche platform nowadays. For now I documented the issue+workaround for mmap and similar functions, by installing the attached.
From cce9fdba3ca659346603eda8c426e92191d5b9e0 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Sat, 9 May 2026 09:17:51 -0700
Subject: [PATCH] Document Solaris 10 mmap etc. issues with caddr_t

---
 doc/glibc-functions/madvise.texi  | 6 ++++++
 doc/glibc-functions/mincore.texi  | 6 ++++++
 doc/posix-functions/mlock.texi    | 6 ++++++
 doc/posix-functions/mmap.texi     | 6 ++++++
 doc/posix-functions/mprotect.texi | 6 ++++++
 doc/posix-functions/msync.texi    | 6 ++++++
 doc/posix-functions/munlock.texi  | 6 ++++++
 doc/posix-functions/munmap.texi   | 6 ++++++
 doc/posix-functions/shmdt.texi    | 6 ++++++
 9 files changed, 54 insertions(+)

diff --git a/doc/glibc-functions/madvise.texi b/doc/glibc-functions/madvise.texi
index d4ae05b400..aed6bb16fe 100644
--- a/doc/glibc-functions/madvise.texi
+++ b/doc/glibc-functions/madvise.texi
@@ -26,4 +26,10 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Minix 3.1.8, AIX 5.1, Cygwin 1.7.7, mingw, MSVC 14.
+@item
+On Solaris 10 this function accepts @code{char *} not @code{void *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void *} or @code{char *}.
 @end itemize
diff --git a/doc/glibc-functions/mincore.texi b/doc/glibc-functions/mincore.texi
index 553dd73e61..c2fdc7d74b 100644
--- a/doc/glibc-functions/mincore.texi
+++ b/doc/glibc-functions/mincore.texi
@@ -15,4 +15,10 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 OpenBSD 7.5, Minix 3.1.8, AIX 5.1, HP-UX 11, Cygwin 2.9, mingw, MSVC 14.
+@item
+On Solaris 10 this function accepts @code{char *} not @code{void *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void *} or @code{char *}.
 @end itemize
diff --git a/doc/posix-functions/mlock.texi b/doc/posix-functions/mlock.texi
index 8ea0f16ec0..9eff29f45e 100644
--- a/doc/posix-functions/mlock.texi
+++ b/doc/posix-functions/mlock.texi
@@ -15,4 +15,10 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Minix 3.1.8, mingw, MSVC 14.
+@item
+On Solaris 10 this function accepts @code{char *} not @code{void const *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void const *} or @code{char const *}.
 @end itemize
diff --git a/doc/posix-functions/mmap.texi b/doc/posix-functions/mmap.texi
index 2a28ecf5c0..c3c5fb9d76 100644
--- a/doc/posix-functions/mmap.texi
+++ b/doc/posix-functions/mmap.texi
@@ -24,6 +24,12 @@ To get anonymous memory, on some platforms, you can use the flags
 @code{MAP_ANONYMOUS | MAP_PRIVATE} and @code{-1} instead of a file descriptor;
 on others you have to use a read-only file descriptor of @file{/dev/zero}.
 @item
+On Solaris 10 this function accepts and returns @code{char *} not @code{void *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void *} or @code{char *} for both arguments and results.
+@item
 On HP-UX, passing a non-NULL first argument, as a hint for the address (even
 without @code{MAP_FIXED}), often causes @code{mmap} to fail.  Better pass NULL
 in this case.
diff --git a/doc/posix-functions/mprotect.texi b/doc/posix-functions/mprotect.texi
index 43ce6c04ca..7bb6aa70e6 100644
--- a/doc/posix-functions/mprotect.texi
+++ b/doc/posix-functions/mprotect.texi
@@ -21,4 +21,10 @@ mingw.
 @item
 On AIX, it is not possible to use @code{mprotect} on memory regions allocated
 with @code{malloc}.
+@item
+On Solaris 10 this function accepts @code{char *} not @code{void *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void *} or @code{char *}.
 @end itemize
diff --git a/doc/posix-functions/msync.texi b/doc/posix-functions/msync.texi
index 607d0b83f8..697f58afad 100644
--- a/doc/posix-functions/msync.texi
+++ b/doc/posix-functions/msync.texi
@@ -17,4 +17,10 @@ This function is missing on some platforms:
 Minix 3.1.8, mingw, MSVC 14.
 @item
 On NetBSD, @code{msync} takes only two arguments.
+@item
+On Solaris 10 this function accepts @code{char *} not @code{void *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void *} or @code{char *}.
 @end itemize
diff --git a/doc/posix-functions/munlock.texi b/doc/posix-functions/munlock.texi
index 26cc89b160..56219376ab 100644
--- a/doc/posix-functions/munlock.texi
+++ b/doc/posix-functions/munlock.texi
@@ -15,4 +15,10 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Minix 3.1.8, mingw, MSVC 14.
+@item
+On Solaris 10 this function accepts @code{char *} not @code{void const *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void const *} or @code{char const *}.
 @end itemize
diff --git a/doc/posix-functions/munmap.texi b/doc/posix-functions/munmap.texi
index 67dd9aa5c0..98622e114a 100644
--- a/doc/posix-functions/munmap.texi
+++ b/doc/posix-functions/munmap.texi
@@ -15,4 +15,10 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 mingw, MSVC 14.
+@item
+On Solaris 10 this function accepts @code{char *} not @code{void *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void *} or @code{char *}.
 @end itemize
diff --git a/doc/posix-functions/shmdt.texi b/doc/posix-functions/shmdt.texi
index 9ea1c17112..bd35781542 100644
--- a/doc/posix-functions/shmdt.texi
+++ b/doc/posix-functions/shmdt.texi
@@ -15,4 +15,10 @@ Portability problems not fixed by Gnulib:
 @item
 This function is missing on some platforms:
 mingw, MSVC 14, Android 7.1.
+@item
+On Solaris 10 this function accepts @code{char *} not @code{void const *},
+unless you define feature test macros like @code{_POSIX_C_SOURCE}
+or @code{_XOPEN_SOURCE} that may undesirably hide other symbols.
+To work around this problem, callers can limit themselves to either
+@code{void *} or @code{char *}.
 @end itemize
-- 
2.51.0

Reply via email to