Mercurial > libbuf
annotate buf-puts.c @ 14:1297027290b9
misc: add CHANGES.md
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 16 Dec 2020 15:41:26 +0100 |
parents | 3e1c384e0d3f |
children | 939fe74cd80a |
rev | line source |
---|---|
0 | 1 /* |
2 * buf-puts.c -- simple string buffer for C | |
3 * | |
4 * Copyright (c) 2019-2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <assert.h> | |
20 #include <string.h> | |
21 | |
22 #include "buf.h" | |
23 #include "buf-int.h" | |
24 | |
25 bool | |
26 buf_puts(struct buf *b, const char *s) | |
27 { | |
28 assert(b); | |
29 assert(s); | |
30 | |
31 const size_t len = strlen(s); | |
32 | |
33 if (!_buf_grow(b, len)) | |
34 return false; | |
35 | |
13
3e1c384e0d3f
buf_puts: uses memcpy as it may be optimized
David Demelier <markand@malikania.fr>
parents:
0
diff
changeset
|
36 memcpy(&b->data[b->length], s, len + 1); |
0 | 37 b->length += len; |
38 | |
39 return true; | |
40 } |