From 81e543a4c9e07c212dd3c80649fa2efb71dd4207 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 25 Nov 2017 05:21:35 +0100 Subject: [PATCH] Cleanups --- libretro-common/file/nbio/nbio_linux.c | 15 ++++++++++----- libretro-common/file/nbio/nbio_unixmmap.c | 7 ++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libretro-common/file/nbio/nbio_linux.c b/libretro-common/file/nbio/nbio_linux.c index 66455fedf2..45fefab2e7 100644 --- a/libretro-common/file/nbio/nbio_linux.c +++ b/libretro-common/file/nbio/nbio_linux.c @@ -81,15 +81,16 @@ struct nbio_t* nbio_open(const char * filename, unsigned mode) static void nbio_begin_op(struct nbio_t* handle, uint16_t op) { - struct iocb * cbp = &handle->cb; + struct iocb * cbp = &handle->cb; memset(&handle->cb, 0, sizeof(handle->cb)); - handle->cb.aio_fildes = handle->fd; + + handle->cb.aio_fildes = handle->fd; handle->cb.aio_lio_opcode = op; - handle->cb.aio_buf = (uint64_t)(uintptr_t)handle->ptr; - handle->cb.aio_offset = 0; - handle->cb.aio_nbytes = handle->len; + handle->cb.aio_buf = (uint64_t)(uintptr_t)handle->ptr; + handle->cb.aio_offset = 0; + handle->cb.aio_nbytes = handle->len; if (io_submit(handle->ctx, 1, &cbp) != 1) { @@ -123,6 +124,9 @@ bool nbio_iterate(struct nbio_t* handle) void nbio_resize(struct nbio_t* handle, size_t len) { + if (!handle) + return; + if (len < handle->len) { /* this works perfectly fine if this check is removed, but it @@ -131,6 +135,7 @@ void nbio_resize(struct nbio_t* handle, size_t len) puts("ERROR - attempted file shrink operation, not implemented"); abort(); } + if (ftruncate(handle->fd, len) != 0) { puts("ERROR - couldn't resize file (ftruncate)"); diff --git a/libretro-common/file/nbio/nbio_unixmmap.c b/libretro-common/file/nbio/nbio_unixmmap.c index a6a4e41a31..a484e01eeb 100644 --- a/libretro-common/file/nbio/nbio_unixmmap.c +++ b/libretro-common/file/nbio/nbio_unixmmap.c @@ -96,7 +96,10 @@ void nbio_resize(struct nbio_t* handle, size_t len) void* nbio_get_ptr(struct nbio_t* handle, size_t* len) { - if (len) *len = handle->len; + if (!handle) + return NULL; + if (len) + *len = handle->len; return handle->ptr; } @@ -107,6 +110,8 @@ void nbio_cancel(struct nbio_t* handle) void nbio_free(struct nbio_t* handle) { + if (!handle) + return; close(handle->fd); munmap(handle->ptr, handle->len); free(handle);