Beispiel #1
0
dboolean M_BufferSetFile(buf_t *buf, const char *filename) {
  FILE *fp = NULL;
  size_t length = 0;
  dboolean out = false;

  if ((fp = fopen(filename, "rb")) == NULL)
    return false;

  fseek(fp, 0, SEEK_END);
  length = ftell(fp);
  fseek(fp, 0, SEEK_SET);

  M_BufferClear(buf);
  M_BufferEnsureTotalCapacity(buf, length);

  if (fread(buf->data, sizeof(byte), length, fp) == length) {
    buf->cursor = length;
    buf->size = length;
    out = true;
  }
  else {
    M_BufferClear(buf);
    out = false;
  }

  fclose(fp);
  return out;
}
Beispiel #2
0
bool M_BufferMove(buf_t *buf, size_t dpos, size_t spos, size_t count) {
  if ((spos + count) > M_BufferGetSize(buf))
    return false;

  M_BufferEnsureTotalCapacity(buf, dpos + count);

  memmove(M_BufferGetData(buf) + dpos, M_BufferGetData(buf) + spos, count);

  return true;
}
Beispiel #3
0
void M_BufferInitWithCapacity(buf_t *buf, size_t capacity) {
  M_BufferInit(buf);
  M_BufferEnsureTotalCapacity(buf, capacity);
}
Beispiel #4
0
void M_BufferSetData(buf_t *buf, const void *data, size_t size) {
  M_BufferClear(buf);
  M_BufferEnsureTotalCapacity(buf, size);
  M_BufferWrite(buf, data, size);
}