~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/azio.c

Merged vcol stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
/* @(#) $Id$ */
13
13
 
14
 
#include "config.h"
15
 
 
16
14
#include "azio.h"
17
15
 
18
 
#include <fcntl.h>
 
16
#include <stdio.h>
 
17
#include <string.h>
 
18
#include <assert.h>
19
19
#include <unistd.h>
20
20
 
21
 
#include <cstdio>
22
 
#include <cstring>
23
 
#include <cstdlib>
24
 
#include <cassert>
25
 
 
26
 
using namespace drizzled;
27
 
 
28
21
static int const az_magic[3] = {0xfe, 0x03, 0x01}; /* az magic header */
29
22
 
 
23
/* gzip flag unsigned char */
 
24
#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
 
25
#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
 
26
#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
 
27
#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
 
28
#define COMMENT      0x10 /* bit 4 set: file comment present */
 
29
#define RESERVED     0xE0 /* bits 5..7: reserved */
 
30
 
30
31
static unsigned int azwrite(azio_stream *s, void *buf, unsigned int len);
31
32
static int azrewind (azio_stream *s);
32
33
static unsigned int azio_enable_aio(azio_stream *s);
33
34
static int do_flush(azio_stream *file, int flush);
34
35
static int    get_byte(azio_stream *s);
35
36
static void   check_header(azio_stream *s);
36
 
static int write_header(azio_stream *s);
 
37
static void write_header(azio_stream *s);
37
38
static int    destroy(azio_stream *s);
38
39
static void putLong(azio_stream *s, uLong x);
39
40
static uLong  getLong(azio_stream *s);
43
44
static void do_aio_cleanup(azio_stream *s);
44
45
#endif
45
46
 
46
 
extern "C" pthread_handler_t run_task(void *p);
47
 
 
48
 
extern "C" pthread_handler_t run_task(void *p)
 
47
static pthread_handler_t run_task(void *p)
49
48
{
50
49
  int fd;
51
50
  char *buffer;
52
51
  size_t offset;
53
 
  azio_stream *s= (azio_stream *)p;
 
52
  azio_stream *s= (azio_stream *)p;  
 
53
 
 
54
  my_thread_init();
54
55
 
55
56
  while (1)
56
57
  {
61
62
    }
62
63
    offset= s->container.offset;
63
64
    fd= s->container.fd;
64
 
    buffer= (char *)s->container.buffer;
 
65
    buffer= s->container.buffer;
65
66
    pthread_mutex_unlock(&s->container.thresh_mutex);
66
67
 
67
68
    if (s->container.ready == AZ_THREAD_DEAD)
75
76
    pthread_mutex_unlock(&s->container.thresh_mutex);
76
77
  }
77
78
 
 
79
  my_thread_end();
 
80
 
78
81
  return 0;
79
82
}
80
83
 
81
84
static void azio_kill(azio_stream *s)
82
85
{
83
86
  pthread_mutex_lock(&s->container.thresh_mutex);
84
 
  s->container.ready= AZ_THREAD_DEAD;
 
87
  s->container.ready= AZ_THREAD_DEAD; 
85
88
  pthread_mutex_unlock(&s->container.thresh_mutex);
86
89
 
87
90
  pthread_cond_signal(&s->container.threshhold);
88
 
  pthread_join(s->container.mainthread, NULL);
 
91
  pthread_join(s->container.mainthread, (void *)NULL);
89
92
}
90
93
 
91
94
static size_t azio_return(azio_stream *s)
123
126
  pthread_attr_init(&attr);
124
127
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
125
128
 
126
 
  s->container.ready= AZ_THREAD_FINISHED;
 
129
  s->container.ready= AZ_THREAD_FINISHED; 
127
130
 
128
131
  /* If we don't create a thread, signal the caller */
