summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-10-28 15:54:10 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-10-28 15:54:10 +0000
commit7807279eaf698474e2eabde440b73a1f587ea7ef (patch)
tree07d972da2a7251d134a0a5d74ce5d8be5ca42838 /apps/buffering.c
parent9f6719ec56f2a6b5ae164f6be7dcd7fc3f072d75 (diff)
Add #defines for error values. Makes the code easier to read.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15348 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 347ad611f3..0fd0c4c520 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -253,7 +253,7 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap,
/* This is how far we shifted buf_widx to align things */
shift = RINGBUF_SUB(new_widx, buf_widx);
-
+
/* How much space are we short in the actual ring buffer? */
overlap = RINGBUF_ADD_CROSS(buf_widx, shift + len, buf_ridx);
if (overlap >= 0 && (alloc_all || (unsigned)overlap > data_size)) {
@@ -426,7 +426,7 @@ static struct memory_handle *move_handle(const struct memory_handle *h,
overlap -= correction;
*delta -= correction;
}
-
+
dest = (struct memory_handle *)(&buffer[newpos]);
if (h == first_handle) {
@@ -784,11 +784,11 @@ management functions for all the actual handle management work.
int bufopen(const char *file, size_t offset, enum data_type type)
{
if (!can_add_handle())
- return -2;
+ return BUFFER_FULL;
int fd = open(file, O_RDONLY);
if (fd < 0)
- return -1;
+ return FILE_ERROR;
size_t size = filesize(fd);
@@ -797,7 +797,7 @@ int bufopen(const char *file, size_t offset, enum data_type type)
{
DEBUGF("bufopen: failed to add handle\n");
close(fd);
- return -2;
+ return BUFFER_FULL;
}
strncpy(h->path, file, MAX_PATH);
@@ -835,12 +835,12 @@ int bufopen(const char *file, size_t offset, enum data_type type)
int bufalloc(const void *src, size_t size, enum data_type type)
{
if (!can_add_handle())
- return -2;
+ return BUFFER_FULL;
struct memory_handle *h = add_handle(size, false, true);
if (!h)
- return -2;
+ return BUFFER_FULL;
if (src) {
if (type == TYPE_ID3 && size == sizeof(struct mp3entry)) {
@@ -888,11 +888,11 @@ int bufseek(int handle_id, size_t newpos)
{
struct memory_handle *h = find_handle(handle_id);
if (!h)
- return -1;
+ return HANDLE_NOT_FOUND;
if (newpos > h->filesize) {
/* access beyond the end of the file */
- return -3;
+ return INVALID_VALUE;
}
else if (newpos < h->offset || h->offset + h->available < newpos) {
/* access before or after buffered data. A rebuffer is needed. */
@@ -910,7 +910,7 @@ int bufadvance(int handle_id, off_t offset)
{
const struct memory_handle *h = find_handle(handle_id);
if (!h)
- return -1;
+ return HANDLE_NOT_FOUND;
size_t newpos = h->offset + RINGBUF_SUB(h->ridx, h->data) + offset;
return bufseek(handle_id, newpos);
@@ -922,18 +922,18 @@ ssize_t bufread(int handle_id, size_t size, void *dest)
{
const struct memory_handle *h = find_handle(handle_id);
if (!h)
- return -1;
+ return HANDLE_NOT_FOUND;
size_t ret;
size_t copy_n = RINGBUF_SUB(h->widx, h->ridx);
if (size == 0 && h->filerem > 0 && copy_n == 0)
/* Data isn't ready */
- return -2;
+ return DATA_NOT_READY;
if (copy_n < size && h->filerem > 0)
/* Data isn't ready */
- return -2;
+ return DATA_NOT_READY;
if (copy_n == 0 && h->filerem == 0)
/* File is finished reading */
@@ -965,18 +965,18 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data)
{
const struct memory_handle *h = find_handle(handle_id);
if (!h)
- return -1;
+ return HANDLE_NOT_FOUND;
ssize_t ret;
size_t copy_n = RINGBUF_SUB(h->widx, h->ridx);
if (size == 0 && h->filerem > 0 && copy_n == 0)
/* Data isn't ready */
- return -2;
+ return DATA_NOT_READY;
if (copy_n < size && h->filerem > 0)
/* Data isn't ready */
- return -2;
+ return DATA_NOT_READY;
if (copy_n == 0 && h->filerem == 0)
/* File is finished reading */
@@ -1021,7 +1021,7 @@ ssize_t buf_get_offset(int handle_id, void *ptr)
{
const struct memory_handle *h = find_handle(handle_id);
if (!h)
- return -1;
+ return HANDLE_NOT_FOUND;
return (size_t)ptr - (size_t)&buffer[h->ridx];
}
@@ -1030,7 +1030,7 @@ ssize_t buf_handle_offset(int handle_id)
{
const struct memory_handle *h = find_handle(handle_id);
if (!h)
- return -1;
+ return HANDLE_NOT_FOUND;
return h->offset;
}