summaryrefslogtreecommitdiffstats
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
parent9f6719ec56f2a6b5ae164f6be7dcd7fc3f072d75 (diff)
downloadrockbox-7807279eaf698474e2eabde440b73a1f587ea7ef.tar.gz
rockbox-7807279eaf698474e2eabde440b73a1f587ea7ef.zip
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
-rw-r--r--apps/buffering.c36
-rw-r--r--apps/buffering.h7
-rw-r--r--apps/playback.c12
3 files changed, 31 insertions, 24 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;
}
diff --git a/apps/buffering.h b/apps/buffering.h
index 29771adc1a..7dc07f5881 100644
--- a/apps/buffering.h
+++ b/apps/buffering.h
@@ -35,6 +35,13 @@ enum data_type {
TYPE_UNKNOWN,
};
+/* Error return values */
+#define HANDLE_NOT_FOUND -1
+#define BUFFER_FULL -2
+#define INVALID_VALUE -3
+#define FILE_ERROR -4
+#define DATA_NOT_READY -5
+
/* Initialise the buffering subsystem */
void buffering_init(void);
diff --git a/apps/playback.c b/apps/playback.c
index 3c1dd37d3f..2fae4d34ea 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -366,11 +366,11 @@ static void *bufgetcodec(struct track_info *track)
void *ptr;
ssize_t ret = bufgetdata(track->codec_hid, track->codecsize, &ptr);
- if (ret == -2) {
+ if (ret == DATA_NOT_READY) {
buf_request_buffer_handle(track->codec_hid);
}
- while (ret == -2) {
+ while (ret == DATA_NOT_READY) {
sleep(1);
ret = bufgetdata(track->codec_hid, track->codecsize, &ptr);
}
@@ -1516,13 +1516,13 @@ static size_t codec_filebuf_callback(void *ptr, size_t size)
return 0;
- if (copy_n == -2)
+ if (copy_n == DATA_NOT_READY)
{
buf_request_buffer_handle(CUR_TI->audio_hid);
}
/* Let the disk buffer catch fill until enough data is available */
- while (copy_n == -2)
+ while (copy_n == DATA_NOT_READY)
{
sleep(1);
@@ -1561,13 +1561,13 @@ static void* codec_request_buffer_callback(size_t *realsize, size_t reqsize)
return NULL;
}
- if (ret == -2)
+ if (ret == DATA_NOT_READY)
{
buf_request_buffer_handle(CUR_TI->audio_hid);
}
/* Let the disk buffer catch fill until enough data is available */
- while (ret == -2)
+ while (ret == DATA_NOT_READY)
{
sleep(1);