~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_cache.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
  expected to hit the cache again.
27
27
 
28
28
  Allows "partial read" errors in the record header (when READING_HEADER flag
29
 
  is set) - unread part is bzero'ed
 
29
  is set) - unread part is zero'ed
30
30
 
31
31
  Note: out-of-cache reads are enabled for shared IO_CACHE's too,
32
32
  as these reads will be cached by OS cache (and my_pread is always atomic)
35
35
 
36
36
#include "myisamdef.h"
37
37
 
38
 
int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length,
 
38
int _mi_read_cache(IO_CACHE *info, unsigned char *buff, my_off_t pos, uint32_t length,
39
39
                   int flag)
40
40
{
41
 
  uint read_length,in_buff_length;
 
41
  uint32_t read_length,in_buff_length;
42
42
  my_off_t offset;
43
 
  uchar *in_buff_pos;
44
 
  DBUG_ENTER("_mi_read_cache");
 
43
  unsigned char *in_buff_pos;
45
44
 
46
45
  if (pos < info->pos_in_file)
47
46
  {
50
49
      read_length=(uint) (info->pos_in_file-pos);
51
50
    info->seek_not_done=1;
52
51
    if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP)))
53
 
      DBUG_RETURN(1);
 
52
      return(1);
54
53
    if (!(length-=read_length))
55
 
      DBUG_RETURN(0);
 
54
      return(0);
56
55
    pos+=read_length;
57
56
    buff+=read_length;
58
57
  }
61
60
      (my_off_t) (info->read_end - info->request_pos))
62
61
  {
63
62
    in_buff_pos=info->request_pos+(uint) offset;
64
 
    in_buff_length= min(length, (size_t) (info->read_end-in_buff_pos));
 
63
    in_buff_length= cmin(length, (size_t) (info->read_end-in_buff_pos));
65
64
    memcpy(buff,info->request_pos+(uint) offset,(size_t) in_buff_length);
66
65
    if (!(length-=in_buff_length))
67
 
      DBUG_RETURN(0);
 
66
      return(0);
68
67
    pos+=in_buff_length;
69
68
    buff+=in_buff_length;
70
69
  }
82
81
    else
83
82
      info->read_pos=info->read_end;                    /* All block used */
84
83
    if (!(*info->read_function)(info,buff,length))
85
 
      DBUG_RETURN(0);
 
84
      return(0);
86
85
    read_length=info->error;
87
86
  }
88
87
  else
89
88
  {
90
89
    info->seek_not_done=1;
91
90
    if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length)
92
 
      DBUG_RETURN(0);
 
91
      return(0);
93
92
  }
94
93
  if (!(flag & READING_HEADER) || (int) read_length == -1 ||
95
94
      read_length+in_buff_length < 3)
96
95
  {
97
 
    DBUG_PRINT("error",
98
 
               ("Error %d reading next-multi-part block (Got %d bytes)",
99
 
                my_errno, (int) read_length));
100
96
    if (!my_errno || my_errno == -1)
101
97
      my_errno=HA_ERR_WRONG_IN_RECORD;
102
 
    DBUG_RETURN(1);
 
98
    return(1);
103
99
  }
104
 
  bzero(buff+read_length,MI_BLOCK_INFO_HEADER_LENGTH - in_buff_length -
105
 
        read_length);
106
 
  DBUG_RETURN(0);
 
100
  memset(buff+read_length, 0,
 
101
         MI_BLOCK_INFO_HEADER_LENGTH - in_buff_length - read_length);
 
102
  return(0);
107
103
} /* _mi_read_cache */