static char *process_int_arg(char *to, char *end, size_t length,
                             longlong par, char arg_type, uint print_type)
{
  size_t res_length, to_length;
  char *store_start= to, *store_end;
  char buff[32];

  if ((to_length= (size_t) (end-to)) < 16 || length)
    store_start= buff;

  if (arg_type == 'd' || arg_type == 'i')
    store_end= longlong10_to_str(par, store_start, -10);
  else if (arg_type == 'u')
    store_end= longlong10_to_str(par, store_start, 10);
  else if (arg_type == 'p')
  {
    store_start[0]= '0';
    store_start[1]= 'x';
    store_end= ll2str(par, store_start + 2, 16, 0);
  }
  else if (arg_type == 'o')
  {
    store_end= ll2str(par, store_start, 8, 0);
  }
  else
  {
    DBUG_ASSERT(arg_type == 'X' || arg_type =='x');
    store_end= ll2str(par, store_start, 16, (arg_type == 'X'));
  }

  if ((res_length= (size_t) (store_end - store_start)) > to_length)
    return to;                           /* num doesn't fit in output */
  /* If %#d syntax was used, we have to pre-zero/pre-space the string */
  if (store_start == buff)
  {
    length= MY_MIN(length, to_length);
    if (res_length < length)
    {
      size_t diff= (length- res_length);
      memset(to, (print_type & PREZERO_ARG) ? '0' : ' ', diff);
      if (arg_type == 'p' && print_type & PREZERO_ARG)
      {
        if (diff > 1)
          to[1]= 'x';
        else
          store_start[0]= 'x';
        store_start[1]= '0';
      }
      to+= diff;
    }
    memmove(to, store_start, res_length);
  }
  to+= res_length;
  return to;
}
Exemple #2
0
int main() {
	long long l;
	long lv;
	int v;
	char buf[1024];

	char *p = "-101212125";
	str2ll(p, strlen(p), &l);
	printf("%lld\n", l);


	p = "1234567890";
	str2ll(p, strlen(p), &l);
	printf("%lld\n", l);

	memset(buf, 0, sizeof(buf));
	snprintf(buf, sizeof(buf), "%lld", LLONG_MAX);
	str2ll(buf, strlen(buf), &l);
	memset(buf, 0, sizeof(buf));
	ll2str(l, buf, sizeof(buf));
	printf("%s, %lld\n", buf, l);

	printf("%lld\n", LLONG_MIN);
	p = "-9223372036854775808";
	v = str2ll(p, strlen(p), &l);
	memset(buf, 0, sizeof(buf));
	ll2str(l, buf, sizeof(buf));
	printf("%d, %s, %lld\n", v, p, l);

	p = "-9223372036854775809";
	v = str2ll(p, strlen(p), &l);
	printf("%d, %s, %lld\n", v, p, l);

	p = "9223372036854775808";
	v = str2ll(p, strlen(p), &l);
	printf("%d, %s, %lld\n", v, p, l);

	p = "0001";
	v = str2ll(p, strlen(p), &l);
	printf("%d, %s, %lld\n", v, p, l);

	v = ll2str(1234567890L, buf, 9);
	buf[v] = 0;
	printf("%d, %s\n", v, buf);	

	v = ll2str(-101212125L, buf, 9);
	buf[v] = 0;
	printf("%d, %s\n", v, buf);	
	return 0;
}