Mercurial > libpst
comparison src/readpstlog.c @ 75:987aa872294e stable-0-6-11
Use ftello/fseeko to properly handle large files.
Document and properly use datasize field in b5 blocks.
Fix some MSVC compile issues and collect MSVC dependencies into one place.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 03 Jun 2008 12:00:58 -0700 |
parents | b12f4e50e2e8 |
children | 0f1492b7fe8b |
comparison
equal
deleted
inserted
replaced
74:6f82d13e9300 | 75:987aa872294e |
---|---|
1 #include "define.h" | 1 #include "define.h" |
2 | |
3 #include <stdio.h> | |
4 #include <ctype.h> | |
5 #include <string.h> | |
6 | |
7 #ifndef _WIN32 | |
8 # include <unistd.h> | |
9 #endif | |
10 | |
11 #ifndef __GNUC__ | |
12 # include "XGetopt.h" | |
13 #endif | |
14 | |
15 | 2 |
16 #define BUF_SIZE 4096 | 3 #define BUF_SIZE 4096 |
17 | 4 |
18 int usage(); | 5 int usage(); |
19 size_t get(void * buf, int size, unsigned int count, FILE *fp); | 6 size_t get(void * buf, int size, unsigned int count, FILE *fp); |
21 int is_in(int a, int *b, int c); | 8 int is_in(int a, int *b, int c); |
22 | 9 |
23 int main(int argc, char** argv) { | 10 int main(int argc, char** argv) { |
24 int identity = 0; | 11 int identity = 0; |
25 int level = 0; | 12 int level = 0; |
26 off_t *i = NULL; | |
27 int x, ptr, stop=0, flag; | 13 int x, ptr, stop=0, flag; |
28 char *fname, *buf, rec_type; | 14 char *fname, *buf, rec_type; |
29 unsigned char version; | 15 unsigned char version; |
30 int *show_type=NULL, show_size=0; | 16 int *show_type=NULL, show_size=0; |
31 int *ex_type=NULL, ex_size=0; | 17 int *ex_type=NULL, ex_size=0; |
82 off_t temp; | 68 off_t temp; |
83 if (fread(&temp, sizeof(off_t), 1, fp)<=0) break; | 69 if (fread(&temp, sizeof(off_t), 1, fp)<=0) break; |
84 x = (int)temp; | 70 x = (int)temp; |
85 ptr = 0; | 71 ptr = 0; |
86 if (x > 0) { | 72 if (x > 0) { |
87 if (i) free(i); | 73 off_t i[x+1]; // plus 1 because we want to read the offset of the next index |
88 i = (off_t*)xmalloc(sizeof(off_t)*(x+1)); | |
89 // plus 1 cause we want to read the offset of the next index | |
90 if (get(i, sizeof(off_t), x+1, fp)==0) { | 74 if (get(i, sizeof(off_t), x+1, fp)==0) { |
91 // we have reached the end of the debug file | 75 // we have reached the end of the debug file |
92 printf("oh dear. we must now end\n"); | 76 printf("oh dear. we must now end\n"); |
93 break; | 77 break; |
94 } | 78 } |
95 while (ptr < x) { | 79 while (ptr < x) { |
96 fseek(fp, i[ptr++], SEEK_SET); | 80 fseeko(fp, i[ptr++], SEEK_SET); |
97 get(&rec_type, 1, sizeof(char), fp); | 81 get(&rec_type, 1, sizeof(char), fp); |
98 if (rec_type == 'L') { | 82 if (rec_type == 'L') { |
99 get(&lfile_rec, sizeof(lfile_rec), 1, fp); | 83 get(&lfile_rec, sizeof(lfile_rec), 1, fp); |
100 funcname=lfile_rec.funcname; | 84 funcname=lfile_rec.funcname; |
101 filename=lfile_rec.filename; | 85 filename=lfile_rec.filename; |
180 } | 164 } |
181 printf("\n"); | 165 printf("\n"); |
182 } | 166 } |
183 if (dtype == DEBUG_FUNCRET_NO) level--; | 167 if (dtype == DEBUG_FUNCRET_NO) level--; |
184 } | 168 } |
185 if (fseek(fp, i[ptr], SEEK_SET)==-1) { | 169 if (fseeko(fp, i[ptr], SEEK_SET)==-1) { |
186 printf("finished\n"); | 170 printf("finished\n"); |
187 break; | 171 break; |
188 } | 172 } |
189 } else { | 173 } else { |
190 printf("...no more items\n"); | 174 printf("...no more items\n"); |