diff options
author | Lukas Fleischer | 2013-11-22 13:24:52 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2014-01-08 14:59:38 +0100 |
commit | 9973ef0207d21535a05610ca50d9f45c7c56c758 (patch) | |
tree | b6049b899f23d7447ee39077f80e2dd2f86d3d2b /vector.c | |
parent | e21da6c2a6ffcd8b4a2b2b06cf7486f36f291a5b (diff) | |
download | cgit-9973ef0207d21535a05610ca50d9f45c7c56c758.tar.gz cgit-9973ef0207d21535a05610ca50d9f45c7c56c758.tar.bz2 cgit-9973ef0207d21535a05610ca50d9f45c7c56c758.zip |
Use argv_array in place of vector
Instead of using our own vector implementation, use argv_array from Git
which has been specifically designed for dynamic size argv arrays.
Drop vector.h and vector.c which are no longer needed.
Signed-off-by: Lukas Fleischer <[email protected]>
Diffstat (limited to 'vector.c')
-rw-r--r-- | vector.c | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/vector.c b/vector.c deleted file mode 100644 index 0863908..0000000 --- a/vector.c +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <string.h> | ||
3 | #include <errno.h> | ||
4 | #include "vector.h" | ||
5 | |||
6 | static int grow(struct vector *vec, int gently) | ||
7 | { | ||
8 | size_t new_alloc; | ||
9 | void *new_data; | ||
10 | |||
11 | new_alloc = vec->alloc * 3 / 2; | ||
12 | if (!new_alloc) | ||
13 | new_alloc = 8; | ||
14 | new_data = realloc(vec->data, new_alloc * vec->size); | ||
15 | if (!new_data) { | ||
16 | if (gently) | ||
17 | return ENOMEM; | ||
18 | perror("vector.c:grow()"); | ||
19 | exit(1); | ||
20 | } | ||
21 | vec->data = new_data; | ||
22 | vec->alloc = new_alloc; | ||
23 | return 0; | ||
24 | } | ||
25 | |||
26 | int vector_push(struct vector *vec, const void *data, int gently) | ||
27 | { | ||
28 | int rc; | ||
29 | |||
30 | if (vec->count == vec->alloc && (rc = grow(vec, gently))) | ||
31 | return rc; | ||
32 | if (data) | ||
33 | memmove(vec->data + vec->count * vec->size, data, vec->size); | ||
34 | else | ||
35 | memset(vec->data + vec->count * vec->size, 0, vec->size); | ||
36 | vec->count++; | ||
37 | return 0; | ||
38 | } | ||