Exemple #1
0
void * TMemoryStream::Realloc(__int64 & NewCapacity)
{
  if ((NewCapacity > 0) && (NewCapacity != FSize))
  {
    NewCapacity = (NewCapacity + (MemoryDelta - 1)) & ~(MemoryDelta - 1);
  }
  void * Result = FMemory;
  if (NewCapacity != FCapacity)
  {
    if (NewCapacity == 0)
    {
      nb_free(FMemory);
      FMemory = nullptr;
      Result = nullptr;
    }
    else
    {
      if (FCapacity == 0)
      {
        Result = nb_malloc(static_cast<size_t>(NewCapacity));
      }
      else
      {
        Result = nb_realloc(FMemory, static_cast<size_t>(NewCapacity));
      }
      if (Result == nullptr)
      {
        throw EStreamError(FMTLOAD(SMemoryStreamError));
      }
    }
  }
  return Result;
}
Exemple #2
0
void nb_statistics_resize(struct nb_statistics *s, int count)
{
	if (count < s->count)
		return;
	int bottom = s->count;
	s->count = count;
	s->stats = nb_realloc((void*)s->stats, count * sizeof(struct nb_stat));
	memset(s->stats + bottom, 0,
	      (s->count - bottom) * sizeof(struct nb_stat));
}
Exemple #3
0
char *read_header (char *header, size_t *len, FILE *file)
{
  int next_char;

  header = read_line (header, len, file);
  if (!header)
    /* We reached EOF */
    return header;

  while (1)
  {
    next_char = getc (file);
    if (next_char == EOF)
      return header;

    ungetc (next_char, file);
    if (next_char != ' ' && next_char != '\t')
      return header;

    /* The current header is continued on the next line */
    {
      char *cont = nb_malloc (256);
      size_t contlen = 256;
      int space_needed;

      cont = read_line (cont, &contlen, file);
      if (!cont)
      {
	/* This cannot happen - we have at least the ungetted char to read */
	nb_error (0, _("internal error while reading a header continuation"));
      }

      space_needed = strlen (header) + strlen (cont) + 1;
      if (space_needed > *len)
      {
	header = nb_realloc (header, space_needed);
	*len = space_needed;
      }
      strcat (header, cont);
      free (cont);
    }
  }
}