Пример #1
0
const char *dbuf_c_str(struct dbuf_s *dbuf)
{
    assert(dbuf != NULL);
    assert(dbuf->alloc != 0);
    assert(dbuf->buf != NULL);

    if (_dbuf_expand(dbuf, 1) != 0) {
        ((char *)dbuf->buf)[dbuf->len] = '\0';
        return dbuf->buf;
    }

    return NULL;
}
Пример #2
0
int dbuf_append(struct dbuf_s *dbuf, const void *buf, size_t len)
{
    assert(dbuf != NULL);
    assert(dbuf->alloc != 0);
    assert(dbuf->buf != NULL);

    if (_dbuf_expand(dbuf, len) != 0) {
        memcpy(&(((char *)dbuf->buf)[dbuf->len]), buf, len);
        dbuf->len += len;
        return 1;
    }

    return 0;
}
Пример #3
0
int dbuf_prepend(struct dbuf_s *dbuf, const void *buf, size_t len)
{
  assert(dbuf);
  assert(dbuf->alloc);
  assert(dbuf->buf);

  if (_dbuf_expand(dbuf, len) != 0) {
    memmove(&(((char *)dbuf->buf)[len]), dbuf->buf, dbuf->len);
    memcpy(dbuf->buf, buf, len);
    dbuf->len += len;
    return 1;
  }

  return 0;
}