~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_iocache2.c

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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