summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
authorBrandon Low <lostlogic@rockbox.org>2007-11-28 04:58:16 +0000
committerBrandon Low <lostlogic@rockbox.org>2007-11-28 04:58:16 +0000
commit3386dd7be90f4f4a23d36359f2052fa834fb20e7 (patch)
tree4765c534909e8d55455872bf7b0b2b1e464ff2c5 /apps/buffering.c
parent05784b52abb3d21dfe0e7b1e014e601ce1d10803 (diff)
downloadrockbox-3386dd7be90f4f4a23d36359f2052fa834fb20e7.tar.gz
rockbox-3386dd7be90f4f4a23d36359f2052fa834fb20e7.zip
Fix FS8069, because Nico_P made it easy
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15840 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index f0a50c274c..f5bc2eeb19 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -657,6 +657,7 @@ static bool buffer_handle(int handle_id)
657 /* finished buffering the file */ 657 /* finished buffering the file */
658 close(h->fd); 658 close(h->fd);
659 h->fd = -1; 659 h->fd = -1;
660 call_buffering_callbacks(EVENT_HANDLE_FINISHED, h->id);
660 } 661 }
661 662
662 return true; 663 return true;
@@ -1138,6 +1139,58 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data)
1138 return size; 1139 return size;
1139} 1140}
1140 1141
1142ssize_t bufgettail(int handle_id, size_t size, void **data)
1143{
1144 size_t tidx;
1145
1146 const struct memory_handle *h;
1147
1148 h = find_handle(handle_id);
1149
1150 if (!h)
1151 return ERR_HANDLE_NOT_FOUND;
1152
1153 if (h->filerem)
1154 return ERR_HANDLE_NOT_DONE;
1155
1156 /* We don't support tail requests of > guardbuf_size, for simplicity */
1157 if (size > GUARD_BUFSIZE)
1158 return ERR_INVALID_VALUE;
1159
1160 tidx = RINGBUF_SUB(h->widx, size);
1161
1162 if (tidx + size > buffer_len)
1163 {
1164 size_t copy_n = tidx + size - buffer_len;
1165 memcpy(guard_buffer, (unsigned char *)buffer, copy_n);
1166 }
1167
1168 *data = &buffer[tidx];
1169 return size;
1170}
1171
1172ssize_t bufcuttail(int handle_id, size_t size)
1173{
1174 struct memory_handle *h;
1175
1176 h = find_handle(handle_id);
1177
1178 if (!h)
1179 return ERR_HANDLE_NOT_FOUND;
1180
1181 if (h->filerem)
1182 return ERR_HANDLE_NOT_DONE;
1183
1184 if (h->available < size)
1185 size = h->available;
1186
1187 h->available -= size;
1188 h->filesize -= size;
1189 h->widx = RINGBUF_SUB(h->widx, size);
1190 return size;
1191}
1192
1193
1141/* 1194/*
1142SECONDARY EXPORTED FUNCTIONS 1195SECONDARY EXPORTED FUNCTIONS
1143============================ 1196============================