129
132
  if (pthread_create(&s->container.mainthread, &attr, run_task,
138
141
static int azio_read(azio_stream *s)
139
142
{
140
143
  pthread_mutex_lock(&s->container.thresh_mutex);
141
 
  s->container.ready= AZ_THREAD_ACTIVE;
 
144
  s->container.ready= AZ_THREAD_ACTIVE; 
142
145
  pthread_mutex_unlock(&s->container.thresh_mutex);
143
146
  pthread_cond_broadcast(&s->container.threshhold);
144
147
 
159
162
  int err;
160
163
  int level = Z_DEFAULT_COMPRESSION ; /* compression level */
161
164
  int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
162
 
  int fd= -1;
 
165
  File fd= -1;
163
166
 
164
167
  memset(s, 0, sizeof(azio_stream));
165
168
 
184
187
  s->method= method;
185
188
 
186
189
  /*
187
 
    We do our own version of append by nature.
 
190
    We do our own version of append by nature. 
188
191
    We must always have write access to take card of the header.
189
192
  */
190
193
  assert(Flags | O_APPEND);
191
194
  assert(Flags | O_WRONLY);
192
195
 
193
 
  if (Flags & O_RDWR)
 
196
  if (Flags & O_RDWR) 
194
197
    s->mode = 'w';
195
198
 
196
 
  if (s->mode == 'w')
 
199
  if (s->mode == 'w') 
197
200
  {
198
201
    err = deflateInit2(&(s->stream), level,
199
202
                       Z_DEFLATED, -MAX_WBITS, 8, strategy);
225
228
  s->stream.avail_out = AZ_BUFSIZE_WRITE;
226
229
 
227
230
  errno = 0;
228
 
  s->file = fd < 0 ? internal::my_open(path, Flags, MYF(0)) : fd;
 
231
  s->file = fd < 0 ? my_open(path, Flags, MYF(0)) : fd;
229
232
#ifdef AZIO_AIO
230
233
  s->container.fd= s->file;
231
234
#endif
232
235
 
233
 
  if (s->file < 0 )
 
236
  if (s->file < 0 ) 
234
237
  {
235
238
    destroy(s);
236
239
    return Z_NULL;
237
240
  }
238
241
 
239
 
  if (Flags & O_CREAT || Flags & O_TRUNC)
 
242
  if (Flags & O_CREAT || Flags & O_TRUNC) 
240
243
  {
241
244
    s->rows= 0;
242
245
    s->forced_flushes= 0;
250
253
    s->frm_length= 0;
251
254
    s->dirty= 1; /* We create the file dirty */
252
255
    s->start = AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
253
 
    if(write_header(s))
254
 
      return Z_NULL;
255
 
    s->pos= (size_t)lseek(s->file, 0, SEEK_END);
 
256
    write_header(s);
 
257
    s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
256
258
  }
257
 
  else if (s->mode == 'w')
 
259
  else if (s->mode == 'w') 
258
260
  {
259
261
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
260
 
    const ssize_t read_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
261
 
    if(pread(s->file, buffer, read_size, 0) < read_size)
262
 
      return Z_NULL;
 
262
    pread(s->file, buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
263
263
    read_header(s, buffer);
264
 
    s->pos= (size_t)lseek(s->file, 0, SEEK_END);
 
264
    s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
265
265
  }
266
266
  else
267
267
  {
282
282
}
283
283
 
284
284
 
285
 
int write_header(azio_stream *s)
 
285
void write_header(azio_stream *s)
286
286
{
287
287
  char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
288
288
  char *ptr= buffer;
313
313
  int8store(ptr + AZ_AUTOINCREMENT_POS, (uint64_t)s->auto_increment); /* Start of Data Block Index Block */
314
314
  int4store(ptr+ AZ_LONGEST_POS , s->longest_row); /* Longest row */
315
315
  int4store(ptr+ AZ_SHORTEST_POS, s->shortest_row); /* Shorest row */
316
 
  int4store(ptr+ AZ_FRM_POS,
 
316
  int4store(ptr+ AZ_FRM_POS, 
317
317
            AZHEADER_SIZE + AZMETA_BUFFER_SIZE); /* FRM position */
318
318
  *(ptr + AZ_DIRTY_POS)= (unsigned char)s->dirty; /* Start of Data Block Index Block */
319
319
 
320
320
  /* Always begin at the begining, and end there as well */
321
 
  const ssize_t write_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
322
 
  if(pwrite(s->file, (unsigned char*) buffer, write_size, 0)!=write_size)
323
 
    return -1;
324
 
 
325
 
  return 0;
 
321
  pwrite(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
326
322
}
327
323
 
328
324
/* ===========================================================================
330
326
  for end of file.
331
327
  IN assertion: the stream s has been sucessfully opened for reading.
332
328
*/
333
 
int get_byte(azio_stream *s)
 
329
int get_byte(s)
 
330
  azio_stream *s;
334
331
{
335
332
  if (s->z_eof) return EOF;
336
 
  if (s->stream.avail_in == 0)
 
333
  if (s->stream.avail_in == 0) 
337
334
  {
338
335
    errno = 0;
339
 
    if (s->stream.avail_in == 0)
 
336
    if (s->stream.avail_in == 0) 
340
337
    {
341
338
      s->z_eof = 1;
342
339
      return EOF;
428
425
 * Cleanup then free the given azio_stream. Return a zlib error code.
429
426
 Try freeing in the reverse order of allocations.
430
427
 */
431
 
int destroy (azio_stream *s)
 
428
int destroy (s)
 
429
  azio_stream *s;
432
430
{
433
431
  int err = Z_OK;
434
432
 
435
 
  if (s->stream.state != NULL)
 
433
  if (s->stream.state != NULL) 
436
434
  {
437
 
    if (s->mode == 'w')
 
435
    if (s->mode == 'w') 
438
436
    {
439
437
      err = deflateEnd(&(s->stream));
440
 
      internal::my_sync(s->file, MYF(0));
 
438
      my_sync(s->file, MYF(0));
441
439
    }
442
 
    else if (s->mode == 'r')
 
440
    else if (s->mode == 'r') 
443
441
      err = inflateEnd(&(s->stream));
444
442
  }
445
443
 
446
444
  do_aio_cleanup(s);
447
445
 
448
 
  if (s->file > 0 && internal::my_close(s->file, MYF(0)))
 
446
  if (s->file > 0 && my_close(s->file, MYF(0))) 
449
447
      err = Z_ERRNO;
450
448
 
451
449
  s->file= -1;
459
457
  Reads the given number of uncompressed bytes from the compressed file.
460
458
  azread returns the number of bytes actually read (0 for end of file).
461
459
*/
462
 
/*
463
 
   This function is legacy, do not use.
464
 
 
465
 
     Reads the given number of uncompressed bytes from the compressed file.
466
 
   If the input file was not in gzip format, gzread copies the given number
467
 
   of bytes into the buffer.
468
 
     gzread returns the number of uncompressed bytes actually read (0 for
469
 
   end of file, -1 for error).
470
 
*/
471
 
static unsigned int azread_internal( azio_stream *s, voidp buf, unsigned int len, int *error)
 
460
unsigned int azread_internal( azio_stream *s, voidp buf, unsigned int len, int *error)
472
461
{
473
462
  Bytef *start = (Bytef*)buf; /* starting point for crc computation */
474
463
  Byte  *next_out; /* == stream.next_out but not forced far (for MSDOS) */
475
464
  *error= 0;
476
465
 
477
466
  if (s->mode != 'r')
478
 
  {
 
467
  { 
479
468
    *error= Z_STREAM_ERROR;
480
469
    return 0;
481
470
  }
482
471
 
483
472
  if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO)
484
 
  {
 
473
  { 
485
474
    *error= s->z_err;
486
475
    return 0;
487
476
  }
488
477
 
489
478
  if (s->z_err == Z_STREAM_END)  /* EOF */
490
 
  {
 
479
  { 
491
480
    return 0;
492
481
  }
493
482
 
504
493
    start++;
505
494
    if (s->last) {
506
495
      s->z_err = Z_STREAM_END;
507
 
      {
 
496
      { 
508
497
        return 1;
509
498
      }
510
499
    }
516
505
 
517
506
      errno = 0;
518
507
      get_block(s);
519
 
      if (s->stream.avail_in == 0)
 
508
      if (s->stream.avail_in == 0) 
520
509
      {
521
510
        s->z_eof = 1;
522
511
      }
542
531
         * Check for such files:
543
532
       */
544
533
        check_header(s);
545
 
        if (s->z_err == Z_OK)
 
534
        if (s->z_err == Z_OK) 
546
535
        {
547
536
          inflateReset(&(s->stream));
548
537
          s->crc = crc32(0L, Z_NULL, 0);
565
554
}
566
555
 
567
556
/* ===========================================================================
568
 
  Experimental Interface. We abstract out a concecpt of rows
 
557
  Experimental Interface. We abstract out a concecpt of rows 
569
558
*/
570
559
size_t azwrite_row(azio_stream *s, void *buf, unsigned int len)
571
560
{
599
588
  size_t read;
600
589
 
601
590
  read= azread_internal(s, buffer, sizeof(unsigned int), error);
602
 
 
 
591
  
603
592
  /* On error the return value will be zero as well */
604
593
  if (read == 0)
605
594
    return read;
608
597
  new_ptr= (char *)realloc(s->row_ptr, (sizeof(char) * row_length));
609
598
 
610
599
  if (!new_ptr)
611
 
    return SIZE_MAX;
 
600
    return -1;
612
601
 
613
602
  s->row_ptr= new_ptr;
614
603
 
628
617
  s->stream.next_in = (Bytef*)buf;
629
618
  s->stream.avail_in = len;
630
619
 
631
 
  while (s->stream.avail_in != 0)
 
620
  while (s->stream.avail_in != 0) 
632
621
  {
633
 
    if (s->stream.avail_out == 0)
 
622
    if (s->stream.avail_out == 0) 
634
623
    {
635
624
 
636
625
      s->stream.next_out = s->outbuf;
637
 
      if (pwrite(s->file, (unsigned char *)s->outbuf, AZ_BUFSIZE_WRITE, s->pos) != AZ_BUFSIZE_WRITE)
 
626
      if (pwrite(s->file, (unsigned char *)s->outbuf, AZ_BUFSIZE_WRITE, s->pos) != AZ_BUFSIZE_WRITE) 
638
627
      {
639
628
        s->z_err = Z_ERRNO;
640
629
        break;
669
658
 
670
659
  s->stream.avail_in = 0; /* should be zero already anyway */
671
660
 
672
 
  for (;;)
 
661
  for (;;) 
673
662
  {
674
663
    len = AZ_BUFSIZE_WRITE - s->stream.avail_out;
675
664
 
676
 
    if (len != 0)
 
665
    if (len != 0) 
677
666
    {
678
 
      if ((uInt)pwrite(s->file, (unsigned char *)s->outbuf, len, s->pos) != len)
 
667
      if ((uInt)pwrite(s->file, (unsigned char *)s->outbuf, len, s->pos) != len) 
679
668
      {
680
669
        s->z_err = Z_ERRNO;
681
670
        assert(0);
707
696
  else
708
697
    s->dirty= AZ_STATE_SAVED; /* Mark it clean, we should be good now */
709
698
 
710
 
  afterwrite_pos= (size_t)lseek(s->file, 0, SEEK_CUR);
711
 
  if(write_header(s))
712
 
    return Z_ERRNO;
 
699
  afterwrite_pos= (size_t)my_tell(s->file, MYF(0));
 
700
  write_header(s);
713
701
 
714
702
  return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
715
703
}
733
721
  s->method= AZ_METHOD_BLOCK;
734
722
}
735
723
 
736
 
int ZEXPORT azflush (azio_stream *s,int flush)
 
724
int ZEXPORT azflush (s, flush)
 
725
  azio_stream *s;
 
726
  int flush;
737
727
{
738
728
  int err;
739
729
 
740
 
  if (s->mode == 'r')
 
730
  if (s->mode == 'r') 
741
731
  {
742
732
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
743
 
    const ssize_t read_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
744
 
    if(pread(s->file, (unsigned char*) buffer, read_size, 0)!=read_size)
745
 
      return Z_ERRNO;
 
733
    pread(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
746
734
    read_header(s, buffer); /* skip the .az header */
747
735
    azrewind(s);
748
736
 
754
742
    err= do_flush(s, flush);
755
743
 
756
744
    if (err) return err;
757
 
    internal::my_sync(s->file, MYF(0));
 
745
    my_sync(s->file, MYF(0));
758
746
    return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
759
747
  }
760
748
}
789
777
/* ===========================================================================
790
778
  Rewinds input file.
791
779
*/
792
 
int azrewind (azio_stream *s)
 
780
int azrewind (s)
 
781
  azio_stream *s;
793
782
{
794
783
  if (s == NULL || s->mode != 'r') return -1;
795
784
 
818
807
  SEEK_END is not implemented, returns error.
819
808
  In this version of the library, azseek can be extremely slow.
820
809
*/
821
 
size_t azseek (azio_stream *s, size_t offset, int whence)
 
810
size_t azseek (s, offset, whence)
 
811
  azio_stream *s;
 
812
  size_t offset;
 
813
  int whence;
822
814
{
823
815
 
824
816
  if (s == NULL || whence == SEEK_END ||
825
817
      s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
826
 
    return SIZE_MAX;
 
818
    return -1L;
827
819
  }
828
820
 
829
 
  if (s->mode == 'w')
 
821
  if (s->mode == 'w') 
830
822
  {
831
 
    if (whence == SEEK_SET)
 
823
    if (whence == SEEK_SET) 
832
824
      offset -= s->in;
833
825
 
834
826
    /* At this point, offset is the number of zero bytes to write. */
835
827
    /* There was a zmemzero here if inbuf was null -Brian */
836
 
    while (offset > 0)
 
828
    while (offset > 0)  
837
829
    {
838
830
      uInt size = AZ_BUFSIZE_READ;
839
831
      if (offset < AZ_BUFSIZE_READ) size = (uInt)offset;
840
832
 
841
833
      size = azwrite(s, s->inbuf, size);
842
 
      if (size == 0)
843
 
        return SIZE_MAX;
 
834
      if (size == 0) return -1L;
844
835
 
845
836
      offset -= size;
846
837
    }
857
848
  if (offset >= s->out) {
858
849
    offset -= s->out;
859
850
  } else if (azrewind(s)) {
860
 
    return SIZE_MAX;
 
851
    return -1L;
861
852
  }
862
853
  /* offset is now the number of bytes to skip. */
863
854
 
873
864
    if (offset < AZ_BUFSIZE_WRITE) size = (int)offset;
874
865
 
875
866
    size = azread_internal(s, s->outbuf, size, &error);
876
 
    if (error < 0) return SIZE_MAX;
 
867
    if (error < 0) return -1L;
877
868
    offset -= size;
878
869
  }
879
870
  return s->out;
884
875
  given compressed file. This position represents a number of bytes in the
885
876
  uncompressed data stream.
886
877
*/
887
 
size_t ZEXPORT aztell (azio_stream *file)
 
878
size_t ZEXPORT aztell (file)
 
879
  azio_stream *file;
888
880
{
889
881
  return azseek(file, 0L, SEEK_CUR);
890
882
}
898
890
  int n;
899
891
  unsigned char buffer[1];
900
892
 
901
 
  for (n = 0; n < 4; n++)
 
893
  for (n = 0; n < 4; n++) 
902
894
  {
903
895
    buffer[0]= (int)(x & 0xff);
904
 
    size_t ret= pwrite(s->file, buffer, 1, s->pos);
905
 
    assert(ret == 1);
 
896
    pwrite(s->file, buffer, 1, s->pos);
906
897
    s->pos++;
907
898
    x >>= 8;
908
899
  }
934
925
  int returnable;
935
926
 
936
927
  if (s == NULL) return Z_STREAM_ERROR;
937
 
 
 
928
  
938
929
  if (s->file < 1) return Z_OK;
939
930
 
940
 
  if (s->mode == 'w')
 
931
  if (s->mode == 'w') 
941
932
  {
942
933
    if (do_flush(s, Z_FINISH) != Z_OK)
943
934
      return destroy(s);
968
959
}
969
960
 
970
961
/*
971
 
  Though this was added to support MySQL's FRM file, anything can be
 
962
  Though this was added to support MySQL's FRM file, anything can be 
972
963
  stored in this location.
973
964
*/
974
 
int azwrite_frm(azio_stream *s, const char *blob, unsigned int length)
 
965
int azwrite_frm(azio_stream *s, char *blob, unsigned int length)
975
966
{
976
 
  if (s->mode == 'r')
 
967
  if (s->mode == 'r') 
977
968
    return 1;
978
969
 
979
 
  if (s->rows > 0)
 
970
  if (s->rows > 0) 
980
971
    return 1;
981
972
 
982
973
  s->frm_start_pos= (uint) s->start;
983
974
  s->frm_length= length;
984
975
  s->start+= length;
985
976
 
986
 
  if (pwrite(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos) != (ssize_t)s->frm_length)
987
 
    return 1;
 
977
  pwrite(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
988
978
 
989
979
  write_header(s);
990
 
  s->pos= (size_t)lseek(s->file, 0, SEEK_END);
 
980
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
991
981
 
992
982
  return 0;
993
983
}
994
984
 
995
985
int azread_frm(azio_stream *s, char *blob)
996
986
{
997
 
  ssize_t r= pread(s->file, (unsigned char*) blob,
998
 
                   s->frm_length, s->frm_start_pos);
999
 
  if (r != (ssize_t)s->frm_length)
1000
 
    return r;
 
987
  pread(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
1001
988
 
1002
989
  return 0;
1003
990
}
1006
993
/*
1007
994
  Simple comment field
1008
995
*/
1009
 
int azwrite_comment(azio_stream *s, const char *blob, unsigned int length)
 
996
int azwrite_comment(azio_stream *s, char *blob, unsigned int length)
1010
997
{
1011
 
  if (s->mode == 'r')
1012
 
    return -1;
 
998
  if (s->mode == 'r') 
 
999
    return 1;
1013
1000
 
1014
 
  if (s->rows > 0)
1015
 
    return -1;
 
1001
  if (s->rows > 0) 
 
1002
    return 1;
1016
1003
 
1017
1004
  s->comment_start_pos= (uint) s->start;
1018
1005
  s->comment_length= length;
1019
1006
  s->start+= length;
1020
1007
 
1021
 
  ssize_t r= pwrite(s->file, (unsigned char*) blob,
1022
 
                    s->comment_length, s->comment_start_pos);
1023
 
  if (r != (ssize_t)s->comment_length)
1024
 
    return -1;
 
1008
  pwrite(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
1025
1009
 
1026
1010
  write_header(s);
1027
 
  s->pos= (size_t)lseek(s->file, 0, SEEK_END);
 
1011
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
1028
1012
 
1029
1013
  return 0;
1030
1014
}
1031
1015
 
1032
1016
int azread_comment(azio_stream *s, char *blob)
1033
1017
{
1034
 
  ssize_t r= pread(s->file, (unsigned char*) blob,
1035
 
                   s->comment_length, s->comment_start_pos);
1036
 
  if (r != (ssize_t)s->comment_length)
1037
 
    return r;
 
1018
  pread(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
1038
1019
 
1039
1020
  return 0;
1040
1021
}
1050
1031
}
1051
1032
#endif
1052
1033
 
1053
 
/*
 
1034
/* 
1054
1035
  Normally all IO goes through azio_read(), but in case of error or non-support
1055
1036
  we make use of pread().
1056
1037
*/
1057
1038
static void get_block(azio_stream *s)
1058
1039
{
1059
1040
#ifdef AZIO_AIO
1060
 
  if (s->method == AZ_METHOD_AIO && s->mode == 'r'
 
1041
  if (s->method == AZ_METHOD_AIO && s->mode == 'r' 
1061
1042
      && s->pos < s->check_point
1062
1043
      && s->aio_inited)
1063
1044
  {
1072
1053
    }
1073
1054
    s->pos+= s->stream.avail_in;
1074
1055
    s->inbuf= (Byte *)s->container.buffer;
1075
 
    /* We only azio_read when we know there is more data to be read */
 
1056
    /* We only aio_read when we know there is more data to be read */
1076
1057
    if (s->pos >= s->check_point)
1077
1058
    {
1078
1059
      s->aio_inited= 0;