]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/strvec.c
Undoes mod: xfs-cmds:slinx:120772a
[thirdparty/xfsprogs-dev.git] / db / strvec.c
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33 #include <libxfs.h>
34 #include "strvec.h"
35 #include "output.h"
36 #include "malloc.h"
37
38 static int count_strvec(char **vec);
39
40 void
41 add_strvec(
42 char ***vecp,
43 char *str)
44 {
45 char *dup;
46 int i;
47 char **vec;
48
49 dup = xstrdup(str);
50 vec = *vecp;
51 i = count_strvec(vec);
52 vec = xrealloc(vec, sizeof(*vec) * (i + 2));
53 vec[i] = dup;
54 vec[i + 1] = NULL;
55 *vecp = vec;
56 }
57
58 char **
59 copy_strvec(
60 char **vec)
61 {
62 int i;
63 char **rval;
64
65 i = count_strvec(vec);
66 rval = new_strvec(i);
67 for (i = 0; vec[i] != NULL; i++)
68 rval[i] = xstrdup(vec[i]);
69 return rval;
70 }
71
72 static int
73 count_strvec(
74 char **vec)
75 {
76 int i;
77
78 for (i = 0; vec[i] != NULL; i++)
79 continue;
80 return i;
81 }
82
83 void
84 free_strvec(
85 char **vec)
86 {
87 int i;
88
89 for (i = 0; vec[i] != NULL; i++)
90 xfree(vec[i]);
91 xfree(vec);
92 }
93
94 char **
95 new_strvec(
96 int count)
97 {
98 char **rval;
99
100 rval = xmalloc(sizeof(*rval) * (count + 1));
101 rval[count] = NULL;
102 return rval;
103 }
104
105 void
106 print_strvec(
107 char **vec)
108 {
109 int i;
110
111 for (i = 0; vec[i] != NULL; i++)
112 dbprintf("%s", vec[i]);
113 }