From 4a2e31190b50664e67f24db3faf72c4c51d7c774 Mon Sep 17 00:00:00 2001 From: nico Date: Mon, 9 Jul 2007 13:16:32 +0000 Subject: [PATCH] Fix the warnings by using more appropriate types. git-svn-id: svn://jdgordon.mine.nu/mob@46 9862a28c-4e93-4879-ac26-10afcf840a8f --- testplugin.c | 62 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/testplugin.c b/testplugin.c index 1768e42..eabe74e 100644 --- a/testplugin.c +++ b/testplugin.c @@ -90,12 +90,13 @@ static void graph_view(int width); /* add a new handle to the linked list and return it. It will have become the new current handle. The handle will reserve "data_size" bytes or if that's not possible, decrease "data_size" to allow adding the handle. */ -static struct memory_handle *add_handle(int *data_size) +static struct memory_handle *add_handle(size_t *data_size) { /* this will give each handle a unique id */ static int cur_handle_id = 1; - int len = (data_size ? *data_size : 0) + sizeof(struct memory_handle); + size_t len = (data_size ? *data_size : 0) + + sizeof(struct memory_handle); /* check that we actually can add the handle and its data */ int overlap = RINGBUF_ADD_CROSS(buf_widx, len + 3, buf_ridx); @@ -249,7 +250,7 @@ static struct memory_handle *move_handle(size_t newpos, struct memory_handle *h) } /* Buffer data for the given handle. Return the amount of data buffered or -1 if the handle wasn't found */ -static int buffer_handle(int handle_id) +static ssize_t buffer_handle(int handle_id) { DEBUGF("buffer_handle(%d)\n", handle_id); struct memory_handle *h = find_handle(handle_id); @@ -275,7 +276,7 @@ static int buffer_handle(int handle_id) rb->lseek(h->fd, h->offset, SEEK_SET); } - int ret = 0; + ssize_t ret = 0; while (h->filerem > 0) { //DEBUGF("h: %d\n", (void *)h - (void *)buffer); @@ -313,12 +314,10 @@ static int buffer_handle(int handle_id) rb->close(h->fd); } - DEBUGF("buffered %d bytes (%d of %d available, remaining: %d)\n", + DEBUGF("buffered %ld bytes (%ld of %ld available, remaining: %ld)\n", ret, h->available, h->filesize, h->filerem); -#ifndef ROCKBOX_HAS_LOGF graph_view(100); -#endif return ret; } @@ -341,9 +340,7 @@ static void free_buffer(int handle_id) h->ridx = h->data; h->available -= delta; -#ifndef ROCKBOX_HAS_LOGF graph_view(100); -#endif } static void fill_buffer(void) @@ -359,9 +356,9 @@ static void fill_buffer(void) } } -static int data_rem(void) +static size_t data_rem(void) { - int ret = 0; + size_t ret = 0; struct memory_handle *m = first_handle; while (m) { @@ -372,9 +369,9 @@ static int data_rem(void) return ret; } -static int wasted_space(void) +static size_t wasted_space(void) { - int ret = 0; + size_t ret = 0; struct memory_handle *m = first_handle; while (m) { @@ -393,7 +390,7 @@ static int wasted_space(void) */ int bufopen(char *file, size_t offset) { - DEBUGF("bufopen: %s (offset: %d)\n", file, offset); + DEBUGF("bufopen: %s (offset: %ld)\n", file, offset); int fd = rb->open(file, O_RDONLY); if (fd < 0) @@ -402,7 +399,7 @@ int bufopen(char *file, size_t offset) if (offset) rb->lseek(fd, offset, SEEK_SET); - int size = rb->filesize(fd) - offset; + size_t size = rb->filesize(fd) - offset; struct memory_handle *h = add_handle(&size); if (!h) { @@ -454,7 +451,7 @@ int bufseek(int handle_id, size_t offset) /* Advance the reading index in a handle (relatively to its current position). Return 0 for success and < 0 for failure */ -int bufadvance(int handle_id, ssize_t offset) +int bufadvance(int handle_id, off_t offset) { struct memory_handle *h = find_handle(handle_id); if (!h) @@ -463,7 +460,7 @@ int bufadvance(int handle_id, ssize_t offset) if (offset >= 0) { /* check for access beyond what's available */ - if (offset > h->available - RINGBUF_SUB(h->ridx, h->data)) + if ((size_t)offset > (h->available - RINGBUF_SUB(h->ridx, h->data))) return -2; h->ridx = RINGBUF_ADD(h->ridx, offset); @@ -471,18 +468,18 @@ int bufadvance(int handle_id, ssize_t offset) else { /* check for access before what's available */ - if (-offset > RINGBUF_SUB(h->ridx, h->data)) + if ((size_t)(-offset) > RINGBUF_SUB(h->ridx, h->data)) return -2; - h->ridx = RINGBUF_SUB(h->ridx, -offset); + h->ridx = RINGBUF_SUB(h->ridx, (size_t)(-offset)); } return 0; } /* Copy data from the given handle to the dest buffer. - Return the number of bytes copied or -1 for failure. */ -int bufread(int handle_id, size_t size, char *dest) + Return the number of bytes copied or < 0 for failure. */ +ssize_t bufread(int handle_id, size_t size, char *dest) { struct memory_handle *h = find_handle(handle_id); size_t buffered_data; @@ -511,8 +508,8 @@ int bufread(int handle_id, size_t size, char *dest) } /* Update the "data" pointer to make the handle's data available to the caller. - Return the length of the available linear data or -1 for failure. */ -long bufgetdata(int handle_id, size_t size, unsigned char **data) + Return the length of the available linear data or < 0 for failure. */ +ssize_t bufgetdata(int handle_id, size_t size, unsigned char **data) { struct memory_handle *h = find_handle(handle_id); if (!h) @@ -524,13 +521,13 @@ long bufgetdata(int handle_id, size_t size, unsigned char **data) if (h->available == 0 && h->filerem == 0) return 0; - long ret; + ssize_t ret; if (h->ridx + size > buffer_len && h->available - RINGBUF_SUB(h->ridx, h->data) >= size) { /* use the guard buffer to provide what was requested. */ - int copy_n = h->ridx + size - buffer_len; + size_t copy_n = h->ridx + size - buffer_len; rb->memcpy(guard_buffer, (unsigned char *)buffer, copy_n); ret = size; } @@ -635,10 +632,10 @@ static void list_handles(void) } #endif -#ifndef ROCKBOX_HAS_LOGF /* display a nice graphical view of the ringbuffer. */ static void graph_view(int width) { +#ifndef ROCKBOX_HAS_LOGF int i, r_pos, w_pos; r_pos = buf_ridx * width / buffer_len; w_pos = buf_widx * width / buffer_len; @@ -683,8 +680,10 @@ static void graph_view(int width) } DEBUGF("|"); DEBUGF("\n"); -} +#else + (void)width; #endif +} bool buffer_init(void) { @@ -763,7 +762,7 @@ void playback_thread(void) int fd = -1; /* used to write the files out as they are read */ unsigned char *data; char outfile[MAX_PATH]; - long read, total; + long read, total = 0; while (1) { @@ -917,7 +916,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) while (!done_playing) { if (wasted_space() > buffer_len/4) { - DEBUGF("there is %d bytes of wasted space\n", wasted_space()); + DEBUGF("there is %ld bytes of wasted space\n", wasted_space()); struct memory_handle *m = first_handle; while (m) { free_buffer(m->id); @@ -926,7 +925,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) } if (data_rem() > 0 && BUF_USED < buffer_len/4 && disk_is_spinning()) { - DEBUGF("%d bytes left to buffer and the buffer is running low\n", data_rem()); + DEBUGF("%ld bytes left to buffer and the buffer is running low\n", data_rem()); fill_buffer(); } else { rb->sleep(HZ/2); @@ -990,9 +989,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) } DEBUGF("buffer usage: %d handles_used: %d\n", BUF_USED,num_handles); -#ifndef ROCKBOX_HAS_LOGF + graph_view(100); -#endif #endif -- 2.11.4.GIT