|
|
@ -22,21 +22,22 @@ f2b_buf_free(f2b_buf_t *buf) { |
|
|
|
memset(buf, 0x0, sizeof(f2b_buf_t)); |
|
|
|
memset(buf, 0x0, sizeof(f2b_buf_t)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
size_t |
|
|
|
f2b_buf_append(f2b_buf_t *buf, const char *str, size_t len) { |
|
|
|
f2b_buf_append(f2b_buf_t *buf, const char *str, size_t len) { |
|
|
|
|
|
|
|
|
|
|
|
assert(buf != NULL); |
|
|
|
assert(buf != NULL); |
|
|
|
assert(str != NULL); |
|
|
|
assert(str != NULL); |
|
|
|
|
|
|
|
|
|
|
|
if (len == 0) |
|
|
|
if (len == 0) |
|
|
|
len = strlen(str); |
|
|
|
len = strlen(str); |
|
|
|
if (buf->size < (buf->used + len)) |
|
|
|
if ((buf->used + len) > buf->size) { |
|
|
|
return false; /* not enough space */ |
|
|
|
/* not enough space, append as much as possible */ |
|
|
|
|
|
|
|
len = buf->size - buf->used; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
memcpy(&buf->data[buf->used], str, len); |
|
|
|
memcpy(&buf->data[buf->used], str, len); |
|
|
|
buf->used += len; |
|
|
|
buf->used += len; |
|
|
|
buf->data[buf->used] = '\0'; |
|
|
|
buf->data[buf->used] = '\0'; |
|
|
|
return true; |
|
|
|
return len; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|