diff options
author | Michiel Van Der Kolk <not.valid@email.address> | 2005-04-28 14:20:23 +0000 |
---|---|---|
committer | Michiel Van Der Kolk <not.valid@email.address> | 2005-04-28 14:20:23 +0000 |
commit | 9ceac0a293b22e71dc534a89751f7c4be8b1a0cb (patch) | |
tree | 5754a28dfec5ccefcbdfcf80da3bba713ae60b36 /apps/plugins | |
parent | 4350eec6bb2e87ee4b777911dbb2dbbf2a27ab7a (diff) | |
download | rockbox-9ceac0a293b22e71dc534a89751f7c4be8b1a0cb.tar.gz rockbox-9ceac0a293b22e71dc534a89751f7c4be8b1a0cb.zip |
Better endian functions for reading longs/shorts
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6371 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/searchengine/dbinterface.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/apps/plugins/searchengine/dbinterface.c b/apps/plugins/searchengine/dbinterface.c index 9ab52ad103..778a7adb3b 100644 --- a/apps/plugins/searchengine/dbinterface.c +++ b/apps/plugins/searchengine/dbinterface.c | |||
@@ -54,19 +54,33 @@ int database_init() { | |||
54 | return 0; | 54 | return 0; |
55 | } | 55 | } |
56 | 56 | ||
57 | long readlong(int fd) { | ||
58 | long num; | ||
59 | rb->read(fd,&num,4); | ||
60 | #ifdef ROCKBOX_LITTLE_ENDIAN | ||
61 | num=BE32(num); | ||
62 | #endif | ||
63 | return num; | ||
64 | } | ||
65 | |||
66 | short readshort(int fd) { | ||
67 | short num; | ||
68 | rb->read(fd,&num,2); | ||
69 | #ifdef ROCKBOX_LITTLE_ENDIAN | ||
70 | num=BE16(num); | ||
71 | #endif | ||
72 | return num; | ||
73 | } | ||
74 | |||
75 | |||
57 | void loadentry(int filerecord) { | 76 | void loadentry(int filerecord) { |
58 | if(entryarray[filerecord].loadedfiledata==0) { | 77 | if(entryarray[filerecord].loadedfiledata==0) { |
59 | rb->lseek(*rb->tagdb_fd,FILERECORD2OFFSET(filerecord),SEEK_SET); | 78 | rb->lseek(*rb->tagdb_fd,FILERECORD2OFFSET(filerecord),SEEK_SET); |
60 | entryarray[filerecord].filename=(char *)my_malloc(rb->tagdbheader->filelen); | 79 | entryarray[filerecord].filename=(char *)my_malloc(rb->tagdbheader->filelen); |
61 | rb->read(*rb->tagdb_fd,entryarray[filerecord].filename,rb->tagdbheader->filelen); | 80 | rb->read(*rb->tagdb_fd,entryarray[filerecord].filename,rb->tagdbheader->filelen); |
62 | rb->read(*rb->tagdb_fd,&entryarray[filerecord].hash,4); | 81 | entryarray[filerecord].hash=readlong(*rb->tagdb_fd); |
63 | rb->read(*rb->tagdb_fd,&entryarray[filerecord].songentry,4); | 82 | entryarray[filerecord].songentry=readlong(*rb->tagdb_fd); |
64 | rb->read(*rb->tagdb_fd,&entryarray[filerecord].rundbentry,4); | 83 | entryarray[filerecord].rundbentry=readlong(*rb->tagdb_fd); |
65 | #ifdef ROCKBOX_LITTLE_ENDIAN | ||
66 | entryarray[filerecord].hash=BE32(entryarray[filerecord].hash); | ||
67 | entryarray[filerecord].songentry=BE32(entryarray[filerecord].songentry); | ||
68 | entryarray[filerecord].rundbentry=BE32(entryarray[filerecord].rundbentry); | ||
69 | #endif | ||
70 | entryarray[filerecord].loadedfiledata=1; | 84 | entryarray[filerecord].loadedfiledata=1; |
71 | } | 85 | } |
72 | currententry=&entryarray[filerecord]; | 86 | currententry=&entryarray[filerecord]; |
@@ -80,18 +94,12 @@ void loadsongdata() { | |||
80 | currententry->genre=(char *)my_malloc(rb->tagdbheader->genrelen); | 94 | currententry->genre=(char *)my_malloc(rb->tagdbheader->genrelen); |
81 | rb->lseek(*rb->tagdb_fd,currententry->songentry,SEEK_SET); | 95 | rb->lseek(*rb->tagdb_fd,currententry->songentry,SEEK_SET); |
82 | rb->read(*rb->tagdb_fd,currententry->title,rb->tagdbheader->songlen); | 96 | rb->read(*rb->tagdb_fd,currententry->title,rb->tagdbheader->songlen); |
83 | rb->read(*rb->tagdb_fd,¤tentry->artistoffset,4); | 97 | currententry->artistoffset=readlong(*rb->tagdb_fd); |
84 | rb->read(*rb->tagdb_fd,¤tentry->albumoffset,4); | 98 | currententry->albumoffset=readlong(*rb->tagdb_fd); |
85 | rb->lseek(*rb->tagdb_fd,4,SEEK_CUR); | 99 | rb->lseek(*rb->tagdb_fd,4,SEEK_CUR); |
86 | rb->read(*rb->tagdb_fd,currententry->genre,rb->tagdbheader->genrelen); | 100 | rb->read(*rb->tagdb_fd,currententry->genre,rb->tagdbheader->genrelen); |
87 | rb->read(*rb->tagdb_fd,¤tentry->bitrate,2); | 101 | currententry->bitrate=readshort(*rb->tagdb_fd); |
88 | rb->read(*rb->tagdb_fd,¤tentry->year,2); | 102 | currententry->year=readshort(*rb->tagdb_fd); |
89 | #ifdef ROCKBOX_LITTLE_ENDIAN | ||
90 | currententry->artistoffset=BE32(currententry->artistoffset); | ||
91 | currententry->albumoffset=BE32(currententry->albumoffset); | ||
92 | currententry->bitrate=BE16(currententry->bitrate); | ||
93 | currententry->year=BE16(currententry->year); | ||
94 | #endif | ||
95 | currententry->loadedsongdata=1; | 103 | currententry->loadedsongdata=1; |
96 | } | 104 | } |
97 | 105 | ||