~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/azio.cc

  • Committer: Monty Taylor
  • Date: 2009-03-25 21:06:47 UTC
  • mto: This revision was merged to the branch mainline in revision 964.
  • Revision ID: mordred@inaugust.com-20090325210647-7j1tm98gvct3jxsu
Removed legacy_db_type.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <stdio.h>
17
17
#include <string.h>
 
18
#include <stdlib.h>
18
19
#include <assert.h>
19
20
#include <unistd.h>
20
21
 
21
22
static int const az_magic[3] = {0xfe, 0x03, 0x01}; /* az magic header */
22
23
 
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
 
 
31
24
static unsigned int azwrite(azio_stream *s, void *buf, unsigned int len);
32
25
static int azrewind (azio_stream *s);
33
26
static unsigned int azio_enable_aio(azio_stream *s);
34
27
static int do_flush(azio_stream *file, int flush);
35
28
static int    get_byte(azio_stream *s);
36
29
static void   check_header(azio_stream *s);
37
 
static void write_header(azio_stream *s);
 
30
static int write_header(azio_stream *s);
38
31
static int    destroy(azio_stream *s);
39
32
static void putLong(azio_stream *s, uLong x);
40
33
static uLong  getLong(azio_stream *s);
44
37
static void do_aio_cleanup(azio_stream *s);
45
38
#endif
46
39
 
47
 
static pthread_handler_t run_task(void *p)
 
40
extern "C"
 
41
pthread_handler_t run_task(void *p)
48
42
{
49
43
  int fd;
50
44
  char *buffer;
51
45
  size_t offset;
52
 
  azio_stream *s= (azio_stream *)p;  
 
46
  azio_stream *s= (azio_stream *)p;
53
47
 
54
48
  my_thread_init();
55
49
 
62
56
    }
63
57
    offset= s->container.offset;
64
58
    fd= s->container.fd;
65
 
    buffer= s->container.buffer;
 
59
    buffer= (char *)s->container.buffer;
66
60
    pthread_mutex_unlock(&s->container.thresh_mutex);
67
61
 
68
62
    if (s->container.ready == AZ_THREAD_DEAD)
84
78
static void azio_kill(azio_stream *s)
85
79
{
86
80
  pthread_mutex_lock(&s->container.thresh_mutex);
87
 
  s->container.ready= AZ_THREAD_DEAD; 
 
81
  s->container.ready= AZ_THREAD_DEAD;
88
82
  pthread_mutex_unlock(&s->container.thresh_mutex);
89
83
 
90
84
  pthread_cond_signal(&s->container.threshhold);
91
 
  pthread_join(s->container.mainthread, (void *)NULL);
 
85
  pthread_join(s->container.mainthread, NULL);
92
86
}
93
87
 
94
88
static size_t azio_return(azio_stream *s)
126
120
  pthread_attr_init(&attr);
127
121
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
128
122
 
129
 
  s->container.ready= AZ_THREAD_FINISHED; 
 
123
  s->container.ready= AZ_THREAD_FINISHED;
130
124
 
131
125
  /* If we don't create a thread, signal the caller */
