1
0
mirror of https://github.com/libretro/RetroArch synced 2025-02-19 21:40:49 +00:00

Style nits

This commit is contained in:
twinaphex 2017-11-25 02:18:24 +01:00
parent ac651b7581
commit 395e84ede2

@ -11,7 +11,21 @@
#include <sys/syscall.h>
#include <linux/aio_abi.h>
/* there's also a Unix AIO thingy, but it's not in glibc and we don't want more dependencies */
struct nbio_t
{
int fd;
bool busy;
aio_context_t ctx;
struct iocb cb;
void* ptr;
size_t len;
};
/* there's also a Unix AIO thingy, but it's not in glibc
* and we don't want more dependencies */
static int io_setup(unsigned nr, aio_context_t * ctxp)
{
@ -39,28 +53,15 @@ static int io_getevents(aio_context_t ctx, long min_nr, long nr,
return syscall(__NR_io_getevents, ctx, min_nr, nr, events, timeout);
}
struct nbio_t
{
int fd;
bool busy;
aio_context_t ctx;
struct iocb cb;
void* ptr;
size_t len;
};
struct nbio_t* nbio_open(const char * filename, unsigned mode)
{
static const int o_flags[] = { O_RDONLY, O_RDWR|O_CREAT|O_TRUNC, O_RDWR, O_RDONLY, O_RDWR|O_CREAT|O_TRUNC };
aio_context_t ctx = 0;
struct nbio_t* handle;
int fd;
fd = open(filename, o_flags[mode]|O_CLOEXEC, 0644);
if (fd < 0) return NULL;
struct nbio_t* handle = NULL;
int fd = open(filename, o_flags[mode]|O_CLOEXEC, 0644);
if (fd < 0)
return NULL;
if (io_setup(128, &ctx) < 0)
{
@ -74,6 +75,7 @@ struct nbio_t* nbio_open(const char * filename, unsigned mode)
handle->len = lseek(fd, 0, SEEK_END);
handle->ptr = malloc(handle->len);
handle->busy = false;
return handle;
}
@ -114,10 +116,8 @@ bool nbio_iterate(struct nbio_t* handle)
{
struct io_event ev;
if (io_getevents(handle->ctx, 0, 1, &ev, NULL) == 1)
{
handle->busy = false;
}
}
return !handle->busy;
}
@ -125,7 +125,8 @@ void nbio_resize(struct nbio_t* handle, size_t len)
{
if (len < handle->len)
{
/* this works perfectly fine if this check is removed, but it won't work on other nbio implementations */
/* this works perfectly fine if this check is removed, but it
* won't work on other nbio implementations */
/* therefore, it's blocked so nobody accidentally relies on it */
puts("ERROR - attempted file shrink operation, not implemented");
abort();
@ -133,7 +134,8 @@ void nbio_resize(struct nbio_t* handle, size_t len)
if (ftruncate(handle->fd, len) != 0)
{
puts("ERROR - couldn't resize file (ftruncate)");
abort(); /* this one returns void and I can't find any other way for it to report failure */
abort(); /* this one returns void and I can't find any other way
for it to report failure */
}
handle->ptr = realloc(handle->ptr, len);
handle->len = len;
@ -141,13 +143,20 @@ 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->busy) return handle->ptr;
else return NULL;
if (!handle)
return NULL;
if (len)
*len = handle->len;
if (!handle->busy)
return handle->ptr;
return NULL;
}
void nbio_cancel(struct nbio_t* handle)
{
if (!handle)
return;
if (handle->busy)
{
struct io_event ev;
@ -158,6 +167,9 @@ void nbio_cancel(struct nbio_t* handle)
void nbio_free(struct nbio_t* handle)
{
if (!handle)
return;
io_destroy(handle->ctx);
close(handle->fd);
free(handle->ptr);