]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/strvec.c
xfs: cache last bitmap block in realtime allocator
[thirdparty/xfsprogs-dev.git] / db / strvec.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "libxfs.h"
8 #include "strvec.h"
9 #include "output.h"
10 #include "malloc.h"
11
12 static int count_strvec(char **vec);
13
14 void
15 add_strvec(
16 char ***vecp,
17 char *str)
18 {
19 char *dup;
20 int i;
21 char **vec;
22
23 dup = xstrdup(str);
24 vec = *vecp;
25 i = count_strvec(vec);
26 vec = xrealloc(vec, sizeof(*vec) * (i + 2));
27 vec[i] = dup;
28 vec[i + 1] = NULL;
29 *vecp = vec;
30 }
31
32 char **
33 copy_strvec(
34 char **vec)
35 {
36 int i;
37 char **rval;
38
39 i = count_strvec(vec);
40 rval = new_strvec(i);
41 for (i = 0; vec[i] != NULL; i++)
42 rval[i] = xstrdup(vec[i]);
43 return rval;
44 }
45
46 static int
47 count_strvec(
48 char **vec)
49 {
50 int i;
51
52 for (i = 0; vec[i] != NULL; i++)
53 continue;
54 return i;
55 }
56
57 void
58 free_strvec(
59 char **vec)
60 {
61 int i;
62
63 for (i = 0; vec[i] != NULL; i++)
64 xfree(vec[i]);
65 xfree(vec);
66 }
67
68 char **
69 new_strvec(
70 int count)
71 {
72 char **rval;
73
74 rval = xmalloc(sizeof(*rval) * (count + 1));
75 rval[count] = NULL;
76 return rval;
77 }
78
79 void
80 print_strvec(
81 char **vec)
82 {
83 int i;
84
85 for (i = 0; vec[i] != NULL; i++)
86 dbprintf("%s", vec[i]);
87 }