Skip to content

Commit a9746b3

Browse files
committed
strarray: move to its own file
1 parent 629515a commit a9746b3

File tree

2 files changed

+56
-46
lines changed

2 files changed

+56
-46
lines changed

src/strarray.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
#include "util.h"
9+
10+
#include "common.h"
11+
12+
int git_strarray_copy(git_strarray *tgt, const git_strarray *src)
13+
{
14+
size_t i;
15+
16+
assert(tgt && src);
17+
18+
memset(tgt, 0, sizeof(*tgt));
19+
20+
if (!src->count)
21+
return 0;
22+
23+
tgt->strings = git__calloc(src->count, sizeof(char *));
24+
GIT_ERROR_CHECK_ALLOC(tgt->strings);
25+
26+
for (i = 0; i < src->count; ++i) {
27+
if (!src->strings[i])
28+
continue;
29+
30+
tgt->strings[tgt->count] = git__strdup(src->strings[i]);
31+
if (!tgt->strings[tgt->count]) {
32+
git_strarray_free(tgt);
33+
memset(tgt, 0, sizeof(*tgt));
34+
return -1;
35+
}
36+
37+
tgt->count++;
38+
}
39+
40+
return 0;
41+
}
42+
43+
void git_strarray_free(git_strarray *array)
44+
{
45+
size_t i;
46+
47+
if (array == NULL)
48+
return;
49+
50+
for (i = 0; i < array->count; ++i)
51+
git__free(array->strings[i]);
52+
53+
git__free(array->strings);
54+
55+
memset(array, 0, sizeof(*array));
56+
}

src/util.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,6 @@
2222
# include <Shlwapi.h>
2323
#endif
2424

25-
void git_strarray_free(git_strarray *array)
26-
{
27-
size_t i;
28-
29-
if (array == NULL)
30-
return;
31-
32-
for (i = 0; i < array->count; ++i)
33-
git__free(array->strings[i]);
34-
35-
git__free(array->strings);
36-
37-
memset(array, 0, sizeof(*array));
38-
}
39-
40-
int git_strarray_copy(git_strarray *tgt, const git_strarray *src)
41-
{
42-
size_t i;
43-
44-
assert(tgt && src);
45-
46-
memset(tgt, 0, sizeof(*tgt));
47-
48-
if (!src->count)
49-
return 0;
50-
51-
tgt->strings = git__calloc(src->count, sizeof(char *));
52-
GIT_ERROR_CHECK_ALLOC(tgt->strings);
53-
54-
for (i = 0; i < src->count; ++i) {
55-
if (!src->strings[i])
56-
continue;
57-
58-
tgt->strings[tgt->count] = git__strdup(src->strings[i]);
59-
if (!tgt->strings[tgt->count]) {
60-
git_strarray_free(tgt);
61-
memset(tgt, 0, sizeof(*tgt));
62-
return -1;
63-
}
64-
65-
tgt->count++;
66-
}
67-
68-
return 0;
69-
}
70-
7125
int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const char **endptr, int base)
7226
{
7327
const char *p;

0 commit comments

Comments
 (0)