X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=vpxstats.c;h=142e367bb48c440fc7873722cdff8cbfdaaca8d5;hb=8099220e6c5e2cc8c857f85e1429d857c87a6f2a;hp=5f88f8d35975a38b388b6cc46f80c66fbb2f3c84;hpb=d5e6f09585d07381068ae533dfad6a8a91febfd8;p=libvpx diff --git a/vpxstats.c b/vpxstats.c index 5f88f8d35..142e367bb 100644 --- a/vpxstats.c +++ b/vpxstats.c @@ -26,21 +26,12 @@ int stats_open_file(stats_io_t *stats, const char *fpf, int pass) { stats->buf.buf = NULL; res = (stats->file != NULL); } else { -#if USE_POSIX_MMAP - struct stat stat_buf; - int fd; - - fd = open(fpf, O_RDONLY); - stats->file = fdopen(fd, "rb"); - fstat(fd, &stat_buf); - stats->buf.sz = stat_buf.st_size; - stats->buf.buf = mmap(NULL, stats->buf.sz, PROT_READ, MAP_PRIVATE, fd, 0); - res = (stats->buf.buf != NULL); -#else size_t nbytes; stats->file = fopen(fpf, "rb"); + if (stats->file == NULL) fatal("First-pass stats file does not exist!"); + if (fseek(stats->file, 0, SEEK_END)) fatal("First-pass stats file must be seekable!"); @@ -55,7 +46,6 @@ int stats_open_file(stats_io_t *stats, const char *fpf, int pass) { nbytes = fread(stats->buf.buf, 1, stats->buf.sz, stats->file); res = (nbytes == stats->buf.sz); -#endif /* USE_POSIX_MMAP */ } return res; @@ -79,28 +69,23 @@ int stats_open_mem(stats_io_t *stats, int pass) { void stats_close(stats_io_t *stats, int last_pass) { if (stats->file) { if (stats->pass == last_pass) { -#if USE_POSIX_MMAP - munmap(stats->buf.buf, stats->buf.sz); -#else free(stats->buf.buf); -#endif /* USE_POSIX_MMAP */ } fclose(stats->file); stats->file = NULL; } else { - if (stats->pass == last_pass) - free(stats->buf.buf); + if (stats->pass == last_pass) free(stats->buf.buf); } } void stats_write(stats_io_t *stats, const void *pkt, size_t len) { if (stats->file) { - (void) fwrite(pkt, 1, len, stats->file); + (void)fwrite(pkt, 1, len, stats->file); } else { if (stats->buf.sz + len > stats->buf_alloc_sz) { - size_t new_sz = stats->buf_alloc_sz + 64 * 1024; - char *new_ptr = realloc(stats->buf.buf, new_sz); + size_t new_sz = stats->buf_alloc_sz + 64 * 1024; + char *new_ptr = realloc(stats->buf.buf, new_sz); if (new_ptr) { stats->buf_ptr = new_ptr + (stats->buf_ptr - (char *)stats->buf.buf); @@ -117,6 +102,4 @@ void stats_write(stats_io_t *stats, const void *pkt, size_t len) { } } -vpx_fixed_buf_t stats_get(stats_io_t *stats) { - return stats->buf; -} +vpx_fixed_buf_t stats_get(stats_io_t *stats) { return stats->buf; }