~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_iocache2.cc

  • Committer: Monty Taylor
  • Date: 2009-03-24 17:44:41 UTC
  • mto: (960.5.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 964.
  • Revision ID: mordred@inaugust.com-20090324174441-nmsq0gwjlgf7f0mt
Changed handlerton to StorageEngine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
  More functions to be used with IO_CACHE files
18
18
*/
19
19
 
20
 
#define MAP_TO_USE_RAID
21
20
#include "mysys_priv.h"
22
21
#include <mystrings/m_string.h>
23
22
#include <stdarg.h>
24
23
#include <mystrings/m_ctype.h>
 
24
#include <mysys/iocache.h>
 
25
#include <string>
 
26
 
 
27
using namespace std;
25
28
 
26
29
/*
27
30
  Copy contents of an IO_CACHE to a file.
58
61
  bytes_in_cache= my_b_bytes_in_cache(cache);
59
62
  do
60
63
  {
61
 
    if (my_fwrite(file, cache->read_pos, bytes_in_cache,
62
 
                  MYF(MY_WME | MY_NABP)) == (size_t) -1)
 
64
    if (fwrite(cache->read_pos, 1, bytes_in_cache, file)
 
65
               != bytes_in_cache)
63
66
      return(1);
64
67
    cache->read_pos= cache->read_end;
65
68
  } while ((bytes_in_cache= my_b_fill(cache)));
73
76
    Prevent optimizer from putting res in a register when debugging
74
77
    we need this to be able to see the value of res when the assert fails
75
78
  */
76
 
  volatile my_off_t res; 
 
79
  volatile my_off_t res;
77
80
 
78
81
  /*
79
82
    We need to lock the append buffer mutex to keep flush_io_cache()
170
173
 
171
174
  if (info->seek_not_done)
172
175
  {                                     /* File touched, do seek */
173
 
    if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) ==
 
176
    if (lseek(info->file,pos_in_file,SEEK_SET) ==
174
177
        MY_FILEPOS_ERROR)
175
178
    {
176
179
      info->error= 0;
252
255
    return my_b_tell(info);
253
256
 
254
257
  info->seek_not_done= 1;
255
 
  return my_seek(info->file, 0L, MY_SEEK_END, MYF(0));
 
258
  return lseek(info->file, 0L, SEEK_END);
256
259
}
257
260
 
258
261
 
276
279
size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
277
280
{
278
281
  size_t out_length= 0;
279
 
  uint32_t minimum_width; /* as yet unimplemented */
280
 
  uint32_t minimum_width_sign;
 
282
  int32_t minimum_width; /* as yet unimplemented */
 
283
  int32_t minimum_width_sign;
281
284
  uint32_t precision; /* as yet unimplemented for anything but %b */
282
285
  bool is_zero_padded;
 
286
  basic_string<unsigned char> buffz;
283
287
 
284
288
  /*
285
289
    Store the location of the beginning of a format directive, for the
294
298
    /* Copy everything until '%' or end of string */
295
299
    const char *start=fmt;
296
300
    size_t length;
297
 
    
 
301
 
298
302
    for (; (*fmt != '\0') && (*fmt != '%'); fmt++) ;
299
303
 
300
304
    length= (size_t) (fmt - start);
305
309
    if (*fmt == '\0')                           /* End of format */
306
310
      return out_length;
307
311
 
308
 
    /* 
 
312
    /*
309
313
      By this point, *fmt must be a percent;  Keep track of this location and
310
 
      skip over the percent character. 
 
314
      skip over the percent character.
311
315
    */
312
316
    assert(*fmt == '%');
313
317
    backtrack= fmt;
322
326
process_flags:
323
327
    switch (*fmt)
324
328
    {
325
 
      case '-': 
 
329
      case '-':
326
330
        minimum_width_sign= -1; fmt++; goto process_flags;
327
331
      case '0':
328
332
        is_zero_padded= true; fmt++; goto process_flags;
383
387
    else if (*fmt == 'd' || *fmt == 'u')        /* Integer parameter */
384
388
    {
385
389
      register int iarg;
386
 
      size_t length2;
 
390
      ssize_t length2;
387
391
      char buff[17];
388
392
 
389
393
      iarg = va_arg(args, int);
390
394
      if (*fmt == 'd')
391
395
        length2= (size_t) (int10_to_str((long) iarg,buff, -10) - buff);
392
396
      else
393
 
        length2= (uint) (int10_to_str((long) (uint) iarg,buff,10)- buff);
 
397
        length2= (uint32_t) (int10_to_str((long) (uint32_t) iarg,buff,10)- buff);
394
398
 
395
399
      /* minimum width padding */
396
 
      if (minimum_width > length2) 
 
400
      if (minimum_width > length2)
397
401
      {
398
402
        const size_t buflen = minimum_width - length2;
399
 
        unsigned char *buffz= my_alloca(buflen);
400
 
        memset(buffz, is_zero_padded ? '0' : ' ', buflen);
401
 
        my_b_write(info, buffz, buflen);
402
 
        my_afree(buffz);
 
403
        buffz.clear();
 
404
        buffz.reserve(buflen);
 
405
        buffz.append(buflen, is_zero_padded ? '0' : ' ');
 
406
        my_b_write(info, buffz.data(), buflen);
403
407
      }
404
408
 
405
409
      out_length+= length2;