132
126
  if (pthread_create(&s->container.mainthread, &attr, run_task,
141
135
static int azio_read(azio_stream *s)
142
136
{
143
137
  pthread_mutex_lock(&s->container.thresh_mutex);
144
 
  s->container.ready= AZ_THREAD_ACTIVE; 
 
138
  s->container.ready= AZ_THREAD_ACTIVE;
145
139
  pthread_mutex_unlock(&s->container.thresh_mutex);
146
140
  pthread_cond_broadcast(&s->container.threshhold);
147
141
 
187
181
  s->method= method;
188
182
 
189
183
  /*
190
 
    We do our own version of append by nature. 
 
184
    We do our own version of append by nature.
191
185
    We must always have write access to take card of the header.
192
186
  */
193
187
  assert(Flags | O_APPEND);
194
188
  assert(Flags | O_WRONLY);
195
189
 
196
 
  if (Flags & O_RDWR) 
 
190
  if (Flags & O_RDWR)
197
191
    s->mode = 'w';
198
192
 
199
 
  if (s->mode == 'w') 
 
193
  if (s->mode == 'w')
200
194
  {
201
195
    err = deflateInit2(&(s->stream), level,
202
196
                       Z_DEFLATED, -MAX_WBITS, 8, strategy);
233
227
  s->container.fd= s->file;
234
228
#endif
235
229
 
236
 
  if (s->file < 0 ) 
 
230
  if (s->file < 0 )
237
231
  {
238
232
    destroy(s);
239
233
    return Z_NULL;
240
234
  }
241
235
 
242
 
  if (Flags & O_CREAT || Flags & O_TRUNC) 
 
236
  if (Flags & O_CREAT || Flags & O_TRUNC)
243
237
  {
244
238
    s->rows= 0;
245
239
    s->forced_flushes= 0;
253
247
    s->frm_length= 0;
254
248
    s->dirty= 1; /* We create the file dirty */
255
249
    s->start = AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
256
 
    write_header(s);
257
 
    s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
 
250
    if(write_header(s))
 
251
      return Z_NULL;
 
252
    s->pos= (size_t)lseek(s->file, 0, SEEK_END);
258
253
  }
259
 
  else if (s->mode == 'w') 
 
254
  else if (s->mode == 'w')
260
255
  {
261
256
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
262
 
    pread(s->file, buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
257
    const ssize_t read_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
 
258
    if(pread(s->file, buffer, read_size, 0) < read_size)
 
259
      return Z_NULL;
263
260
    read_header(s, buffer);
264
 
    s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
 
261
    s->pos= (size_t)lseek(s->file, 0, SEEK_END);
265
262
  }
266
263
  else
267
264
  {
282
279
}
283
280
 
284
281
 
285
 
void write_header(azio_stream *s)
 
282
int write_header(azio_stream *s)
286
283
{
287
284
  char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
288
285
  char *ptr= buffer;
306
303
  int4store(ptr + AZ_COMMENT_LENGTH_POS, s->comment_length); /* COMMENT Block */
307
304
  int4store(ptr + AZ_META_POS, 0); /* Meta Block */
308
305
  int4store(ptr + AZ_META_LENGTH_POS, 0); /* Meta Block */
309
 
  int8store(ptr + AZ_START_POS, (unsigned long long)s->start); /* Start of Data Block Index Block */
310
 
  int8store(ptr + AZ_ROW_POS, (unsigned long long)s->rows); /* Start of Data Block Index Block */
311
 
  int8store(ptr + AZ_FLUSH_POS, (unsigned long long)s->forced_flushes); /* Start of Data Block Index Block */
312
 
  int8store(ptr + AZ_CHECK_POS, (unsigned long long)s->check_point); /* Start of Data Block Index Block */
313
 
  int8store(ptr + AZ_AUTOINCREMENT_POS, (unsigned long long)s->auto_increment); /* Start of Data Block Index Block */
 
306
  int8store(ptr + AZ_START_POS, (uint64_t)s->start); /* Start of Data Block Index Block */
 
307
  int8store(ptr + AZ_ROW_POS, (uint64_t)s->rows); /* Start of Data Block Index Block */
 
308
  int8store(ptr + AZ_FLUSH_POS, (uint64_t)s->forced_flushes); /* Start of Data Block Index Block */
 
309
  int8store(ptr + AZ_CHECK_POS, (uint64_t)s->check_point); /* Start of Data Block Index Block */
 
310
  int8store(ptr + AZ_AUTOINCREMENT_POS, (uint64_t)s->auto_increment); /* Start of Data Block Index Block */
314
311
  int4store(ptr+ AZ_LONGEST_POS , s->longest_row); /* Longest row */
315
312
  int4store(ptr+ AZ_SHORTEST_POS, s->shortest_row); /* Shorest row */
316
 
  int4store(ptr+ AZ_FRM_POS, 
 
313
  int4store(ptr+ AZ_FRM_POS,
317
314
            AZHEADER_SIZE + AZMETA_BUFFER_SIZE); /* FRM position */
318
315
  *(ptr + AZ_DIRTY_POS)= (unsigned char)s->dirty; /* Start of Data Block Index Block */
319
316
 
320
317
  /* Always begin at the begining, and end there as well */
321
 
  pwrite(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
318
  const ssize_t write_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
 
319
  if(pwrite(s->file, (unsigned char*) buffer, write_size, 0)!=write_size)
 
320
    return -1;
 
321
 
 
322
  return 0;
322
323
}
323
324
 
324
325
/* ===========================================================================
326
327
  for end of file.
327
328
  IN assertion: the stream s has been sucessfully opened for reading.
328
329
*/
329
 
int get_byte(s)
330
 
  azio_stream *s;
 
330
int get_byte(azio_stream *s)
331
331
{
332
332
  if (s->z_eof) return EOF;
333
 
  if (s->stream.avail_in == 0) 
 
333
  if (s->stream.avail_in == 0)
334
334
  {
335
335
    errno = 0;
336
 
    if (s->stream.avail_in == 0) 
 
336
    if (s->stream.avail_in == 0)
337
337
    {
338
338
      s->z_eof = 1;
339
339
      return EOF;
402
402
    s->minor_version= (unsigned int)buffer[AZ_MINOR_VERSION_POS];
403
403
    s->block_size= 1024 * buffer[AZ_BLOCK_POS];
404
404
    s->start= (size_t)uint8korr(buffer + AZ_START_POS);
405
 
    s->rows= (unsigned long long)uint8korr(buffer + AZ_ROW_POS);
406
 
    s->check_point= (unsigned long long)uint8korr(buffer + AZ_CHECK_POS);
407
 
    s->forced_flushes= (unsigned long long)uint8korr(buffer + AZ_FLUSH_POS);
408
 
    s->auto_increment= (unsigned long long)uint8korr(buffer + AZ_AUTOINCREMENT_POS);
 
405
    s->rows= (uint64_t)uint8korr(buffer + AZ_ROW_POS);
 
406
    s->check_point= (uint64_t)uint8korr(buffer + AZ_CHECK_POS);
 
407
    s->forced_flushes= (uint64_t)uint8korr(buffer + AZ_FLUSH_POS);
 
408
    s->auto_increment= (uint64_t)uint8korr(buffer + AZ_AUTOINCREMENT_POS);
409
409
    s->longest_row= (unsigned int)uint4korr(buffer + AZ_LONGEST_POS);
410
410
    s->shortest_row= (unsigned int)uint4korr(buffer + AZ_SHORTEST_POS);
411
411
    s->frm_start_pos= (unsigned int)uint4korr(buffer + AZ_FRM_POS);
425
425
 * Cleanup then free the given azio_stream. Return a zlib error code.
426
426
 Try freeing in the reverse order of allocations.
427
427
 */
428
 
int destroy (s)
429
 
  azio_stream *s;
 
428
int destroy (azio_stream *s)
430
429
{
431
430
  int err = Z_OK;
432
431
 
433
 
  if (s->stream.state != NULL) 
 
432
  if (s->stream.state != NULL)
434
433
  {
435
 
    if (s->mode == 'w') 
 
434
    if (s->mode == 'w')
436
435
    {
437
436
      err = deflateEnd(&(s->stream));
438
437
      my_sync(s->file, MYF(0));
439
438
    }
440
 
    else if (s->mode == 'r') 
 
439
    else if (s->mode == 'r')
441
440
      err = inflateEnd(&(s->stream));
442
441
  }
443
442
 
444
443
  do_aio_cleanup(s);
445
444
 
446
 
  if (s->file > 0 && my_close(s->file, MYF(0))) 
 
445
  if (s->file > 0 && my_close(s->file, MYF(0)))
447
446
      err = Z_ERRNO;
448
447
 
449
448
  s->file= -1;
464
463
  *error= 0;
465
464
 
466
465
  if (s->mode != 'r')
467
 
  { 
 
466
  {
468
467
    *error= Z_STREAM_ERROR;
469
468
    return 0;
470
469
  }
471
470
 
472
471
  if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO)
473
 
  { 
 
472
  {
474
473
    *error= s->z_err;
475
474
    return 0;
476
475
  }
477
476
 
478
477
  if (s->z_err == Z_STREAM_END)  /* EOF */
479
 
  { 
 
478
  {
480
479
    return 0;
481
480
  }
482
481
 
493
492
    start++;
494
493
    if (s->last) {
495
494
      s->z_err = Z_STREAM_END;
496
 
      { 
 
495
      {
497
496
        return 1;
498
497
      }
499
498
    }
505
504
 
506
505
      errno = 0;
507
506
      get_block(s);
508
 
      if (s->stream.avail_in == 0) 
 
507
      if (s->stream.avail_in == 0)
509
508
      {
510
509
        s->z_eof = 1;
511
510
      }
531
530
         * Check for such files:
532
531
       */
533
532
        check_header(s);
534
 
        if (s->z_err == Z_OK) 
 
533
        if (s->z_err == Z_OK)
535
534
        {
536
535
          inflateReset(&(s->stream));
537
536
          s->crc = crc32(0L, Z_NULL, 0);
554
553
}
555
554
 
556
555
/* ===========================================================================
557
 
  Experimental Interface. We abstract out a concecpt of rows 
 
556
  Experimental Interface. We abstract out a concecpt of rows
558
557
*/
559
558
size_t azwrite_row(azio_stream *s, void *buf, unsigned int len)
560
559
{
588
587
  size_t read;
589
588
 
590
589
  read= azread_internal(s, buffer, sizeof(unsigned int), error);
591
 
  
 
590
 
592
591
  /* On error the return value will be zero as well */
593
592
  if (read == 0)
594
593
    return read;
597
596
  new_ptr= (char *)realloc(s->row_ptr, (sizeof(char) * row_length));
598
597
 
599
598
  if (!new_ptr)
600
 
    return -1;
 
599
    return SIZE_MAX;
601
600
 
602
601
  s->row_ptr= new_ptr;
603
602
 
617
616
  s->stream.next_in = (Bytef*)buf;
618
617
  s->stream.avail_in = len;
619
618
 
620
 
  while (s->stream.avail_in != 0) 
 
619
  while (s->stream.avail_in != 0)
621
620
  {
622
 
    if (s->stream.avail_out == 0) 
 
621
    if (s->stream.avail_out == 0)
623
622
    {
624
623
 
625
624
      s->stream.next_out = s->outbuf;
626
 
      if (pwrite(s->file, (unsigned char *)s->outbuf, AZ_BUFSIZE_WRITE, s->pos) != AZ_BUFSIZE_WRITE) 
 
625
      if (pwrite(s->file, (unsigned char *)s->outbuf, AZ_BUFSIZE_WRITE, s->pos) != AZ_BUFSIZE_WRITE)
627
626
      {
628
627
        s->z_err = Z_ERRNO;
629
628
        break;
658
657
 
659
658
  s->stream.avail_in = 0; /* should be zero already anyway */
660
659
 
661
 
  for (;;) 
 
660
  for (;;)
662
661
  {
663
662
    len = AZ_BUFSIZE_WRITE - s->stream.avail_out;
664
663
 
665
 
    if (len != 0) 
 
664
    if (len != 0)
666
665
    {
667
 
      if ((uInt)pwrite(s->file, (unsigned char *)s->outbuf, len, s->pos) != len) 
 
666
      if ((uInt)pwrite(s->file, (unsigned char *)s->outbuf, len, s->pos) != len)
668
667
      {
669
668
        s->z_err = Z_ERRNO;
670
669
        assert(0);
696
695
  else
697
696
    s->dirty= AZ_STATE_SAVED; /* Mark it clean, we should be good now */
698
697
 
699
 
  afterwrite_pos= (size_t)my_tell(s->file, MYF(0));
700
 
  write_header(s);
 
698
  afterwrite_pos= (size_t)lseek(s->file, 0, SEEK_CUR);
 
699
  if(write_header(s))
 
700
    return Z_ERRNO;
701
701
 
702
702
  return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
703
703
}
721
721
  s->method= AZ_METHOD_BLOCK;
722
722
}
723
723
 
724
 
int ZEXPORT azflush (s, flush)
725
 
  azio_stream *s;
726
 
  int flush;
 
724
int ZEXPORT azflush (azio_stream *s,int flush)
727
725
{
728
726
  int err;
729
727
 
730
 
  if (s->mode == 'r') 
 
728
  if (s->mode == 'r')
731
729
  {
732
730
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
733
 
    pread(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
731
    const ssize_t read_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
 
732
    if(pread(s->file, (unsigned char*) buffer, read_size, 0)!=read_size)
 
733
      return Z_ERRNO;
734
734
    read_header(s, buffer); /* skip the .az header */
735
735
    azrewind(s);
736
736
 
777
777
/* ===========================================================================
778
778
  Rewinds input file.
779
779
*/
780
 
int azrewind (s)
781
 
  azio_stream *s;
 
780
int azrewind (azio_stream *s)
782
781
{
783
782
  if (s == NULL || s->mode != 'r') return -1;
784
783
 
807
806
  SEEK_END is not implemented, returns error.
808
807
  In this version of the library, azseek can be extremely slow.
809
808
*/
810
 
size_t azseek (s, offset, whence)
811
 
  azio_stream *s;
812
 
  size_t offset;
813
 
  int whence;
 
809
size_t azseek (azio_stream *s, size_t offset, int whence)
814
810
{
815
811
 
816
812
  if (s == NULL || whence == SEEK_END ||
817
813
      s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
818
 
    return -1L;
 
814
    return SIZE_MAX;
819
815
  }
820
816
 
821
 
  if (s->mode == 'w') 
 
817
  if (s->mode == 'w')
822
818
  {
823
 
    if (whence == SEEK_SET) 
 
819
    if (whence == SEEK_SET)
824
820
      offset -= s->in;
825
821
 
826
822
    /* At this point, offset is the number of zero bytes to write. */
827
823
    /* There was a zmemzero here if inbuf was null -Brian */
828
 
    while (offset > 0)  
 
824
    while (offset > 0)
829
825
    {
830
826
      uInt size = AZ_BUFSIZE_READ;
831
827
      if (offset < AZ_BUFSIZE_READ) size = (uInt)offset;
832
828
 
833
829
      size = azwrite(s, s->inbuf, size);
834
 
      if (size == 0) return -1L;
 
830
      if (size == 0)
 
831
        return SIZE_MAX;
835
832
 
836
833
      offset -= size;
837
834
    }
848
845
  if (offset >= s->out) {
849
846
    offset -= s->out;
850
847
  } else if (azrewind(s)) {
851
 
    return -1L;
 
848
    return SIZE_MAX;
852
849
  }
853
850
  /* offset is now the number of bytes to skip. */
854
851
 
864
861
    if (offset < AZ_BUFSIZE_WRITE) size = (int)offset;
865
862
 
866
863
    size = azread_internal(s, s->outbuf, size, &error);
867
 
    if (error < 0) return -1L;
 
864
    if (error < 0) return SIZE_MAX;
868
865
    offset -= size;
869
866
  }
870
867
  return s->out;
875
872
  given compressed file. This position represents a number of bytes in the
876
873
  uncompressed data stream.
877
874
*/
878
 
size_t ZEXPORT aztell (file)
879
 
  azio_stream *file;
 
875
size_t ZEXPORT aztell (azio_stream *file)
880
876
{
881
877
  return azseek(file, 0L, SEEK_CUR);
882
878
}
890
886
  int n;
891
887
  unsigned char buffer[1];
892
888
 
893
 
  for (n = 0; n < 4; n++) 
 
889
  for (n = 0; n < 4; n++)
894
890
  {
895
891
    buffer[0]= (int)(x & 0xff);
896
 
    pwrite(s->file, buffer, 1, s->pos);
 
892
    assert(pwrite(s->file, buffer, 1, s->pos)==1);
897
893
    s->pos++;
898
894
    x >>= 8;
899
895
  }
925
921
  int returnable;
926
922
 
927
923
  if (s == NULL) return Z_STREAM_ERROR;
928
 
  
 
924
 
929
925
  if (s->file < 1) return Z_OK;
930
926
 
931
 
  if (s->mode == 'w') 
 
927
  if (s->mode == 'w')
932
928
  {
933
929
    if (do_flush(s, Z_FINISH) != Z_OK)
934
930
      return destroy(s);
959
955
}
960
956
 
961
957
/*
962
 
  Though this was added to support MySQL's FRM file, anything can be 
 
958
  Though this was added to support MySQL's FRM file, anything can be
963
959
  stored in this location.
964
960
*/
965
961
int azwrite_frm(azio_stream *s, char *blob, unsigned int length)
966
962
{
967
 
  if (s->mode == 'r') 
 
963
  if (s->mode == 'r')
968
964
    return 1;
969
965
 
970
 
  if (s->rows > 0) 
 
966
  if (s->rows > 0)
971
967
    return 1;
972
968
 
973
969
  s->frm_start_pos= (uint) s->start;
974
970
  s->frm_length= length;
975
971
  s->start+= length;
976
972
 
977
 
  pwrite(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
 
973
  if (pwrite(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos) != (ssize_t)s->frm_length)
 
974
    return 1;
978
975
 
979
976
  write_header(s);
980
 
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
 
977
  s->pos= (size_t)lseek(s->file, 0, SEEK_END);
981
978
 
982
979
  return 0;
983
980
}
984
981
 
985
982
int azread_frm(azio_stream *s, char *blob)
986
983
{
987
 
  pread(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
 
984
  ssize_t r= pread(s->file, (unsigned char*) blob,
 
985
                   s->frm_length, s->frm_start_pos);
 
986
  if (r != (ssize_t)s->frm_length)
 
987
    return r;
988
988
 
989
989
  return 0;
990
990
}
995
995
*/
996
996
int azwrite_comment(azio_stream *s, char *blob, unsigned int length)
997
997
{
998
 
  if (s->mode == 'r') 
 
998
  if (s->mode == 'r')
999
999
    return 1;
1000
1000
 
1001
 
  if (s->rows > 0) 
 
1001
  if (s->rows > 0)
1002
1002
    return 1;
1003
1003
 
1004
1004
  s->comment_start_pos= (uint) s->start;
1005
1005
  s->comment_length= length;
1006
1006
  s->start+= length;
1007
1007
 
1008
 
  pwrite(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
 
1008
  ssize_t r= pwrite(s->file, (unsigned char*) blob,
 
1009
                    s->comment_length, s->comment_start_pos);
 
1010
  if (r != (ssize_t)s->comment_length)
 
1011
    return r;
1009
1012
 
1010
1013
  write_header(s);
1011
 
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
 
1014
  s->pos= (size_t)lseek(s->file, 0, SEEK_END);
1012
1015
 
1013
1016
  return 0;
1014
1017
}
1015
1018
 
1016
1019
int azread_comment(azio_stream *s, char *blob)
1017
1020
{
1018
 
  pread(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
 
1021
  ssize_t r= pread(s->file, (unsigned char*) blob,
 
1022
                   s->comment_length, s->comment_start_pos);
 
1023
  if (r != (ssize_t)s->comment_length)
 
1024
    return r;
1019
1025
 
1020
1026
  return 0;
1021
1027
}
1031
1037
}
1032
1038
#endif
1033
1039
 
1034
 
/* 
 
1040
/*
1035
1041
  Normally all IO goes through azio_read(), but in case of error or non-support
1036
1042
  we make use of pread().
1037
1043
*/
1038
1044
static void get_block(azio_stream *s)
1039
1045
{
1040
1046
#ifdef AZIO_AIO
1041
 
  if (s->method == AZ_METHOD_AIO && s->mode == 'r' 
 
1047
  if (s->method == AZ_METHOD_AIO && s->mode == 'r'
1042
1048
      && s->pos < s->check_point
1043
1049
      && s->aio_inited)
1044
1050
  {