FORM  4.1
compress.c
Go to the documentation of this file.
1 
7 /* #[ License : */
8 /*
9  * Copyright (C) 1984-2013 J.A.M. Vermaseren
10  * When using this file you are requested to refer to the publication
11  * J.A.M.Vermaseren "New features of FORM" math-ph/0010025
12  * This is considered a matter of courtesy as the development was paid
13  * for by FOM the Dutch physics granting agency and we would like to
14  * be able to track its scientific use to convince FOM of its value
15  * for the community.
16  *
17  * This file is part of FORM.
18  *
19  * FORM is free software: you can redistribute it and/or modify it under the
20  * terms of the GNU General Public License as published by the Free Software
21  * Foundation, either version 3 of the License, or (at your option) any later
22  * version.
23  *
24  * FORM is distributed in the hope that it will be useful, but WITHOUT ANY
25  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
27  * details.
28  *
29  * You should have received a copy of the GNU General Public License along
30  * with FORM. If not, see <http://www.gnu.org/licenses/>.
31  */
32 /* #] License : */
33 
34 #include "form3.h"
35 
36 #ifdef WITHZLIB
37 /*
38 #define GZIPDEBUG
39 
40  Low level routines for dealing with zlib during sorting and handling
41  the scratch files. Work started 5-sep-2005.
42  The .sor file handling was more or less completed on 8-sep-2005
43  The handling of the scratch files still needs some thinking.
44  Complications are:
45  gzip compression should be per expression, not per buffer.
46  No gzip compression for expressions with a bracket index.
47  Separate decompression buffers for expressions in the rhs.
48  This last one will involve more buffer work and organization.
49  Information about compression should be stored for each expr.
50  (including what method/program was used)
51  Note: Be careful with compression. By far the most compact method
52  is the original problem....
53 
54  #[ Variables :
55 
56  The following variables are to contain the intermediate buffers
57  for the inflation of the various patches in the sort file.
58  There can be up to MaxFpatches (FilePatches in the setup) and hence
59  we can have that many streams simultaneously. We set this up once
60  and only when needed.
61  (in struct A.N or AB[threadnum].N)
62  Bytef **AN.ziobufnum;
63  Bytef *AN.ziobuffers;
64 */
65 
66 /*
67  #] Variables :
68  #[ SetupOutputGZIP :
69 
70  Routine prepares a gzip output stream for the given file.
71 */
72 
73 int SetupOutputGZIP(FILEHANDLE *f)
74 {
75  GETIDENTITY
76 
77  if ( AT.SS != AT.S0 ) return(0);
78  if ( AR.NoCompress == 1 ) return(0);
79  if ( AR.gzipCompress <= 0 ) return(0);
80 
81  if ( f->ziobuffer == 0 ) {
82 /*
83  1: Allocate a struct for the gzip stream:
84 */
85  f->zsp = Malloc1(sizeof(z_stream),"output zstream");
86 /*
87  2: Allocate the output buffer.
88 */
89  f->ziobuffer =
90  (Bytef *)Malloc1(f->ziosize*sizeof(char),"output zbuffer");
91  if ( f->zsp == 0 || f->ziobuffer == 0 ) {
92  MLOCK(ErrorMessageLock);
93  MesCall("SetupOutputGZIP");
94  MUNLOCK(ErrorMessageLock);
95  Terminate(-1);
96  }
97  }
98 /*
99  3: Set the default fields:
100 */
101  f->zsp->zalloc = Z_NULL;
102  f->zsp->zfree = Z_NULL;
103  f->zsp->opaque = Z_NULL;
104 /*
105  4: Set the output space:
106 */
107  f->zsp->next_out = f->ziobuffer;
108  f->zsp->avail_out = f->ziosize;
109  f->zsp->total_out = 0;
110 /*
111  5: Set the input space:
112 */
113  f->zsp->next_in = (Bytef *)(f->PObuffer);
114  f->zsp->avail_in = (Bytef *)(f->POfill) - (Bytef *)(f->PObuffer);
115  f->zsp->total_in = 0;
116 /*
117  6: Initiate the deflation
118 */
119  if ( deflateInit(f->zsp,AR.gzipCompress) != Z_OK ) {
120  MLOCK(ErrorMessageLock);
121  MesPrint("Error from zlib: %s",f->zsp->msg);
122  MesCall("SetupOutputGZIP");
123  MUNLOCK(ErrorMessageLock);
124  Terminate(-1);
125  }
126 
127  return(0);
128 }
129 
130 /*
131  #] SetupOutputGZIP :
132  #[ PutOutputGZIP :
133 
134  Routine is called when the PObuffer of f is full.
135  The contents of it will be compressed and whenever the output buffer
136  f->ziobuffer is full it will be written and the output buffer
137  will be reset.
138  Upon exit the input buffer will be cleared.
139 */
140 
141 int PutOutputGZIP(FILEHANDLE *f)
142 {
143  GETIDENTITY
144  int zerror;
145 /*
146  First set the number of bytes in the input
147 */
148  f->zsp->next_in = (Bytef *)(f->PObuffer);
149  f->zsp->avail_in = (Bytef *)(f->POfill) - (Bytef *)(f->PObuffer);
150  f->zsp->total_in = 0;
151 
152  while ( ( zerror = deflate(f->zsp,Z_NO_FLUSH) ) == Z_OK ) {
153  if ( f->zsp->avail_out == 0 ) {
154 /*
155  ziobuffer is full. Write the output.
156 */
157 #ifdef GZIPDEBUG
158  {
159  char *s = (char *)((UBYTE *)(f->ziobuffer)+f->ziosize);
160  MLOCK(ErrorMessageLock);
161  MesPrint("%wWriting %l bytes at %10p: %d %d %d %d %d"
162  ,f->ziosize,&(f->POposition),s[-5],s[-4],s[-3],s[-2],s[-1]);
163  MUNLOCK(ErrorMessageLock);
164  }
165 #endif
166 #ifdef ALLLOCK
167  LOCK(f->pthreadslock);
168 #endif
169  if ( f == AR.hidefile ) {
170  LOCK(AS.inputslock);
171  }
172  SeekFile(f->handle,&(f->POposition),SEEK_SET);
173  if ( WriteFile(f->handle,(UBYTE *)(f->ziobuffer),f->ziosize)
174  != f->ziosize ) {
175  if ( f == AR.hidefile ) {
176  UNLOCK(AS.inputslock);
177  }
178 #ifdef ALLLOCK
179  UNLOCK(f->pthreadslock);
180 #endif
181  MLOCK(ErrorMessageLock);
182  MesPrint("%wWrite error during compressed sort. Disk full?");
183  MUNLOCK(ErrorMessageLock);
184  return(-1);
185  }
186  if ( f == AR.hidefile ) {
187  UNLOCK(AS.inputslock);
188  }
189 #ifdef ALLLOCK
190  UNLOCK(f->pthreadslock);
191 #endif
192  ADDPOS(f->filesize,f->ziosize);
193  ADDPOS(f->POposition,f->ziosize);
194 #ifdef WITHPTHREADS
195  if ( AS.MasterSort && AC.ThreadSortFileSynch ) {
196  if ( f->handle >= 0 ) SynchFile(f->handle);
197  }
198 #endif
199 /*
200  Reset the output
201 */
202  f->zsp->next_out = f->ziobuffer;
203  f->zsp->avail_out = f->ziosize;
204  f->zsp->total_out = 0;
205  }
206  else if ( f->zsp->avail_in == 0 ) {
207 /*
208  We compressed everything and it sits in ziobuffer. Finish
209 */
210  return(0);
211  }
212  else {
213  MLOCK(ErrorMessageLock);
214  MesPrint("%w avail_in = %d, avail_out = %d.",f->zsp->avail_in,f->zsp->avail_out);
215  MUNLOCK(ErrorMessageLock);
216  break;
217  }
218  }
219  MLOCK(ErrorMessageLock);
220  MesPrint("%wError in gzip handling of output. zerror = %d",zerror);
221  MUNLOCK(ErrorMessageLock);
222  return(-1);
223 }
224 
225 /*
226  #] PutOutputGZIP :
227  #[ FlushOutputGZIP :
228 
229  Routine is called to flush a stream. The compression of the input buffer
230  will be completed and the contents of f->ziobuffer will be written.
231  Both buffers will be cleared.
232 */
233 
234 int FlushOutputGZIP(FILEHANDLE *f)
235 {
236  GETIDENTITY
237  int zerror;
238 /*
239  Set the proper parameters
240 */
241  f->zsp->next_in = (Bytef *)(f->PObuffer);
242  f->zsp->avail_in = (Bytef *)(f->POfill) - (Bytef *)(f->PObuffer);
243  f->zsp->total_in = 0;
244 
245  while ( ( zerror = deflate(f->zsp,Z_FINISH) ) == Z_OK ) {
246  if ( f->zsp->avail_out == 0 ) {
247 /*
248  Write the output
249 */
250 #ifdef GZIPDEBUG
251  MLOCK(ErrorMessageLock);
252  MesPrint("%wWriting %l bytes at %10p",f->ziosize,&(f->POposition));
253  MUNLOCK(ErrorMessageLock);
254 #endif
255 #ifdef ALLLOCK
256  LOCK(f->pthreadslock);
257 #endif
258  if ( f == AR.hidefile ) {
259  UNLOCK(AS.inputslock);
260  }
261  SeekFile(f->handle,&(f->POposition),SEEK_SET);
262  if ( WriteFile(f->handle,(UBYTE *)(f->ziobuffer),f->ziosize)
263  != f->ziosize ) {
264  if ( f == AR.hidefile ) {
265  UNLOCK(AS.inputslock);
266  }
267 #ifdef ALLLOCK
268  UNLOCK(f->pthreadslock);
269 #endif
270  MLOCK(ErrorMessageLock);
271  MesPrint("%wWrite error during compressed sort. Disk full?");
272  MUNLOCK(ErrorMessageLock);
273  return(-1);
274  }
275  if ( f == AR.hidefile ) {
276  UNLOCK(AS.inputslock);
277  }
278 #ifdef ALLLOCK
279  UNLOCK(f->pthreadslock);
280 #endif
281  ADDPOS(f->filesize,f->ziosize);
282  ADDPOS(f->POposition,f->ziosize);
283 #ifdef WITHPTHREADS
284  if ( AS.MasterSort && AC.ThreadSortFileSynch ) {
285  if ( f->handle >= 0 ) SynchFile(f->handle);
286  }
287 #endif
288 /*
289  Reset the output
290 */
291  f->zsp->next_out = f->ziobuffer;
292  f->zsp->avail_out = f->ziosize;
293  f->zsp->total_out = 0;
294  }
295  }
296  if ( zerror == Z_STREAM_END ) {
297 /*
298  Write the output
299 */
300 #ifdef GZIPDEBUG
301  MLOCK(ErrorMessageLock);
302  MesPrint("%wWriting %l bytes at %10p",(LONG)(f->zsp->avail_out),&(f->POposition));
303  MUNLOCK(ErrorMessageLock);
304 #endif
305 #ifdef ALLLOCK
306  LOCK(f->pthreadslock);
307 #endif
308  if ( f == AR.hidefile ) {
309  LOCK(AS.inputslock);
310  }
311  SeekFile(f->handle,&(f->POposition),SEEK_SET);
312  if ( WriteFile(f->handle,(UBYTE *)(f->ziobuffer),f->zsp->total_out)
313  != (LONG)(f->zsp->total_out) ) {
314  if ( f == AR.hidefile ) {
315  UNLOCK(AS.inputslock);
316  }
317 #ifdef ALLLOCK
318  UNLOCK(f->pthreadslock);
319 #endif
320  MLOCK(ErrorMessageLock);
321  MesPrint("%wWrite error during compressed sort. Disk full?");
322  MUNLOCK(ErrorMessageLock);
323  return(-1);
324  }
325  if ( f == AR.hidefile ) {
326  LOCK(AS.inputslock);
327  }
328 #ifdef ALLLOCK
329  UNLOCK(f->pthreadslock);
330 #endif
331  ADDPOS(f->filesize,f->zsp->total_out);
332  ADDPOS(f->POposition,f->zsp->total_out);
333 #ifdef WITHPTHREADS
334  if ( AS.MasterSort && AC.ThreadSortFileSynch ) {
335  if ( f->handle >= 0 ) SynchFile(f->handle);
336  }
337 #endif
338 #ifdef GZIPDEBUG
339  MLOCK(ErrorMessageLock);
340  { char *s = f->ziobuffer+f->zsp->total_out;
341  MesPrint("%w Last bytes written: %d %d %d %d %d",s[-5],s[-4],s[-3],s[-2],s[-1]);
342  }
343  MesPrint("%w Perceived position in FlushOutputGZIP is %10p",&(f->POposition));
344  MUNLOCK(ErrorMessageLock);
345 #endif
346 /*
347  Reset the output
348 */
349  f->zsp->next_out = f->ziobuffer;
350  f->zsp->avail_out = f->ziosize;
351  f->zsp->total_out = 0;
352  if ( ( zerror = deflateEnd(f->zsp) ) == Z_OK ) return(0);
353  MLOCK(ErrorMessageLock);
354  if ( f->zsp->msg ) {
355  MesPrint("%wError in finishing gzip handling of output: %s",f->zsp->msg);
356  }
357  else {
358  MesPrint("%wError in finishing gzip handling of output.");
359  }
360  MUNLOCK(ErrorMessageLock);
361  }
362  else {
363  MLOCK(ErrorMessageLock);
364  MesPrint("%wError in gzip handling of output.");
365  MUNLOCK(ErrorMessageLock);
366  }
367  return(-1);
368 }
369 
370 /*
371  #] FlushOutputGZIP :
372  #[ SetupAllInputGZIP :
373 
374  Routine prepares all gzip input streams for a merge.
375 
376  Problem (29-may-2008): If we never use GZIP compression, this routine
377  will still allocate the array space. This is an enormous amount!
378  It places an effective restriction on the value of SortIOsize
379 */
380 
381 int SetupAllInputGZIP(SORTING *S)
382 {
383  GETIDENTITY
384  int i, NumberOpened = 0;
385  z_streamp zsp;
386 /*
387  This code was added 29-may-2008 by JV to prevent further processing if
388  there is no compression at all (usually).
389 */
390  for ( i = 0; i < S->inNum; i++ ) {
391  if ( S->fpincompressed[i] ) break;
392  }
393  if ( i >= S->inNum ) return(0);
394 
395  if ( S->zsparray == 0 ) {
396  S->zsparray = (z_streamp)Malloc1(sizeof(z_stream)*S->MaxFpatches,"input zstreams");
397  if ( S->zsparray == 0 ) {
398  MLOCK(ErrorMessageLock);
399  MesCall("SetupAllInputGZIP");
400  MUNLOCK(ErrorMessageLock);
401  Terminate(-1);
402  }
403  AN.ziobuffers = (Bytef *)Malloc1(S->MaxFpatches*S->file.ziosize*sizeof(Bytef),"input raw buffers");
404 /*
405  This seems to be one of the really stupid errors:
406  We allocate way too much space. Way way way too much.
407  AN.ziobufnum = (Bytef **)Malloc1(S->MaxFpatches*S->file.ziosize*sizeof(Bytef *),"input raw pointers");
408 */
409  AN.ziobufnum = (Bytef **)Malloc1(S->MaxFpatches*sizeof(Bytef *),"input raw pointers");
410  if ( AN.ziobuffers == 0 || AN.ziobufnum == 0 ) {
411  MLOCK(ErrorMessageLock);
412  MesCall("SetupAllInputGZIP");
413  MUNLOCK(ErrorMessageLock);
414  Terminate(-1);
415  }
416  for ( i = 0 ; i < S->MaxFpatches; i++ ) {
417  AN.ziobufnum[i] = AN.ziobuffers + i * S->file.ziosize;
418  }
419  }
420  for ( i = 0; i < S->inNum; i++ ) {
421 #ifdef GZIPDEBUG
422  MLOCK(ErrorMessageLock);
423  MesPrint("%wPreparing z-stream %d with compression %d",i,S->fpincompressed[i]);
424  MUNLOCK(ErrorMessageLock);
425 #endif
426  if ( S->fpincompressed[i] ) {
427  zsp = &(S->zsparray[i]);
428 /*
429  1: Set the default fields:
430 */
431  zsp->zalloc = Z_NULL;
432  zsp->zfree = Z_NULL;
433  zsp->opaque = Z_NULL;
434 /*
435  2: Set the output space:
436 */
437  zsp->next_out = Z_NULL;
438  zsp->avail_out = 0;
439  zsp->total_out = 0;
440 /*
441  3: Set the input space temporarily:
442 */
443  zsp->next_in = Z_NULL;
444  zsp->avail_in = 0;
445  zsp->total_in = 0;
446 /*
447  4: Initiate the inflation
448 */
449  if ( inflateInit(zsp) != Z_OK ) {
450  MLOCK(ErrorMessageLock);
451  if ( zsp->msg ) MesPrint("%wError from inflateInit: %s",zsp->msg);
452  else MesPrint("%wError from inflateInit");
453  MesCall("SetupAllInputGZIP");
454  MUNLOCK(ErrorMessageLock);
455  Terminate(-1);
456  }
457  NumberOpened++;
458  }
459  }
460  return(NumberOpened);
461 }
462 
463 /*
464  #] SetupAllInputGZIP :
465  #[ FillInputGZIP :
466 
467  Routine is called when we need new input in the specified buffer.
468  This buffer is used for the output and we keep reading and uncompressing
469  input till either this buffer is full or the input stream is finished.
470  The return value is the number of bytes in the buffer.
471 */
472 
473 LONG FillInputGZIP(FILEHANDLE *f, POSITION *position, UBYTE *buffer, LONG buffersize, int numstream)
474 {
475  GETIDENTITY
476  int zerror;
477  LONG readsize, toread;
478  SORTING *S = AT.SS;
479  z_streamp zsp;
480  POSITION pos;
481  if ( S->fpincompressed[numstream] ) {
482  zsp = &(S->zsparray[numstream]);
483  zsp->next_out = (Bytef *)buffer;
484  zsp->avail_out = buffersize;
485  zsp->total_out = 0;
486  if ( zsp->avail_in == 0 ) {
487 /*
488  First loading of the input
489 */
490  if ( ISGEPOSINC(S->fPatchesStop[numstream],*position,f->ziosize) ) {
491  toread = f->ziosize;
492  }
493  else {
494  DIFPOS(pos,S->fPatchesStop[numstream],*position);
495  toread = (LONG)(BASEPOSITION(pos));
496  }
497  if ( toread > 0 ) {
498 #ifdef GZIPDEBUG
499  MLOCK(ErrorMessageLock);
500  MesPrint("%w-+Reading %l bytes in stream %d at position %10p; stop at %10p",toread,numstream,position,&(S->fPatchesStop[numstream]));
501  MUNLOCK(ErrorMessageLock);
502 #endif
503 #ifdef ALLLOCK
504  LOCK(f->pthreadslock);
505 #endif
506  SeekFile(f->handle,position,SEEK_SET);
507  readsize = ReadFile(f->handle,(UBYTE *)(AN.ziobufnum[numstream]),toread);
508  SeekFile(f->handle,position,SEEK_CUR);
509 #ifdef ALLLOCK
510  UNLOCK(f->pthreadslock);
511 #endif
512 #ifdef GZIPDEBUG
513  MLOCK(ErrorMessageLock);
514  { char *s = AN.ziobufnum[numstream]+readsize;
515  MesPrint("%w read: %l +Last bytes read: %d %d %d %d %d in %s, newpos = %10p",readsize,s[-5],s[-4],s[-3],s[-2],s[-1],f->name,position);
516  }
517  MUNLOCK(ErrorMessageLock);
518 #endif
519  if ( readsize == 0 ) {
520  zsp->next_in = AN.ziobufnum[numstream];
521  zsp->avail_in = f->ziosize;
522  zsp->total_in = 0;
523  return(zsp->total_out);
524  }
525  if ( readsize < 0 ) {
526  MLOCK(ErrorMessageLock);
527  MesPrint("%wFillInputGZIP: Read error during compressed sort.");
528  MUNLOCK(ErrorMessageLock);
529  return(-1);
530  }
531  ADDPOS(f->filesize,readsize);
532  ADDPOS(f->POposition,readsize);
533 /*
534  Set the input
535 */
536  zsp->next_in = AN.ziobufnum[numstream];
537  zsp->avail_in = readsize;
538  zsp->total_in = 0;
539  }
540  }
541  while ( ( zerror = inflate(zsp,Z_NO_FLUSH) ) == Z_OK ) {
542  if ( zsp->avail_out == 0 ) {
543 /*
544  Finish
545 */
546  return((LONG)(zsp->total_out));
547  }
548  if ( zsp->avail_in == 0 ) {
549 
550  if ( ISEQUALPOS(S->fPatchesStop[numstream],*position) ) {
551 /*
552  We finished this stream. Try to terminate.
553 */
554  if ( ( zerror = inflate(zsp,Z_SYNC_FLUSH) ) == Z_OK ) {
555  return((LONG)(zsp->total_out));
556  }
557  else
558  break;
559 /*
560 #ifdef GZIPDEBUG
561  MLOCK(ErrorMessageLock);
562  MesPrint("%wClosing stream %d",numstream);
563 #endif
564  readsize = zsp->total_out;
565 #ifdef GZIPDEBUG
566  if ( readsize > 0 ) {
567  WORD *s = (WORD *)(buffer+zsp->total_out);
568  MesPrint("%w Last words: %d %d %d %d %d",s[-5],s[-4],s[-3],s[-2],s[-1]);
569  }
570  else {
571  MesPrint("%w No words");
572  }
573  MUNLOCK(ErrorMessageLock);
574 #endif
575  if ( inflateEnd(zsp) == Z_OK ) return(readsize);
576  break;
577 */
578  }
579 /*
580  Read more input
581 */
582 #ifdef GZIPDEBUG
583  if ( numstream == 0 ) {
584  MLOCK(ErrorMessageLock);
585  MesPrint("%wWant to read in stream 0 at position %10p",position);
586  MUNLOCK(ErrorMessageLock);
587  }
588 #endif
589  if ( ISGEPOSINC(S->fPatchesStop[numstream],*position,f->ziosize) ) {
590  toread = f->ziosize;
591  }
592  else {
593  DIFPOS(pos,S->fPatchesStop[numstream],*position);
594  toread = (LONG)(BASEPOSITION(pos));
595  }
596 #ifdef GZIPDEBUG
597  MLOCK(ErrorMessageLock);
598  MesPrint("%w--Reading %l bytes in stream %d at position %10p",toread,numstream,position);
599  MUNLOCK(ErrorMessageLock);
600 #endif
601 #ifdef ALLLOCK
602  LOCK(f->pthreadslock);
603 #endif
604  SeekFile(f->handle,position,SEEK_SET);
605  readsize = ReadFile(f->handle,(UBYTE *)(AN.ziobufnum[numstream]),toread);
606  SeekFile(f->handle,position,SEEK_CUR);
607 #ifdef ALLLOCK
608  UNLOCK(f->pthreadslock);
609 #endif
610 #ifdef GZIPDEBUG
611  MLOCK(ErrorMessageLock);
612  { char *s = AN.ziobufnum[numstream]+readsize;
613  MesPrint("%w Last bytes read: %d %d %d %d %d",s[-5],s[-4],s[-3],s[-2],s[-1]);
614  }
615  MUNLOCK(ErrorMessageLock);
616 #endif
617  if ( readsize == 0 ) {
618  zsp->next_in = AN.ziobufnum[numstream];
619  zsp->avail_in = f->ziosize;
620  zsp->total_in = 0;
621  return(zsp->total_out);
622  }
623  if ( readsize < 0 ) {
624  MLOCK(ErrorMessageLock);
625  MesPrint("%wFillInputGZIP: Read error during compressed sort.");
626  MUNLOCK(ErrorMessageLock);
627  return(-1);
628  }
629  ADDPOS(f->filesize,readsize);
630  ADDPOS(f->POposition,readsize);
631 /*
632  Reset the input
633 */
634  zsp->next_in = AN.ziobufnum[numstream];
635  zsp->avail_in = readsize;
636  zsp->total_in = 0;
637  }
638  else {
639  break;
640  }
641  }
642 #ifdef GZIPDEBUG
643  MLOCK(ErrorMessageLock);
644  MesPrint("%w zerror = %d in stream %d. At position %10p",zerror,numstream,position);
645  MUNLOCK(ErrorMessageLock);
646 #endif
647  if ( zerror == Z_STREAM_END ) {
648 /*
649  Reset the input
650 */
651  zsp->next_in = Z_NULL;
652  zsp->avail_in = 0;
653  zsp->total_in = 0;
654 /*
655  Make the final call and finish
656 */
657 #ifdef GZIPDEBUG
658  MLOCK(ErrorMessageLock);
659  MesPrint("%wClosing stream %d",numstream);
660 #endif
661  readsize = zsp->total_out;
662 #ifdef GZIPDEBUG
663  if ( readsize > 0 ) {
664  WORD *s = (WORD *)(buffer+zsp->total_out);
665  MesPrint("%w -Last words: %d %d %d %d %d",s[-5],s[-4],s[-3],s[-2],s[-1]);
666  }
667  else {
668  MesPrint("%w No words");
669  }
670  MUNLOCK(ErrorMessageLock);
671 #endif
672  if ( inflateEnd(zsp) == Z_OK ) return(readsize);
673  }
674 
675  MLOCK(ErrorMessageLock);
676  MesPrint("%wFillInputGZIP: Error in gzip handling of input.");
677  MUNLOCK(ErrorMessageLock);
678  return(-1);
679  }
680  else {
681 #ifdef GZIPDEBUG
682  MLOCK(ErrorMessageLock);
683  MesPrint("%w++Reading %l bytes at position %10p",buffersize,position);
684  MUNLOCK(ErrorMessageLock);
685 #endif
686 #ifdef ALLLOCK
687  LOCK(f->pthreadslock);
688 #endif
689  SeekFile(f->handle,position,SEEK_SET);
690  readsize = ReadFile(f->handle,buffer,buffersize);
691  SeekFile(f->handle,position,SEEK_CUR);
692 #ifdef ALLLOCK
693  UNLOCK(f->pthreadslock);
694 #endif
695  if ( readsize < 0 ) {
696  MLOCK(ErrorMessageLock);
697  MesPrint("%wFillInputGZIP: Read error during uncompressed sort.");
698  MesPrint("%w++Reading %l bytes at position %10p",buffersize,position);
699  MUNLOCK(ErrorMessageLock);
700  }
701  return(readsize);
702  }
703 }
704 
705 /*
706  #] FillInputGZIP :
707 */
708 #endif
Definition: structs.h:618
Definition: structs.h:1028
int handle
Definition: structs.h:646