Skip to content

Commit 44b08a4

Browse files
caryrsteveicarus
authored andcommitted
Update fstapi.c to latest from gtkwave 3.3.10
1 parent 30fa8f6 commit 44b08a4

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

vpi/fstapi.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#define FST_DO_MISALIGNED_OPS
3939
#endif
4040

41+
#if defined(__APPLE__) && defined(__MACH__)
42+
#define FST_MACOSX
43+
#endif
44+
4145

4246
/***********************/
4347
/*** ***/
@@ -2186,8 +2190,7 @@ if(!xc->fh)
21862190
off_t offs_cache = ftello(xc->f);
21872191
char *fnam = malloc(strlen(xc->filename) + 6 + 16 + 32 + 1);
21882192
unsigned char *mem = malloc(FST_GZIO_LEN);
2189-
off_t hl;
2190-
uint64_t uclen;
2193+
off_t hl, uclen;
21912194
gzFile zhandle;
21922195
int zfd;
21932196

@@ -2223,14 +2226,22 @@ if(!xc->fh)
22232226

22242227
for(hl = 0; hl < uclen; hl += FST_GZIO_LEN)
22252228
{
2226-
unsigned len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl);
2227-
int gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */
2229+
size_t len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl);
2230+
size_t gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */
2231+
size_t fwlen;
2232+
22282233
if(gzreadlen != len)
22292234
{
22302235
pass_status = 0;
22312236
break;
22322237
}
2233-
fstFwrite(mem, len, 1, xc->fh);
2238+
2239+
fwlen = fstFwrite(mem, len, 1, xc->fh);
2240+
if(fwlen != 1)
2241+
{
2242+
pass_status = 0;
2243+
break;
2244+
}
22342245
}
22352246
gzclose(zhandle);
22362247
free(mem);
@@ -2625,6 +2636,10 @@ if(sectype == FST_BL_ZWRAPPER)
26252636
if(!fcomp) return(0);
26262637
}
26272638

2639+
#if defined(FST_MACOSX)
2640+
setvbuf(fcomp, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
2641+
#endif
2642+
26282643
#ifdef __MINGW32__
26292644
setvbuf(fcomp, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
26302645
xc->filename_unpacked = hf;
@@ -2646,13 +2661,20 @@ if(sectype == FST_BL_ZWRAPPER)
26462661
for(offpnt = 0; offpnt < uclen; offpnt += FST_GZIO_LEN)
26472662
{
26482663
size_t this_len = ((uclen - offpnt) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - offpnt);
2649-
int gzreadlen = gzread(zhandle, gz_membuf, this_len);
2664+
size_t gzreadlen = gzread(zhandle, gz_membuf, this_len);
2665+
size_t fwlen;
2666+
26502667
if(gzreadlen != this_len)
26512668
{
26522669
gzread_pass_status = 0;
26532670
break;
26542671
}
2655-
fstFwrite(gz_membuf, this_len, 1, fcomp);
2672+
fwlen = fstFwrite(gz_membuf, this_len, 1, fcomp);
2673+
if(fwlen != 1)
2674+
{
2675+
gzread_pass_status = 0;
2676+
break;
2677+
}
26562678
}
26572679
gzclose(zhandle);
26582680
}
@@ -2888,7 +2910,7 @@ if((!nam)||(!(xc->f=fopen(nam, "rb"))))
28882910
char *hf = calloc(1, flen + 6);
28892911
int rc;
28902912

2891-
#ifdef __MINGW32__
2913+
#if defined(__MINGW32__) || defined(FST_MACOSX)
28922914
setvbuf(xc->f, (char *)NULL, _IONBF, 0); /* keeps gzip from acting weird in tandem with fopen */
28932915
#endif
28942916

0 commit comments

Comments
 (0)