From f8ffa3fdb516440808679e405d69eb76b0905606 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 1 Feb 2012 08:43:56 -0800 Subject: [PATCH] replaced seek with fstat() --- src/Image.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Image.cc b/src/Image.cc index e94d0aa..86b70a5 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -396,22 +396,27 @@ read_gif_from_memory(GifFileType *gif, GifByteType *buf, int len) { cairo_status_t Image::loadGIF(FILE *stream) { - fseek(stream, 0L, SEEK_END); - int len = ftell(stream); - fseek(stream, 0L, SEEK_SET); + struct stat s; + int fd = fileno(stream); - uint8_t *buf = (uint8_t *) malloc(len); + // stat + if (fstat(fd, &s) < 0) { + fclose(stream); + return CAIRO_STATUS_READ_ERROR; + } + + uint8_t *buf = (uint8_t *) malloc(s.st_size); if (!buf) { fclose(stream); return CAIRO_STATUS_NO_MEMORY; } - size_t read = fread(buf, len, 1, stream); + size_t read = fread(buf, s.st_size, 1, stream); fclose(stream); cairo_status_t result = CAIRO_STATUS_READ_ERROR; - if (1 == read) result = loadGIFFromBuffer(buf, len); + if (1 == read) result = loadGIFFromBuffer(buf, s.st_size); free(buf); return result;