summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 35e47fe51e..0600202717 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -803,11 +803,11 @@ management functions for all the actual handle management work.
803int bufopen(const char *file, size_t offset, enum data_type type) 803int bufopen(const char *file, size_t offset, enum data_type type)
804{ 804{
805 if (!can_add_handle()) 805 if (!can_add_handle())
806 return BUFFER_FULL; 806 return ERR_BUFFER_FULL;
807 807
808 int fd = open(file, O_RDONLY); 808 int fd = open(file, O_RDONLY);
809 if (fd < 0) 809 if (fd < 0)
810 return FILE_ERROR; 810 return ERR_FILE_ERROR;
811 811
812 size_t size = filesize(fd); 812 size_t size = filesize(fd);
813 813
@@ -816,7 +816,7 @@ int bufopen(const char *file, size_t offset, enum data_type type)
816 { 816 {
817 DEBUGF("bufopen: failed to add handle\n"); 817 DEBUGF("bufopen: failed to add handle\n");
818 close(fd); 818 close(fd);
819 return BUFFER_FULL; 819 return ERR_BUFFER_FULL;
820 } 820 }
821 821
822 strncpy(h->path, file, MAX_PATH); 822 strncpy(h->path, file, MAX_PATH);
@@ -854,12 +854,12 @@ int bufopen(const char *file, size_t offset, enum data_type type)
854int bufalloc(const void *src, size_t size, enum data_type type) 854int bufalloc(const void *src, size_t size, enum data_type type)
855{ 855{
856 if (!can_add_handle()) 856 if (!can_add_handle())
857 return BUFFER_FULL; 857 return ERR_BUFFER_FULL;
858 858
859 struct memory_handle *h = add_handle(size, false, true); 859 struct memory_handle *h = add_handle(size, false, true);
860 860
861 if (!h) 861 if (!h)
862 return BUFFER_FULL; 862 return ERR_BUFFER_FULL;
863 863
864 if (src) { 864 if (src) {
865 if (type == TYPE_ID3 && size == sizeof(struct mp3entry)) { 865 if (type == TYPE_ID3 && size == sizeof(struct mp3entry)) {
@@ -907,11 +907,11 @@ int bufseek(int handle_id, size_t newpos)
907{ 907{
908 struct memory_handle *h = find_handle(handle_id); 908 struct memory_handle *h = find_handle(handle_id);
909 if (!h) 909 if (!h)
910 return HANDLE_NOT_FOUND; 910 return ERR_HANDLE_NOT_FOUND;
911 911
912 if (newpos > h->filesize) { 912 if (newpos > h->filesize) {
913 /* access beyond the end of the file */ 913 /* access beyond the end of the file */
914 return INVALID_VALUE; 914 return ERR_INVALID_VALUE;
915 } 915 }
916 else if (newpos < h->offset || h->offset + h->available < newpos) { 916 else if (newpos < h->offset || h->offset + h->available < newpos) {
917 /* access before or after buffered data. A rebuffer is needed. */ 917 /* access before or after buffered data. A rebuffer is needed. */
@@ -929,7 +929,7 @@ int bufadvance(int handle_id, off_t offset)
929{ 929{
930 const struct memory_handle *h = find_handle(handle_id); 930 const struct memory_handle *h = find_handle(handle_id);
931 if (!h) 931 if (!h)
932 return HANDLE_NOT_FOUND; 932 return ERR_HANDLE_NOT_FOUND;
933 933
934 size_t newpos = h->offset + RINGBUF_SUB(h->ridx, h->data) + offset; 934 size_t newpos = h->offset + RINGBUF_SUB(h->ridx, h->data) + offset;
935 return bufseek(handle_id, newpos); 935 return bufseek(handle_id, newpos);
@@ -941,18 +941,18 @@ ssize_t bufread(int handle_id, size_t size, void *dest)
941{ 941{
942 const struct memory_handle *h = find_handle(handle_id); 942 const struct memory_handle *h = find_handle(handle_id);
943 if (!h) 943 if (!h)
944 return HANDLE_NOT_FOUND; 944 return ERR_HANDLE_NOT_FOUND;
945 945
946 size_t ret; 946 size_t ret;
947 size_t copy_n = RINGBUF_SUB(h->widx, h->ridx); 947 size_t copy_n = RINGBUF_SUB(h->widx, h->ridx);
948 948
949 if (size == 0 && h->filerem > 0 && copy_n == 0) 949 if (size == 0 && h->filerem > 0 && copy_n == 0)
950 /* Data isn't ready */ 950 /* Data isn't ready */
951 return DATA_NOT_READY; 951 return ERR_DATA_NOT_READY;
952 952
953 if (copy_n < size && h->filerem > 0) 953 if (copy_n < size && h->filerem > 0)
954 /* Data isn't ready */ 954 /* Data isn't ready */
955 return DATA_NOT_READY; 955 return ERR_DATA_NOT_READY;
956 956
957 if (copy_n == 0 && h->filerem == 0) 957 if (copy_n == 0 && h->filerem == 0)
958 /* File is finished reading */ 958 /* File is finished reading */
@@ -984,18 +984,18 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data)
984{ 984{
985 const struct memory_handle *h = find_handle(handle_id); 985 const struct memory_handle *h = find_handle(handle_id);
986 if (!h) 986 if (!h)
987 return HANDLE_NOT_FOUND; 987 return ERR_HANDLE_NOT_FOUND;
988 988
989 ssize_t ret; 989 ssize_t ret;
990 size_t copy_n = RINGBUF_SUB(h->widx, h->ridx); 990 size_t copy_n = RINGBUF_SUB(h->widx, h->ridx);
991 991
992 if (size == 0 && h->filerem > 0 && copy_n == 0) 992 if (size == 0 && h->filerem > 0 && copy_n == 0)
993 /* Data isn't ready */ 993 /* Data isn't ready */
994 return DATA_NOT_READY; 994 return ERR_DATA_NOT_READY;
995 995
996 if (copy_n < size && h->filerem > 0) 996 if (copy_n < size && h->filerem > 0)
997 /* Data isn't ready */ 997 /* Data isn't ready */
998 return DATA_NOT_READY; 998 return ERR_DATA_NOT_READY;
999 999
1000 if (copy_n == 0 && h->filerem == 0) 1000 if (copy_n == 0 && h->filerem == 0)
1001 /* File is finished reading */ 1001 /* File is finished reading */
@@ -1040,7 +1040,7 @@ ssize_t buf_get_offset(int handle_id, void *ptr)
1040{ 1040{
1041 const struct memory_handle *h = find_handle(handle_id); 1041 const struct memory_handle *h = find_handle(handle_id);
1042 if (!h) 1042 if (!h)
1043 return HANDLE_NOT_FOUND; 1043 return ERR_HANDLE_NOT_FOUND;
1044 1044
1045 return (size_t)ptr - (size_t)&buffer[h->ridx]; 1045 return (size_t)ptr - (size_t)&buffer[h->ridx];
1046} 1046}
@@ -1049,7 +1049,7 @@ ssize_t buf_handle_offset(int handle_id)
1049{ 1049{
1050 const struct memory_handle *h = find_handle(handle_id); 1050 const struct memory_handle *h = find_handle(handle_id);
1051 if (!h) 1051 if (!h)
1052 return HANDLE_NOT_FOUND; 1052 return ERR_HANDLE_NOT_FOUND;
1053 return h->offset; 1053 return h->offset;
1054} 1054}
1055 1055