diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c b/libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c index 9ba8f81..393e407 100644 --- a/libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c +++ b/libraries/evas/src/modules/loaders/pmaps/evas_image_load_pmaps.c | |||
@@ -19,7 +19,8 @@ Evas_Image_Load_Func evas_image_load_pmaps_func = { | |||
19 | EINA_TRUE, | 19 | EINA_TRUE, |
20 | evas_image_load_file_head_pmaps, | 20 | evas_image_load_file_head_pmaps, |
21 | evas_image_load_file_data_pmaps, | 21 | evas_image_load_file_data_pmaps, |
22 | NULL | 22 | NULL, |
23 | EINA_FALSE | ||
23 | }; | 24 | }; |
24 | 25 | ||
25 | /* The buffer to load pmaps images */ | 26 | /* The buffer to load pmaps images */ |
@@ -27,7 +28,9 @@ typedef struct Pmaps_Buffer Pmaps_Buffer; | |||
27 | 28 | ||
28 | struct Pmaps_Buffer | 29 | struct Pmaps_Buffer |
29 | { | 30 | { |
30 | FILE *file; | 31 | Eina_File *file; |
32 | void *map; | ||
33 | size_t position; | ||
31 | 34 | ||
32 | /* the buffer */ | 35 | /* the buffer */ |
33 | DATA8 buffer[FILE_BUFFER_SIZE]; | 36 | DATA8 buffer[FILE_BUFFER_SIZE]; |
@@ -160,13 +163,23 @@ pmaps_buffer_open(Pmaps_Buffer *b, const char *filename, int *error) | |||
160 | { | 163 | { |
161 | size_t len; | 164 | size_t len; |
162 | 165 | ||
163 | b->file = fopen(filename, "rb"); | 166 | b->file = eina_file_open(filename, EINA_FALSE); |
164 | if (!b->file) | 167 | if (!b->file) |
165 | { | 168 | { |
166 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | 169 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; |
167 | return EINA_FALSE; | 170 | return EINA_FALSE; |
168 | } | 171 | } |
169 | 172 | ||
173 | b->map = eina_file_map_all(b->file, EINA_FILE_SEQUENTIAL); | ||
174 | if (!b->map) | ||
175 | { | ||
176 | *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; | ||
177 | eina_file_close(b->file); | ||
178 | b->file = NULL; | ||
179 | return EINA_FALSE; | ||
180 | } | ||
181 | |||
182 | b->position = 0; | ||
170 | *b->buffer = 0; | 183 | *b->buffer = 0; |
171 | *b->unread = 0; | 184 | *b->unread = 0; |
172 | b->last_buffer = 0; | 185 | b->last_buffer = 0; |
@@ -177,7 +190,9 @@ pmaps_buffer_open(Pmaps_Buffer *b, const char *filename, int *error) | |||
177 | if (len < 3) | 190 | if (len < 3) |
178 | { | 191 | { |
179 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; | 192 | *error = EVAS_LOAD_ERROR_CORRUPT_FILE; |
180 | fclose(b->file); | 193 | eina_file_map_free(b->file, b->map); |
194 | eina_file_close(b->file); | ||
195 | b->map = NULL; | ||
181 | b->file = NULL; | 196 | b->file = NULL; |
182 | return EINA_FALSE; | 197 | return EINA_FALSE; |
183 | } | 198 | } |
@@ -197,7 +212,12 @@ static void | |||
197 | pmaps_buffer_close(Pmaps_Buffer *b) | 212 | pmaps_buffer_close(Pmaps_Buffer *b) |
198 | { | 213 | { |
199 | if (b->file) | 214 | if (b->file) |
200 | fclose(b->file); | 215 | { |
216 | if (b->map) eina_file_map_free(b->file, b->map); | ||
217 | b->map = NULL; | ||
218 | eina_file_close(b->file); | ||
219 | b->file = NULL; | ||
220 | } | ||
201 | } | 221 | } |
202 | 222 | ||
203 | static Eina_Bool | 223 | static Eina_Bool |
@@ -295,6 +315,7 @@ static size_t | |||
295 | pmaps_buffer_plain_update(Pmaps_Buffer *b) | 315 | pmaps_buffer_plain_update(Pmaps_Buffer *b) |
296 | { | 316 | { |
297 | size_t r; | 317 | size_t r; |
318 | size_t max; | ||
298 | 319 | ||
299 | /* if we already are in the last buffer we can not update it */ | 320 | /* if we already are in the last buffer we can not update it */ |
300 | if (b->last_buffer) | 321 | if (b->last_buffer) |
@@ -304,9 +325,14 @@ pmaps_buffer_plain_update(Pmaps_Buffer *b) | |||
304 | * stuff */ | 325 | * stuff */ |
305 | if (b->unread_len) | 326 | if (b->unread_len) |
306 | memcpy(b->buffer, b->unread, b->unread_len); | 327 | memcpy(b->buffer, b->unread, b->unread_len); |
307 | 328 | ||
308 | r = fread(&b->buffer[b->unread_len], 1, | 329 | max = FILE_BUFFER_SIZE - b->unread_len - 1; |
309 | FILE_BUFFER_SIZE - b->unread_len - 1, b->file) + b->unread_len; | 330 | if (b->position + max > eina_file_size_get(b->file)) |
331 | max = eina_file_size_get(b->file) - b->position; | ||
332 | |||
333 | memcpy(&b->buffer[b->unread_len], b->map + b->position, max); | ||
334 | b->position += max; | ||
335 | r = max + b->unread_len; | ||
310 | 336 | ||
311 | /* we haven't read anything nor have we bytes in the unread buffer */ | 337 | /* we haven't read anything nor have we bytes in the unread buffer */ |
312 | if (r == 0) | 338 | if (r == 0) |
@@ -324,7 +350,7 @@ pmaps_buffer_plain_update(Pmaps_Buffer *b) | |||
324 | } | 350 | } |
325 | 351 | ||
326 | b->buffer[r] = 0; | 352 | b->buffer[r] = 0; |
327 | 353 | ||
328 | b->unread[0] = '\0'; | 354 | b->unread[0] = '\0'; |
329 | b->unread_len = 0; | 355 | b->unread_len = 0; |
330 | 356 | ||
@@ -339,6 +365,7 @@ static size_t | |||
339 | pmaps_buffer_raw_update(Pmaps_Buffer *b) | 365 | pmaps_buffer_raw_update(Pmaps_Buffer *b) |
340 | { | 366 | { |
341 | size_t r; | 367 | size_t r; |
368 | size_t max; | ||
342 | 369 | ||
343 | if (b->last_buffer) | 370 | if (b->last_buffer) |
344 | return 0; | 371 | return 0; |
@@ -346,8 +373,13 @@ pmaps_buffer_raw_update(Pmaps_Buffer *b) | |||
346 | if (b->unread_len) | 373 | if (b->unread_len) |
347 | memcpy(b->buffer, b->unread, b->unread_len); | 374 | memcpy(b->buffer, b->unread, b->unread_len); |
348 | 375 | ||
349 | r = fread(&b->buffer[b->unread_len], 1, FILE_BUFFER_SIZE - b->unread_len, | 376 | max = FILE_BUFFER_SIZE - b->unread_len; |
350 | b->file) + b->unread_len; | 377 | if (b->position + max > eina_file_size_get(b->file)) |
378 | max = eina_file_size_get(b->file) - b->position; | ||
379 | |||
380 | memcpy(&b->buffer[b->unread_len], b->map + b->position, max); | ||
381 | b->position += max; | ||
382 | r = max + b->unread_len; | ||
351 | 383 | ||
352 | if (r < FILE_BUFFER_SIZE) | 384 | if (r < FILE_BUFFER_SIZE) |
353 | { | 385 | { |