Skip to content

Commit

Permalink
constify parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Aug 8, 2021
1 parent 209e4ac commit 24a8b22
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions test/buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ void M_BufferInitWithCapacity(buf_t *buf, size_t capacity) {
M_BufferEnsureTotalCapacity(buf, capacity);
}

size_t M_BufferGetCapacity(buf_t *buf) {
size_t M_BufferGetCapacity(const buf_t *buf) {
return buf->capacity;
}

size_t M_BufferGetSize(buf_t *buf) {
size_t M_BufferGetSize(const buf_t *buf) {
return buf->size;
}

size_t M_BufferGetCursor(buf_t *buf) {
size_t M_BufferGetCursor(const buf_t *buf) {
return buf->cursor;
}

char* M_BufferGetData(buf_t *buf) {
char* M_BufferGetData(const buf_t *buf) {
return buf->data;
}

char* M_BufferGetDataAtCursor(buf_t *buf) {
char* M_BufferGetDataAtCursor(const buf_t *buf) {
return buf->data + buf->cursor;
}

Expand Down Expand Up @@ -123,11 +123,11 @@ void M_BufferEnsureTotalCapacity(buf_t *buf, size_t capacity) {
}
}

void M_BufferCopy(buf_t *dst, buf_t *src) {
void M_BufferCopy(buf_t *dst, const buf_t *src) {
M_BufferSetData(dst, M_BufferGetData(src), M_BufferGetSize(src));
}

void M_BufferCursorCopy(buf_t *dst, buf_t *src) {
void M_BufferCursorCopy(buf_t *dst, const buf_t *src) {
M_BufferWrite(
dst,
M_BufferGetDataAtCursor(src),
Expand Down Expand Up @@ -210,7 +210,7 @@ bool M_BufferSeekForward(buf_t *buf, size_t count) {
return true;
}

uint8_t M_BufferPeek(buf_t *buf) {
uint8_t M_BufferPeek(const buf_t *buf) {
return *(buf->data + buf->cursor);
}

Expand Down Expand Up @@ -339,14 +339,14 @@ void M_BufferWriteZeros(buf_t *buf, size_t count) {
check_cursor(buf);
}

bool M_BufferEqualsString(buf_t *buf, const char *s) {
bool M_BufferEqualsString(const buf_t *buf, const char *s) {
if (strncmp(buf->data + buf->cursor, s, buf->size - buf->cursor) == 0)
return true;

return false;
}

bool M_BufferEqualsData(buf_t *buf, const void *d, size_t size) {
bool M_BufferEqualsData(const buf_t *buf, const void *d, size_t size) {
if (buf->cursor + size > buf->size)
return false;

Expand Down Expand Up @@ -464,7 +464,7 @@ bool M_BufferReadString(buf_t *buf, char *s, size_t length) {
return M_BufferRead(buf, s, length);
}

bool M_BufferReadStringDup(buf_t *buf, char **s) {
bool M_BufferReadStringDup(const buf_t *buf, char **s) {
char *d = buf->data + buf->cursor;
size_t length = strlen(d);

Expand All @@ -475,7 +475,7 @@ bool M_BufferReadStringDup(buf_t *buf, char **s) {
return true;
}

bool M_BufferCopyString(buf_t *dst, buf_t *src) {
bool M_BufferCopyString(buf_t *dst, const buf_t *src) {
char *s = src->data + src->cursor;
size_t length = strlen(s);

Expand Down Expand Up @@ -515,7 +515,7 @@ void M_BufferTruncate(buf_t *buf, size_t new_size) {
buf->cursor = buf->size - 1;
}

void M_BufferZero(buf_t *buf) {
void M_BufferZero(const buf_t *buf) {
memset(buf->data, 0, buf->capacity);
}

Expand All @@ -531,7 +531,7 @@ void M_BufferFree(buf_t *buf) {
buf->data = NULL;
}

void M_BufferPrint(buf_t *buf) {
void M_BufferPrint(const buf_t *buf) {
printf("Buffer capacity, size and cursor: [%zu, %zu, %zu].\n",
buf->capacity,
buf->size,
Expand All @@ -548,7 +548,7 @@ void M_BufferPrint(buf_t *buf) {
printf("\n");
}

void M_BufferPrintAll(buf_t *buf) {
void M_BufferPrintAll(const buf_t *buf) {
printf("Buffer capacity, size and cursor: [%zu, %zu, %zu].\n",
buf->capacity,
buf->size,
Expand Down
30 changes: 15 additions & 15 deletions test/buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ buf_t* M_BufferNewWithCapacity(size_t capacity);
void M_BufferInit(buf_t *buf);
void M_BufferInitWithCapacity(buf_t *buf, size_t capacity);

size_t M_BufferGetCapacity(buf_t *buf);
size_t M_BufferGetSize(buf_t *buf);
size_t M_BufferGetCursor(buf_t *buf);
char* M_BufferGetData(buf_t *buf);
char* M_BufferGetDataAtCursor(buf_t *buf);
size_t M_BufferGetCapacity(const buf_t *buf);
size_t M_BufferGetSize(const buf_t *buf);
size_t M_BufferGetCursor(const buf_t *buf);
char* M_BufferGetData(const buf_t *buf);
char* M_BufferGetDataAtCursor(const buf_t *buf);

void M_BufferEnsureCapacity(buf_t *buf, size_t capacity);
void M_BufferEnsureTotalCapacity(buf_t *buf, size_t capacity);

void M_BufferCopy(buf_t *dst, buf_t *src);
void M_BufferCursorCopy(buf_t *dst, buf_t *src);
void M_BufferCopy(buf_t *dst, const buf_t *src);
void M_BufferCursorCopy(buf_t *dst, const buf_t *src);
bool M_BufferMove(buf_t *buf, size_t dpos, size_t spos, size_t count);

void M_BufferSetData(buf_t *buf, const void *data, size_t size);
Expand All @@ -58,7 +58,7 @@ bool M_BufferSeek(buf_t *buf, size_t pos);
bool M_BufferSeekBackward(buf_t *buf, size_t count);
bool M_BufferSeekForward(buf_t *buf, size_t count);

uint8_t M_BufferPeek(buf_t *buf);
uint8_t M_BufferPeek(const buf_t *buf);

void M_BufferWrite(buf_t *buf, const void *data, size_t size);
void M_BufferWriteBool(buf_t *buf, bool b);
Expand Down Expand Up @@ -91,8 +91,8 @@ void M_BufferWriteDoubles(buf_t *buf, const double *doubles, size_t count);
void M_BufferWriteString(buf_t *buf, const char *string, size_t length);
void M_BufferWriteZeros(buf_t *buf, size_t count);

bool M_BufferEqualsString(buf_t *buf, const char *s);
bool M_BufferEqualsData(buf_t *buf, const void *d, size_t size);
bool M_BufferEqualsString(const buf_t *buf, const char *s);
bool M_BufferEqualsData(const buf_t *buf, const void *d, size_t size);

bool M_BufferRead(buf_t *buf, void *data, size_t size);
bool M_BufferReadBool(buf_t *buf, bool *b);
Expand Down Expand Up @@ -120,17 +120,17 @@ bool M_BufferReadDouble(buf_t *buf, double *d);
bool M_BufferReadDoubles(buf_t *buf, double *d, size_t count);
#endif
bool M_BufferReadString(buf_t *buf, char *s, size_t length);
bool M_BufferReadStringDup(buf_t *buf, char **s);
bool M_BufferCopyString(buf_t *dst, buf_t *src);
bool M_BufferReadStringDup(const buf_t *buf, char **s);
bool M_BufferCopyString(buf_t *dst, const buf_t *src);

void M_BufferCompact(buf_t *buf);
void M_BufferTruncate(buf_t *buf, size_t new_size);
void M_BufferZero(buf_t *buf);
void M_BufferZero(const buf_t *buf);
void M_BufferClear(buf_t *buf);
void M_BufferFree(buf_t *buf);

void M_BufferPrint(buf_t *buf);
void M_BufferPrintAll(buf_t *buf);
void M_BufferPrint(const buf_t *buf);
void M_BufferPrintAll(const buf_t *buf);

#endif

Expand Down

0 comments on commit 24a8b22

Please sign in to comment.