Пример #1
0
size_t
my_b_write_backtick_quote(IO_CACHE *info, const char *str, size_t len)
{
  const uchar *start;
  const uchar *p= (const uchar *)str;
  const uchar *end= p + len;
  size_t count;
  size_t total= 0;

  if (my_b_write(info, (uchar *)"`", 1))
    return (size_t)-1;
  ++total;
  for (;;)
  {
    start= p;
    while (p < end && *p != '`')
      ++p;
    count= p - start;
    if (count && my_b_write(info, start, count))
      return (size_t)-1;
    total+= count;
    if (p >= end)
      break;
    if (my_b_write(info, (uchar *)"``", 2))
      return (size_t)-1;
    total+= 2;
    ++p;
  }
  if (my_b_write(info, (uchar *)"`", 1))
    return (size_t)-1;
  ++total;
  return total;
}
Пример #2
0
uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
{
  uint out_length=0;
  uint minimum_width; /* as yet unimplemented */
  uint minimum_width_sign;
  uint precision; /* as yet unimplemented for anything but %b */

  /*
    Store the location of the beginning of a format directive, for the
    case where we learn we shouldn't have been parsing a format string
    at all, and we don't want to lose the flag/precision/width/size
    information.
   */
  const char* backtrack;

  for (; *fmt != '\0'; fmt++)
  {
    /* Copy everything until '%' or end of string */
    const char *start=fmt;
    uint length;
    
    for (; (*fmt != '\0') && (*fmt != '%'); fmt++) ;

    length= (uint) (fmt - start);
    out_length+=length;
    if (my_b_write(info, start, length))
      goto err;

    if (*fmt == '\0')				/* End of format */
    {
      return out_length;
    }

    /* 
      By this point, *fmt must be a percent;  Keep track of this location and
      skip over the percent character. 
    */
    DBUG_ASSERT(*fmt == '%');
    backtrack= fmt;
    fmt++;

    minimum_width= 0;
    precision= 0;
    minimum_width_sign= 1;
    /* Skip if max size is used (to be compatible with printf) */
    while (*fmt == '-') { fmt++; minimum_width_sign= -1; }
    if (*fmt == '*') {
      precision= (int) va_arg(args, int);
      fmt++;
    } else {
      while (my_isdigit(&my_charset_latin1, *fmt)) {
Пример #3
0
int _nisam_write_static_record(N_INFO *info, const byte *record)
{
  uchar temp[4];				/* Not sizeof(long) */

  if (info->s->state.dellink != NI_POS_ERROR)
  {
    ulong filepos=info->s->state.dellink;
    info->rec_cache.seek_not_done=1;		/* We have done a seek */
    VOID(my_seek(info->dfile,info->s->state.dellink+1,MY_SEEK_SET,MYF(0)));

    if (my_read(info->dfile,(char*) &temp[0],sizeof(temp), MYF(MY_NABP)))
      goto err;
    info->s->state.dellink=uint4korr(temp);
    if (info->s->state.dellink == (uint32) ~0)	/* Fix for 64 bit long */
      info->s->state.dellink=NI_POS_ERROR;
    info->s->state.del--;
    info->s->state.empty-=info->s->base.reclength;
    VOID(my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0)));
    if (my_write(info->dfile, (char*) record, info->s->base.reclength,
		 MYF(MY_NABP)))
      goto err;
  }
  else
  {
    if (info->s->state.data_file_length > info->s->base.max_data_file_length)
    {
      my_errno=HA_ERR_RECORD_FILE_FULL;
      return(2);
    }
    if (info->opt_flag & WRITE_CACHE_USED)
    {				/* Cash in use */
      if (my_b_write(&info->rec_cache, (byte*) record, info->s->base.reclength))
	goto err;
    }
    else
    {
      info->rec_cache.seek_not_done=1;		/* We have done a seek */
      VOID(my_seek(info->dfile,info->s->state.data_file_length,
		   MY_SEEK_SET,MYF(0)));
      if (my_write(info->dfile,(char*) record,info->s->base.reclength,
		   MYF(MY_NABP | MY_WAIT_IF_FULL)))
	goto err;
    }
    info->s->state.data_file_length+=info->s->base.reclength;
    info->s->state.splitt++;
  }
  return 0;
 err:
  return 1;
}
Пример #4
0
size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
{
  size_t out_length= 0;
  uint minimum_width; /* as yet unimplemented */
  uint minimum_width_sign;
  uint precision; /* as yet unimplemented for anything but %b */
  my_bool is_zero_padded;

  /*
    Store the location of the beginning of a format directive, for the
    case where we learn we shouldn't have been parsing a format string
    at all, and we don't want to lose the flag/precision/width/size
    information.
   */
  const char* backtrack;

  for (; *fmt != '\0'; fmt++)
  {
    /* Copy everything until '%' or end of string */
    const char *start=fmt;
    size_t length;
    
    for (; (*fmt != '\0') && (*fmt != '%'); fmt++) ;

    length= (size_t) (fmt - start);
    out_length+=length;
    if (my_b_write(info, (const uchar*) start, length))
      goto err;

    if (*fmt == '\0')				/* End of format */
      return out_length;

    /* 
      By this point, *fmt must be a percent;  Keep track of this location and
      skip over the percent character. 
    */
    DBUG_ASSERT(*fmt == '%');
    backtrack= fmt;
    fmt++;

    is_zero_padded= FALSE;
    minimum_width_sign= 1;
    minimum_width= 0;
    precision= 0;
    /* Skip if max size is used (to be compatible with printf) */

process_flags:
    switch (*fmt)
    {
      case '-': 
        minimum_width_sign= -1; fmt++; goto process_flags;
      case '0':
        is_zero_padded= TRUE; fmt++; goto process_flags;
      case '#':
        /** @todo Implement "#" conversion flag. */  fmt++; goto process_flags;
      case ' ':
        /** @todo Implement " " conversion flag. */  fmt++; goto process_flags;
      case '+':
        /** @todo Implement "+" conversion flag. */  fmt++; goto process_flags;
    }

    if (*fmt == '*')
    {
      precision= (int) va_arg(args, int);
      fmt++;
    }
    else
    {
      while (my_isdigit(&my_charset_latin1, *fmt)) {
Пример #5
0
int _mi_write_static_record(MI_INFO *info, const uchar *record)
{
  uchar temp[8];				/* max pointer length */
  if (info->s->state.dellink != HA_OFFSET_ERROR &&
      !info->append_insert_at_end)
  {
    my_off_t filepos=info->s->state.dellink;
    info->rec_cache.seek_not_done=1;		/* We have done a seek */
    if (info->s->file_read(info, &temp[0],info->s->base.rec_reflength,
		info->s->state.dellink+1,
		 MYF(MY_NABP)))
      goto err;
    info->s->state.dellink= _mi_rec_pos(info->s,temp);
    info->state->del--;
    info->state->empty-=info->s->base.pack_reclength;
    if (info->s->file_write(info, record, info->s->base.reclength,
		  filepos,
		  MYF(MY_NABP)))
      goto err;
  }
  else
  {
    if (info->state->data_file_length > info->s->base.max_data_file_length-
	info->s->base.pack_reclength)
    {
      my_errno=HA_ERR_RECORD_FILE_FULL;
      return(2);
    }
    if (info->opt_flag & WRITE_CACHE_USED)
    {				/* Cash in use */
      if (my_b_write(&info->rec_cache, record,
		     info->s->base.reclength))
	goto err;
      if (info->s->base.pack_reclength != info->s->base.reclength)
      {
	uint length=info->s->base.pack_reclength - info->s->base.reclength;
	memset(temp, 0, length);
	if (my_b_write(&info->rec_cache, temp,length))
	  goto err;
      }
    }
    else
    {
      info->rec_cache.seek_not_done=1;		/* We have done a seek */
      if (info->s->file_write(info, record, info->s->base.reclength,
		    info->state->data_file_length,
		    info->s->write_flag))
        goto err;
      if (info->s->base.pack_reclength != info->s->base.reclength)
      {
	uint length=info->s->base.pack_reclength - info->s->base.reclength;
	memset(temp, 0, length);
	if (info->s->file_write(info, temp,length,
		      info->state->data_file_length+
		      info->s->base.reclength,
		      info->s->write_flag))
    goto err;
      }
    }
    info->state->data_file_length+=info->s->base.pack_reclength;
    info->s->state.split++;
  }
  return 0;
 err:
  return 1;
}