summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
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,
253 253
254 /* This is how far we shifted buf_widx to align things */ 254 /* This is how far we shifted buf_widx to align things */
255 shift = RINGBUF_SUB(new_widx, buf_widx); 255 shift = RINGBUF_SUB(new_widx, buf_widx);
256 256
257 /* How much space are we short in the actual ring buffer? */ 257 /* How much space are we short in the actual ring buffer? */
258 overlap = RINGBUF_ADD_CROSS(buf_widx, shift + len, buf_ridx); 258 overlap = RINGBUF_ADD_CROSS(buf_widx, shift + len, buf_ridx);
259 if (overlap >= 0 && (alloc_all || (unsigned)overlap > data_size)) { 259 if (overlap >= 0 && (alloc_all || (unsigned)overlap > data_size)) {
@@ -426,7 +426,7 @@ static struct memory_handle *move_handle(const struct memory_handle *h,
426 overlap -= correction; 426 overlap -= correction;
427 *delta -= correction; 427 *delta -= correction;
428 } 428 }
429 429
430 dest = (struct memory_handle *)(&buffer[newpos]); 430 dest = (struct memory_handle *)(&buffer[newpos]);
431 431
432 if (h == first_handle) { 432 if (h == first_handle) {
@@ -784,11 +784,11 @@ management functions for all the actual handle management work.
784int bufopen(const char *file, size_t offset, enum data_type type) 784int bufopen(const char *file, size_t offset, enum data_type type)
785{ 785{
786 if (!can_add_handle()) 786 if (!can_add_handle())
787 return -2; 787 return BUFFER_FULL;
788 788
789 int fd = open(file, O_RDONLY); 789 int fd = open(file, O_RDONLY);
790 if (fd < 0) 790 if (fd < 0)
791 return -1; 791 return FILE_ERROR;
792 792
793 size_t size = filesize(fd); 793 size_t size = filesize(fd);
794 794
@@ -797,7 +797,7 @@ int bufopen(const char *file, size_t offset, enum data_type type)
797 { 797 {
798 DEBUGF("bufopen: failed to add handle\n"); 798 DEBUGF("bufopen: failed to add handle\n");
799 close(fd); 799 close(fd);
800 return -2; 800 return BUFFER_FULL;
801 } 801 }
802 802
803 strncpy(h->path, file, MAX_PATH); 803 strncpy(h->path, file, MAX_PATH);
@@ -835,12 +835,12 @@ int bufopen(const char *file, size_t offset, enum data_type type)
835int bufalloc(const void *src, size_t size, enum data_type type) 835int bufalloc(const void *src, size_t size, enum data_type type)
836{ 836{
837 if (!can_add_handle()) 837 if (!can_add_handle())
838 return -2; 838 return BUFFER_FULL;
839 839
840 struct memory_handle *h = add_handle(size, false, true); 840 struct memory_handle *h = add_handle(size, false, true);
841 841
842 if (!h) 842 if (!h)
843 return -2; 843 return BUFFER_FULL;
844 844
845 if (src) { 845 if (src) {
846 if (type == TYPE_ID3 && size == sizeof(struct mp3entry)) { 846 if (type == TYPE_ID3 && size == sizeof(struct mp3entry)) {
@@ -888,11 +888,11 @@ int bufseek(int handle_id, size_t newpos)
888{ 888{
889 struct memory_handle *h = find_handle(handle_id); 889 struct memory_handle *h = find_handle(handle_id);
890 if (!h) 890 if (!h)
891 return -1; 891 return HANDLE_NOT_FOUND;
892 892
893 if (newpos > h->filesize) { 893 if (newpos > h->filesize) {
894 /* access beyond the end of the file */ 894 /* access beyond the end of the file */
895 return -3; 895 return INVALID_VALUE;
896 } 896 }
897 else if (newpos < h->offset || h->offset + h->available < newpos) { 897 else if (newpos < h->offset || h->offset + h->available < newpos) {
898 /* access before or after buffered data. A rebuffer is needed. */ 898 /* access before or after buffered data. A rebuffer is needed. */
@@ -910,7 +910,7 @@ int bufadvance(int handle_id, off_t offset)
910{ 910{
911 const struct memory_handle *h = find_handle(handle_id); 911 const struct memory_handle *h = find_handle(handle_id);
912 if (!h) 912 if (!h)
913 return -1; 913 return HANDLE_NOT_FOUND;
914 914
915 size_t newpos = h->offset + RINGBUF_SUB(h->ridx, h->data) + offset; 915 size_t newpos = h->offset + RINGBUF_SUB(h->ridx, h->data) + offset;
916 return bufseek(handle_id, newpos); 916 return bufseek(handle_id, newpos);
@@ -922,18 +922,18 @@ ssize_t bufread(int handle_id, size_t size, void *dest)
922{ 922{
923 const struct memory_handle *h = find_handle(handle_id); 923 const struct memory_handle *h = find_handle(handle_id);
924 if (!h) 924 if (!h)
925 return -1; 925 return HANDLE_NOT_FOUND;
926 926
927 size_t ret; 927 size_t ret;
928 size_t copy_n = RINGBUF_SUB(h->widx, h->ridx); 928 size_t copy_n = RINGBUF_SUB(h->widx, h->ridx);
929 929
930 if (size == 0 && h->filerem > 0 && copy_n == 0) 930 if (size == 0 && h->filerem > 0 && copy_n == 0)
931 /* Data isn't ready */ 931 /* Data isn't ready */
932 return -2; 932 return DATA_NOT_READY;
933 933
934 if (copy_n < size && h->filerem > 0) 934 if (copy_n < size && h->filerem > 0)
935 /* Data isn't ready */ 935 /* Data isn't ready */
936 return -2; 936 return DATA_NOT_READY;
937 937
938 if (copy_n == 0 && h->filerem == 0) 938 if (copy_n == 0 && h->filerem == 0)
939 /* File is finished reading */ 939 /* File is finished reading */
@@ -965,18 +965,18 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data)
965{ 965{
966 const struct memory_handle *h = find_handle(handle_id); 966 const struct memory_handle *h = find_handle(handle_id);
967 if (!h) 967 if (!h)
968 return -1; 968 return HANDLE_NOT_FOUND;
969 969
970 ssize_t ret; 970 ssize_t ret;
971 size_t copy_n = RINGBUF_SUB(h->widx, h->ridx); 971 size_t copy_n = RINGBUF_SUB(h->widx, h->ridx);
972 972
973 if (size == 0 && h->filerem > 0 && copy_n == 0) 973 if (size == 0 && h->filerem > 0 && copy_n == 0)
974 /* Data isn't ready */ 974 /* Data isn't ready */
975 return -2; 975 return DATA_NOT_READY;
976 976
977 if (copy_n < size && h->filerem > 0) 977 if (copy_n < size && h->filerem > 0)
978 /* Data isn't ready */ 978 /* Data isn't ready */
979 return -2; 979 return DATA_NOT_READY;
980 980
981 if (copy_n == 0 && h->filerem == 0) 981 if (copy_n == 0 && h->filerem == 0)
982 /* File is finished reading */ 982 /* File is finished reading */
@@ -1021,7 +1021,7 @@ ssize_t buf_get_offset(int handle_id, void *ptr)
1021{ 1021{
1022 const struct memory_handle *h = find_handle(handle_id); 1022 const struct memory_handle *h = find_handle(handle_id);
1023 if (!h) 1023 if (!h)
1024 return -1; 1024 return HANDLE_NOT_FOUND;
1025 1025
1026 return (size_t)ptr - (size_t)&buffer[h->ridx]; 1026 return (size_t)ptr - (size_t)&buffer[h->ridx];
1027} 1027}
@@ -1030,7 +1030,7 @@ ssize_t buf_handle_offset(int handle_id)
1030{ 1030{
1031 const struct memory_handle *h = find_handle(handle_id); 1031 const struct memory_handle *h = find_handle(handle_id);
1032 if (!h) 1032 if (!h)
1033 return -1; 1033 return HANDLE_NOT_FOUND;
1034 return h->offset; 1034 return h->offset;
1035} 1035}
1036 1036