Skip to content

Commit

Permalink
Constify buffer API
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jan 2, 2015
1 parent 3b67208 commit 11461b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ void buffer_free(Buffer *buf) {
buf->size = 0;
}

bool buffer_put(Buffer *buf, void *data, size_t len) {
bool buffer_put(Buffer *buf, const void *data, size_t len) {
if (!buffer_alloc(buf, len))
return false;
memcpy(buf->data, data, len);
buf->len = len;
return true;
}

bool buffer_append(Buffer *buf, void *data, size_t len) {
bool buffer_append(Buffer *buf, const void *data, size_t len) {
size_t rem = buf->size - buf->len;
if (len > rem && !buffer_alloc(buf, buf->size + len - rem))
return false;
Expand Down
4 changes: 2 additions & 2 deletions buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef struct {
void buffer_free(Buffer *buf);
bool buffer_alloc(Buffer *buf, size_t size);
void buffer_truncate(Buffer *buf);
bool buffer_put(Buffer *buf, void *data, size_t len);
bool buffer_append(Buffer *buf, void *data, size_t len);
bool buffer_put(Buffer *buf, const void *data, size_t len);
bool buffer_append(Buffer *buf, const void *data, size_t len);

#endif

0 comments on commit 11461b6

Please sign in to comment.