Mercurial > libbuf
comparison buf-sub.c @ 21:939fe74cd80a
buf: switch to int from bool
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 24 Feb 2021 11:39:26 +0100 |
parents | cf8cb4a0729e |
children | d87e84936795 |
comparison
equal
deleted
inserted
replaced
20:08a6d4e6012d | 21:939fe74cd80a |
---|---|
20 #include <stdlib.h> | 20 #include <stdlib.h> |
21 #include <string.h> | 21 #include <string.h> |
22 | 22 |
23 #include "buf.h" | 23 #include "buf.h" |
24 | 24 |
25 bool | 25 int |
26 buf_sub(struct buf *b, const struct buf *src, size_t pos, size_t count) | 26 buf_sub(struct buf *b, const struct buf *src, size_t pos, size_t count) |
27 { | 27 { |
28 assert(b); | 28 assert(b); |
29 assert(src); | 29 assert(src); |
30 assert(pos <= src->length); | 30 assert(pos <= src->length); |
31 | 31 |
32 if (count >= src->length) | 32 if (count >= src->length) |
33 count = src->length - pos; | 33 count = src->length - pos; |
34 if (!(b->data = BUF_MALLOC(count + 1))) | 34 if (!(b->data = BUF_MALLOC(count + 1))) |
35 return false; | 35 return -1; |
36 | 36 |
37 strncpy(b->data, &src->data[pos], count); | 37 strncpy(b->data, &src->data[pos], count); |
38 b->length = count; | 38 b->length = count; |
39 b->capacity = count; | 39 b->capacity = count; |
40 b->data[b->length] = 0; | 40 b->data[b->length] = 0; |
41 | 41 |
42 return true; | 42 return 0; |
43 } | 43 } |