diff options
author | Peng Wu <alexepico@gmail.com> | 2010-08-05 17:19:03 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2010-08-05 17:19:03 +0800 |
commit | a09f59ffd11df79d7bfcd47e3eb7b97af0723387 (patch) | |
tree | fb1bc845f9234c5b68b923cc6ab35ea2c9e7f8a9 /src | |
parent | 8f9b41ba0be98e6a3caf71b5798bf38324db0676 (diff) | |
download | libpinyin-a09f59ffd11df79d7bfcd47e3eb7b97af0723387.tar.gz libpinyin-a09f59ffd11df79d7bfcd47e3eb7b97af0723387.tar.xz libpinyin-a09f59ffd11df79d7bfcd47e3eb7b97af0723387.zip |
fixes load method.
Diffstat (limited to 'src')
-rwxr-xr-x | src/include/memory_chunk.h | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/include/memory_chunk.h b/src/include/memory_chunk.h index 978126e..6fd9d9a 100755 --- a/src/include/memory_chunk.h +++ b/src/include/memory_chunk.h @@ -23,10 +23,7 @@ #define MEMORY_CHUNK_H #include <assert.h> -#include <sys/types.h> -#include <sys/stat.h> #include <unistd.h> - #include <stdlib.h> #include "stl_lite.h" @@ -217,17 +214,17 @@ public: /* free old data */ reset(); - struct stat stat_buf; - - int retval = stat(filename, &stat_buf); - - if ( retval ) - return false; + size_t file_size; FILE* file = fopen(filename, "r"); if ( !file ) return false; - int data_len = stat_buf.st_size; + + fseek(file, 0, SEEK_END); + file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + int data_len = file_size; void* data = malloc(data_len); if ( !data ){ fclose(file); @@ -236,9 +233,7 @@ public: data_len = fread(data, 1, data_len, file); set_chunk(data, data_len, free); - //Fixes memory chunk end. - if ( stat_buf.st_size > data_len ) - m_allocated = (char *) m_data_begin + stat_buf.st_size; + fclose(file); return true; } |