]>
git.proxmox.com Git - libgit2.git/blob - src/strarray.c
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
12 int git_strarray_copy(git_strarray
*tgt
, const git_strarray
*src
)
19 memset(tgt
, 0, sizeof(*tgt
));
24 tgt
->strings
= git__calloc(src
->count
, sizeof(char *));
25 GIT_ERROR_CHECK_ALLOC(tgt
->strings
);
27 for (i
= 0; i
< src
->count
; ++i
) {
31 tgt
->strings
[tgt
->count
] = git__strdup(src
->strings
[i
]);
32 if (!tgt
->strings
[tgt
->count
]) {
33 git_strarray_dispose(tgt
);
34 memset(tgt
, 0, sizeof(*tgt
));
44 void git_strarray_dispose(git_strarray
*array
)
51 for (i
= 0; i
< array
->count
; ++i
)
52 git__free(array
->strings
[i
]);
54 git__free(array
->strings
);
56 memset(array
, 0, sizeof(*array
));
59 #ifndef GIT_DEPRECATE_HARD
60 void git_strarray_free(git_strarray
*array
)
62 git_strarray_dispose(array
);