summaryrefslogtreecommitdiff
path: root/hurd/fopenport.c
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-02-12 14:10:34 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-02-12 15:55:04 +0100
commit62d6c3303089d9c708527ab7bf98348a6429e8c3 (patch)
tree73a5a9637c522d97df9281137cb26c44809e9167 /hurd/fopenport.c
parentf4315054b46d5e58b44a709a51943fb73f846afb (diff)
downloadglibc-62d6c3303089d9c708527ab7bf98348a6429e8c3.tar.gz
mach, hurd: Cast through uintptr_t
When casting between a pointer and an integer of a different size, GCC emits a warning (which is escalated to a build failure by -Werror). Indeed, if what you start with is a pointer, which you then cast to a shorter integer and then back again, you're going to cut off some bits of the pointer. But if you start with an integer (such as mach_port_t), then cast it to a longer pointer (void *), and then back to a shorter integer, you are fine. To keep GCC happy, cast through an intermediary uintptr_t, which is always the same size as a pointer. Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230212111044.610942-4-bugaevc@gmail.com>
Diffstat (limited to 'hurd/fopenport.c')
-rw-r--r--hurd/fopenport.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/hurd/fopenport.c b/hurd/fopenport.c
index 60afb44552..be6aa30c7e 100644
--- a/hurd/fopenport.c
+++ b/hurd/fopenport.c
@@ -28,9 +28,10 @@ readio (void *cookie, char *buf, size_t n)
mach_msg_type_number_t nread;
error_t err;
char *bufp = buf;
+ io_t io = (io_t) (uintptr_t) cookie;
nread = n;
- if (err = __io_read ((io_t) cookie, &bufp, &nread, -1, n))
+ if (err = __io_read (io, &bufp, &nread, -1, n))
return __hurd_fail (err);
if (bufp != buf)
@@ -50,8 +51,9 @@ writeio (void *cookie, const char *buf, size_t n)
{
vm_size_t wrote;
error_t err;
+ io_t io = (io_t) (uintptr_t) cookie;
- if (err = __io_write ((io_t) cookie, buf, n, -1, &wrote))
+ if (err = __io_write (io, buf, n, -1, &wrote))
return __hurd_fail (err);
return wrote;
@@ -65,7 +67,8 @@ seekio (void *cookie,
off64_t *pos,
int whence)
{
- error_t err = __io_seek ((file_t) cookie, *pos, whence, pos);
+ io_t io = (io_t) (uintptr_t) cookie;
+ error_t err = __io_seek (io, *pos, whence, pos);
return err ? __hurd_fail (err) : 0;
}
@@ -74,8 +77,9 @@ seekio (void *cookie,
static int
closeio (void *cookie)
{
+ io_t io = (io_t) (uintptr_t) cookie;
error_t error = __mach_port_deallocate (__mach_task_self (),
- (mach_port_t) cookie);
+ io);
if (error)
return __hurd_fail (error);
return 0;
@@ -127,6 +131,7 @@ __fopenport (mach_port_t port, const char *mode)
return NULL;
}
- return fopencookie ((void *) port, mode, funcsio);
+ return fopencookie ((void *) (uintptr_t) port,
+ mode, funcsio);
}
weak_alias (__fopenport, fopenport)