~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_statrec.c

Cleanup around SAFEMALLOC

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
        /* Functions to handle fixed-length-records */
17
17
 
18
 
#include "myisam_priv.h"
19
 
 
20
 
using namespace drizzled;
21
 
 
22
 
int _mi_write_static_record(MI_INFO *info, const unsigned char *record)
 
18
#include "myisamdef.h"
 
19
 
 
20
int _mi_write_static_record(MI_INFO *info, const uchar *record)
23
21
{
24
 
  unsigned char temp[8];                                /* max pointer length */
 
22
  uchar temp[8];                                /* max pointer length */
25
23
  if (info->s->state.dellink != HA_OFFSET_ERROR &&
26
24
      !info->append_insert_at_end)
27
25
  {
28
 
    internal::my_off_t filepos=info->s->state.dellink;
 
26
    my_off_t filepos=info->s->state.dellink;
29
27
    info->rec_cache.seek_not_done=1;            /* We have done a seek */
30
28
    if (info->s->file_read(info, &temp[0],info->s->base.rec_reflength,
31
29
                info->s->state.dellink+1,
44
42
    if (info->state->data_file_length > info->s->base.max_data_file_length-
45
43
        info->s->base.pack_reclength)
46
44
    {
47
 
      errno=HA_ERR_RECORD_FILE_FULL;
 
45
      my_errno=HA_ERR_RECORD_FILE_FULL;
48
46
      return(2);
49
47
    }
50
48
    if (info->opt_flag & WRITE_CACHE_USED)
54
52
        goto err;
55
53
      if (info->s->base.pack_reclength != info->s->base.reclength)
56
54
      {
57
 
        uint32_t length=info->s->base.pack_reclength - info->s->base.reclength;
 
55
        uint length=info->s->base.pack_reclength - info->s->base.reclength;
58
56
        memset(temp, 0, length);
59
57
        if (my_b_write(&info->rec_cache, temp,length))
60
58
          goto err;
69
67
        goto err;
70
68
      if (info->s->base.pack_reclength != info->s->base.reclength)
71
69
      {
72
 
        uint32_t length=info->s->base.pack_reclength - info->s->base.reclength;
 
70
        uint length=info->s->base.pack_reclength - info->s->base.reclength;
73
71
        memset(temp, 0, length);
74
72
        if (info->s->file_write(info, temp,length,
75
73
                      info->state->data_file_length+
86
84
  return 1;
87
85
}
88
86
 
89
 
int _mi_update_static_record(MI_INFO *info, internal::my_off_t pos, const unsigned char *record)
 
87
int _mi_update_static_record(MI_INFO *info, my_off_t pos, const uchar *record)
90
88
{
91
89
  info->rec_cache.seek_not_done=1;              /* We have done a seek */
92
90
  return (info->s->file_write(info,
98
96
 
99
97
int _mi_delete_static_record(MI_INFO *info)
100
98
{
101
 
  unsigned char temp[9];                                /* 1+sizeof(uint32) */
 
99
  uchar temp[9];                                /* 1+sizeof(uint32) */
102
100
 
103
101
  info->state->del++;
104
102
  info->state->empty+=info->s->base.pack_reclength;
106
104
  _mi_dpointer(info,temp+1,info->s->state.dellink);
107
105
  info->s->state.dellink = info->lastpos;
108
106
  info->rec_cache.seek_not_done=1;
109
 
  return (info->s->file_write(info,(unsigned char*) temp, 1+info->s->rec_reflength,
 
107
  return (info->s->file_write(info,(uchar*) temp, 1+info->s->rec_reflength,
110
108
                    info->lastpos, MYF(MY_NABP)) != 0);
111
109
}
112
110
 
113
111
 
114
 
int _mi_cmp_static_record(register MI_INFO *info, register const unsigned char *old)
 
112
int _mi_cmp_static_record(register MI_INFO *info, register const uchar *old)
115
113
{
116
114
  if (info->opt_flag & WRITE_CACHE_USED)
117
115
  {
132
130
    if (memcmp(info->rec_buff, old,
133
131
               (uint) info->s->base.reclength))
134
132
    {
135
 
      errno=HA_ERR_RECORD_CHANGED;              /* Record have changed */
 
133
      my_errno=HA_ERR_RECORD_CHANGED;           /* Record have changed */
136
134
      return(1);
137
135
    }
138
136
  }
141
139
 
142
140
 
143
141
int _mi_cmp_static_unique(MI_INFO *info, MI_UNIQUEDEF *def,
144
 
                          const unsigned char *record, internal::my_off_t pos)
 
142
                          const uchar *record, my_off_t pos)
145
143
{
146
144
  info->rec_cache.seek_not_done=1;              /* We have done a seek */
147
145
  if (info->s->file_read(info, info->rec_buff, info->s->base.reclength,
157
155
        /*         1 if record is deleted */
158
156
        /*        MY_FILE_ERROR on read-error or locking-error */
159
157
 
160
 
int _mi_read_static_record(register MI_INFO *info, register internal::my_off_t pos,
161
 
                           register unsigned char *record)
 
158
int _mi_read_static_record(register MI_INFO *info, register my_off_t pos,
 
159
                           register uchar *record)
162
160
{
163
161
  int error;
164
162
 
177
175
    {
178
176
      if (!*record)
179
177
      {
180
 
        errno=HA_ERR_RECORD_DELETED;
 
178
        my_errno=HA_ERR_RECORD_DELETED;
181
179
        return(1);                              /* Record is deleted */
182
180
      }
183
181
      info->update|= HA_STATE_AKTIV;            /* Record is read */
191
189
 
192
190
 
193
191
 
194
 
int _mi_read_rnd_static_record(MI_INFO *info, unsigned char *buf,
195
 
                               register internal::my_off_t filepos,
 
192
int _mi_read_rnd_static_record(MI_INFO *info, uchar *buf,
 
193
                               register my_off_t filepos,
196
194
                               bool skip_deleted_blocks)
197
195
{
198
196
  int locked,error,cache_read;
199
 
  uint32_t cache_length;
 
197
  uint cache_length;
200
198
  MYISAM_SHARE *share=info->s;
201
199
 
202
200
  cache_read=0;
204
202
  if (info->opt_flag & WRITE_CACHE_USED &&
205
203
      (info->rec_cache.pos_in_file <= filepos || skip_deleted_blocks) &&
206
204
      flush_io_cache(&info->rec_cache))
207
 
    return(errno);
 
205
    return(my_errno);
208
206
  if (info->opt_flag & READ_CACHE_USED)
209
207
  {                                             /* Cache in use */
210
208
    if (filepos == my_b_tell(&info->rec_cache) &&
222
220
    if (filepos >= info->state->data_file_length)
223
221
    {                                           /* Test if new records */
224
222
      if (_mi_readinfo(info,F_RDLCK,0))
225
 
        return(errno);
 
223
        return(my_errno);
226
224
      locked=1;
227
225
    }
228
226
    else
237
235
  if (filepos >= info->state->data_file_length)
238
236
  {
239
237
    fast_mi_writeinfo(info);
240
 
    return(errno=HA_ERR_END_OF_FILE);
 
238
    return(my_errno=HA_ERR_END_OF_FILE);
241
239
  }
242
240
  info->lastpos= filepos;
243
241
  info->nextpos= filepos+share->base.pack_reclength;
247
245
    if ((error=_mi_read_static_record(info,filepos,buf)))
248
246
    {
249
247
      if (error > 0)
250
 
        error=errno=HA_ERR_RECORD_DELETED;
 
248
        error=my_errno=HA_ERR_RECORD_DELETED;
251
249
      else
252
 
        error=errno;
 
250
        error=my_errno;
253
251
    }
254
252
    return(error);
255
253
  }
256
254
 
257
255
        /* Read record with cacheing */
258
 
  error=my_b_read(&info->rec_cache,(unsigned char*) buf,share->base.reclength);
 
256
  error=my_b_read(&info->rec_cache,(uchar*) buf,share->base.reclength);
259
257
  if (info->s->base.pack_reclength != info->s->base.reclength && !error)
260
258
  {
261
259
    char tmp[8];                                /* Skill fill bytes */
262
 
    error=my_b_read(&info->rec_cache,(unsigned char*) tmp,
 
260
    error=my_b_read(&info->rec_cache,(uchar*) tmp,
263
261
                    info->s->base.pack_reclength - info->s->base.reclength);
264
262
  }
265
263
  if (locked)
266
 
    _mi_writeinfo(info,0);              /* Unlock keyfile */
 
264
    VOID(_mi_writeinfo(info,0));                /* Unlock keyfile */
267
265
  if (!error)
268
266
  {
269
267
    if (!buf[0])
270
268
    {                                           /* Record is removed */
271
 
      return(errno=HA_ERR_RECORD_DELETED);
 
269
      return(my_errno=HA_ERR_RECORD_DELETED);
272
270
    }
273
271
                                                /* Found and may be updated */
274
272
    info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
275
273
    return(0);
276
274
  }
277
 
  /* errno should be set if rec_cache.error == -1 */
278
 
  if (info->rec_cache.error != -1 || errno == 0)
279
 
    errno=HA_ERR_WRONG_IN_RECORD;
280
 
  return(errno);                        /* Something wrong (EOF?) */
 
275
  /* my_errno should be set if rec_cache.error == -1 */
 
276
  if (info->rec_cache.error != -1 || my_errno == 0)
 
277
    my_errno=HA_ERR_WRONG_IN_RECORD;
 
278
  return(my_errno);                     /* Something wrong (EOF?) */
281
279
}