Diffstat (limited to 'noncore/apps/opie-reader/pdb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/pdb.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/noncore/apps/opie-reader/pdb.cpp b/noncore/apps/opie-reader/pdb.cpp index 68b904e..3054424 100644 --- a/noncore/apps/opie-reader/pdb.cpp +++ b/noncore/apps/opie-reader/pdb.cpp | |||
@@ -1,57 +1,63 @@ | |||
1 | #include "pdb.h" | 1 | #include "pdb.h" |
2 | #include <sys/types.h> | ||
3 | #include <sys/stat.h> | ||
4 | #include <unistd.h> | ||
2 | 5 | ||
3 | size_t Cpdb::recordpos(int n) | 6 | size_t Cpdb::recordpos(int n) |
4 | { | 7 | { |
5 | UInt16 mxn = ntohs(head.recordList.numRecords); | 8 | UInt16 mxn = ntohs(head.recordList.numRecords); |
6 | if (n >= mxn) | 9 | if (n >= mxn) |
7 | { | 10 | { |
8 | return file_length; | 11 | return file_length; |
9 | } | 12 | } |
10 | else | 13 | else |
11 | { | 14 | { |
12 | size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16); | 15 | size_t dataoffset = sizeof(DatabaseHdrType) - sizeof(UInt16); |
13 | dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n; | 16 | dataoffset += /*dataoffset%4 + */ sizeof(RecordListType) * n; |
14 | fseek(fin, dataoffset, SEEK_SET); | 17 | fseek(fin, dataoffset, SEEK_SET); |
15 | RecordListType hdr; | 18 | RecordListType hdr; |
16 | fread(&hdr, 1, sizeof(hdr), fin); | 19 | fread(&hdr, 1, sizeof(hdr), fin); |
17 | return ntohl(hdr.nextRecordListID); | 20 | return ntohl(hdr.nextRecordListID); |
18 | } | 21 | } |
19 | 22 | ||
20 | } | 23 | } |
21 | 24 | ||
22 | size_t Cpdb::recordlength(int n) | 25 | size_t Cpdb::recordlength(int n) |
23 | { | 26 | { |
24 | return recordpos(n+1)-recordpos(n); | 27 | return recordpos(n+1)-recordpos(n); |
25 | } | 28 | } |
26 | 29 | ||
27 | void Cpdb::gotorecordnumber(int n) | 30 | void Cpdb::gotorecordnumber(int n) |
28 | { | 31 | { |
29 | fseek(fin, recordpos(n), SEEK_SET); | 32 | fseek(fin, recordpos(n), SEEK_SET); |
30 | } | 33 | } |
31 | 34 | ||
32 | bool Cpdb::openfile(const char *src) | 35 | bool Cpdb::openfile(const char *src) |
33 | { | 36 | { |
34 | 37 | ||
35 | // printf("In openfile\n"); | 38 | // printf("In openfile\n"); |
36 | int ret = 0; | 39 | int ret = 0; |
37 | // printf("closing fin:%x\n",fin); | 40 | // printf("closing fin:%x\n",fin); |
38 | if (fin != NULL) fclose(fin); | 41 | if (fin != NULL) fclose(fin); |
39 | // printf("opening fin\n"); | 42 | // printf("opening fin\n"); |
40 | fin = fopen(src,"rb"); | 43 | fin = fopen(src,"rb"); |
41 | 44 | ||
42 | if (fin==0) | 45 | if (fin==0) |
43 | { | 46 | { |
44 | return false; | 47 | return false; |
45 | } | 48 | } |
46 | 49 | ||
47 | // just holds the first few chars of the file | 50 | // just holds the first few chars of the file |
48 | //char buf[0x100]; | 51 | //char buf[0x100]; |
49 | fseek(fin,0,SEEK_END); | 52 | struct stat buf; |
50 | file_length = ftell(fin); | 53 | stat(src, &buf); |
54 | file_length = buf.st_size; | ||
55 | // fseek(fin,0,SEEK_END); | ||
56 | // file_length = ftell(fin); | ||
51 | 57 | ||
52 | fseek(fin,0,SEEK_SET); | 58 | // fseek(fin,0,SEEK_SET); |
53 | 59 | ||
54 | fread(&head, 1, sizeof(head), fin); | 60 | fread(&head, 1, sizeof(head), fin); |
55 | 61 | ||
56 | return true; | 62 | return true; |
57 | } | 63 | } |