Exemplo n.º 1
0
DLL_EXPORTED
int
libintl_vsnprintf (char *resultbuf, size_t length, const char *format, va_list args)
{
  if (strchr (format, '$') == NULL)
    return system_vsnprintf (resultbuf, length, format, args);
  else
    {
      size_t maxlength = length;
      char *result = libintl_vasnprintf (resultbuf, &length, format, args);
      if (result == NULL)
        return -1;
      if (result != resultbuf)
        {
          if (maxlength > 0)
            {
              size_t pruned_length =
                (length < maxlength ? length : maxlength - 1);
              memcpy (resultbuf, result, pruned_length);
              resultbuf[pruned_length] = '\0';
            }
          free (result);
        }
      if (length > INT_MAX)
        {
          errno = EOVERFLOW;
          return -1;
        }
      else
        return length;
    }
}
Exemplo n.º 2
0
DLL_EXPORTED
int
libintl_vsnprintf (char *resultbuf, size_t length, const char *format, va_list args)
{
  if (strchr (format, '$') == NULL)
    return system_vsnprintf (resultbuf, length, format, args);
  else
    {
      size_t maxlength = length;
      char *result = libintl_vasnprintf (resultbuf, &length, format, args);
      if (result != resultbuf)
	{
	  if (maxlength > 0)
	    {
	      if (length < maxlength)
		abort ();
	      memcpy (resultbuf, result, maxlength - 1);
	      resultbuf[maxlength - 1] = '\0';
	    }
	  free (result);
	  return -1;
	}
      else
	return length;
    }
}