From 3c2e4a3a7be2f092d6d489f521736896e64c7e03 Mon Sep 17 00:00:00 2001 From: Cary R Date: Fri, 16 Jul 2010 11:24:35 -0700 Subject: [PATCH] Update fstapi.c to latest from gtkwave 3.3.10 (cherry picked from commit 44b08a4630224d18855caca270ed48998b0ced5c) --- vpi/fstapi.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/vpi/fstapi.c b/vpi/fstapi.c index 2e3958e60..bbb32e737 100644 --- a/vpi/fstapi.c +++ b/vpi/fstapi.c @@ -38,6 +38,10 @@ #define FST_DO_MISALIGNED_OPS #endif +#if defined(__APPLE__) && defined(__MACH__) +#define FST_MACOSX +#endif + /***********************/ /*** ***/ @@ -2186,8 +2190,7 @@ if(!xc->fh) off_t offs_cache = ftello(xc->f); char *fnam = malloc(strlen(xc->filename) + 6 + 16 + 32 + 1); unsigned char *mem = malloc(FST_GZIO_LEN); - off_t hl; - uint64_t uclen; + off_t hl, uclen; gzFile zhandle; int zfd; @@ -2223,14 +2226,22 @@ if(!xc->fh) for(hl = 0; hl < uclen; hl += FST_GZIO_LEN) { - unsigned len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl); - int gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */ + size_t len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl); + size_t gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */ + size_t fwlen; + if(gzreadlen != len) { pass_status = 0; break; } - fstFwrite(mem, len, 1, xc->fh); + + fwlen = fstFwrite(mem, len, 1, xc->fh); + if(fwlen != 1) + { + pass_status = 0; + break; + } } gzclose(zhandle); free(mem); @@ -2625,6 +2636,10 @@ if(sectype == FST_BL_ZWRAPPER) if(!fcomp) return(0); } +#if defined(FST_MACOSX) + setvbuf(fcomp, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */ +#endif + #ifdef __MINGW32__ setvbuf(fcomp, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */ xc->filename_unpacked = hf; @@ -2646,13 +2661,20 @@ if(sectype == FST_BL_ZWRAPPER) for(offpnt = 0; offpnt < uclen; offpnt += FST_GZIO_LEN) { size_t this_len = ((uclen - offpnt) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - offpnt); - int gzreadlen = gzread(zhandle, gz_membuf, this_len); + size_t gzreadlen = gzread(zhandle, gz_membuf, this_len); + size_t fwlen; + if(gzreadlen != this_len) { gzread_pass_status = 0; break; } - fstFwrite(gz_membuf, this_len, 1, fcomp); + fwlen = fstFwrite(gz_membuf, this_len, 1, fcomp); + if(fwlen != 1) + { + gzread_pass_status = 0; + break; + } } gzclose(zhandle); } @@ -2888,7 +2910,7 @@ if((!nam)||(!(xc->f=fopen(nam, "rb")))) char *hf = calloc(1, flen + 6); int rc; -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(FST_MACOSX) setvbuf(xc->f, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */ #endif