~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/azio.c

  • Committer: Stewart Smith
  • Date: 2008-10-15 03:45:49 UTC
  • mto: This revision was merged to the branch mainline in revision 516.
  • Revision ID: stewart@flamingspork.com-20081015034549-uy15gbp9jl255py4
fix not checked return values for ARCHIVE's azio.c

(I should really port the NDB version across... it already has these fixes and more).

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
static int do_flush(azio_stream *file, int flush);
35
35
static int    get_byte(azio_stream *s);
36
36
static void   check_header(azio_stream *s);
37
 
static void write_header(azio_stream *s);
 
37
static int write_header(azio_stream *s);
38
38
static int    destroy(azio_stream *s);
39
39
static void putLong(azio_stream *s, uLong x);
40
40
static uLong  getLong(azio_stream *s);
253
253
    s->frm_length= 0;
254
254
    s->dirty= 1; /* We create the file dirty */
255
255
    s->start = AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
256
 
    write_header(s);
 
256
    if(write_header(s))
 
257
      return Z_NULL;
257
258
    s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
258
259
  }
259
260
  else if (s->mode == 'w') 
260
261
  {
261
262
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
262
 
    pread(s->file, buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
263
    const ssize_t read_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
 
264
    if(pread(s->file, buffer, read_size, 0) < read_size)
 
265
      return Z_NULL;
263
266
    read_header(s, buffer);
264
267
    s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
265
268
  }
282
285
}
283
286
 
284
287
 
285
 
void write_header(azio_stream *s)
 
288
int write_header(azio_stream *s)
286
289
{
287
290
  char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
288
291
  char *ptr= buffer;
318
321
  *(ptr + AZ_DIRTY_POS)= (unsigned char)s->dirty; /* Start of Data Block Index Block */
319
322
 
320
323
  /* Always begin at the begining, and end there as well */
321
 
  pwrite(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
324
  const ssize_t write_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
 
325
  if(pwrite(s->file, (unsigned char*) buffer, write_size, 0)!=write_size)
 
326
    return -1;
 
327
 
 
328
  return 0;
322
329
}
323
330
 
324
331
/* ===========================================================================
697
704
    s->dirty= AZ_STATE_SAVED; /* Mark it clean, we should be good now */
698
705
 
699
706
  afterwrite_pos= (size_t)my_tell(s->file, MYF(0));
700
 
  write_header(s);
 
707
  if(write_header(s))
 
708
    return Z_ERRNO;
701
709
 
702
710
  return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
703
711
}
730
738
  if (s->mode == 'r') 
731
739
  {
732
740
    unsigned char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
733
 
    pread(s->file, (unsigned char*) buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0);
 
741
    const ssize_t read_size= AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
 
742
    if(pread(s->file, (unsigned char*) buffer, read_size, 0)!=read_size)
 
743
      return Z_ERRNO;
734
744
    read_header(s, buffer); /* skip the .az header */
735
745
    azrewind(s);
736
746
 
893
903
  for (n = 0; n < 4; n++) 
894
904
  {
895
905
    buffer[0]= (int)(x & 0xff);
896
 
    pwrite(s->file, buffer, 1, s->pos);
 
906
    assert(pwrite(s->file, buffer, 1, s->pos)==1);
897
907
    s->pos++;
898
908
    x >>= 8;
899
909
  }
974
984
  s->frm_length= length;
975
985
  s->start+= length;
976
986
 
977
 
  pwrite(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
 
987
  if(pwrite(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos)
 
988
     != s->frm_length)
 
989
    return 1;
978
990
 
979
991
  write_header(s);
980
992
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
984
996
 
985
997
int azread_frm(azio_stream *s, char *blob)
986
998
{
987
 
  pread(s->file, (unsigned char*) blob, s->frm_length, s->frm_start_pos);
 
999
  ssize_t r= pread(s->file, (unsigned char*) blob,
 
1000
                   s->frm_length, s->frm_start_pos);
 
1001
  if(r!=s->frm_length)
 
1002
    return r;
988
1003
 
989
1004
  return 0;
990
1005
}
1005
1020
  s->comment_length= length;
1006
1021
  s->start+= length;
1007
1022
 
1008
 
  pwrite(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
 
1023
  ssize_t r= pwrite(s->file, (unsigned char*) blob,
 
1024
                    s->comment_length, s->comment_start_pos);
 
1025
  if(r!=s->comment_length)
 
1026
    return r;
1009
1027
 
1010
1028
  write_header(s);
1011
1029
  s->pos= (size_t)my_seek(s->file, 0, MY_SEEK_END, MYF(0));
1015
1033
 
1016
1034
int azread_comment(azio_stream *s, char *blob)
1017
1035
{
1018
 
  pread(s->file, (unsigned char*) blob, s->comment_length, s->comment_start_pos);
 
1036
  ssize_t r= pread(s->file, (unsigned char*) blob,
 
1037
                   s->comment_length, s->comment_start_pos);
 
1038
  if(r!=s->comment_length)
 
1039
    return r;
1019
1040
 
1020
1041
  return 0;
1021
1042
}