All pastes #426871 Raw Edit

Untitled

public text v1 · immutable
·published 2007-04-06 13:33 UTC
rendered paste body
B3dChar* b3d_read_string(B3d *context)
{
  int currentSize = 100;
  B3dChar *result = (B3dChar*)b3d_malloc(context, currentSize);
  
  int pos = -1;
  do
  {
    ++pos;
    if(pos == currentSize)
    {
      int newSize = currentSize * 2;
      B3dChar *newBuff = (B3dChar*)b3d_malloc(context, newSize);
      memcpy(newBuff, result, currentSize);
      b3d_free(context, result);
      
      result = newBuff;
      currentSize = newSize;
    }

    context->read(context, result + pos, 1);
  }while(result[pos] != '\0');
  
  return result;
}