summaryrefslogtreecommitdiff
path: root/firmware/general.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2010-05-17 12:34:05 +0000
committerMichael Sevakis <jethead71@rockbox.org>2010-05-17 12:34:05 +0000
commitfcf36dd4f9879a82342e5606535d2dcf46d1de2a (patch)
tree21ed249c7a6f9d0bd7e2049c7a9f9e0708ba28f8 /firmware/general.c
parent9fde12676b382a31a10c58e2473edfde460e4d73 (diff)
downloadrockbox-fcf36dd4f9879a82342e5606535d2dcf46d1de2a.tar.gz
rockbox-fcf36dd4f9879a82342e5606535d2dcf46d1de2a.zip
Simplify mpegplayer a bit and use array-based lists rather than linked lists for stream management. Move a couple useful functions to handle pointer arrays from kernel.c into general.c; mpeglayer now makes use of them.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26101 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/general.c')
-rw-r--r--firmware/general.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/firmware/general.c b/firmware/general.c
index fa1025492b..20b0277c09 100644
--- a/firmware/general.c
+++ b/firmware/general.c
@@ -196,3 +196,40 @@ char *create_datetime_filename(char *buffer, const char *path,
196 return buffer; 196 return buffer;
197} 197}
198#endif /* CONFIG_RTC */ 198#endif /* CONFIG_RTC */
199
200/***
201 ** Compacted pointer lists
202 **
203 ** N-length list requires N+1 elements to ensure NULL-termination.
204 **/
205
206/* Find a pointer in a pointer array. Returns the addess of the element if
207 * found or the address of the terminating NULL otherwise. This can be used
208 * to bounds check and add items. */
209void ** find_array_ptr(void **arr, void *ptr)
210{
211 void *curr;
212 for (curr = *arr; curr != NULL && curr != ptr; curr = *(++arr));
213 return arr;
214}
215
216/* Remove a pointer from a pointer array if it exists. Compacts it so that
217 * no gaps exist. Returns 0 on success and -1 if the element wasn't found. */
218int remove_array_ptr(void **arr, void *ptr)
219{
220 void *curr;
221 arr = find_array_ptr(arr, ptr);
222
223 if (*arr == NULL)
224 return -1;
225
226 /* Found. Slide up following items. */
227 do
228 {
229 void **arr1 = arr + 1;
230 *arr++ = curr = *arr1;
231 }
232 while (curr != NULL);
233
234 return 0;
235}