Debian Codegraph @

src/proxy/list.c

raw
1 /*********************************************************************
2 *
3 * Authors: Vincenzo Ciaschini - [email protected]
4 *
5 * Copyright (c) Members of the EGEE Collaboration. 2004-2010.
6 * See http://www.eu-egee.org/partners/ for details on the copyright holders.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 * Parts of this code may be based upon or even include verbatim pieces,
21 * originally written by other people, in which case the original header
22 * follows.
23 *
24 *********************************************************************/
25 #include "config.h"
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 char **listadd(char **vect, char *data)
31 {
32 int i = 0;
33 char **newvect;
34
35 if (!data)
36 return vect;
37
38 if (vect)
39 while (vect[i++]) ;
40 else
41 i=1;
42
43 if ((newvect = (char **)malloc((i+1)*sizeof(char *)))) {
44 if (vect) {
45 memcpy(newvect, vect, (sizeof(char*)*(i-1)));
46 newvect[i-1] = data;
47 newvect[i] = NULL;
48 free(vect);
49 }
50 else {
51 newvect[0] = data;
52 newvect[1] = NULL;
53 }
54 return newvect;
55 }
56 return NULL;
57 }
58
59 void listfree(char **vect, void (*f)(void *))
60 {
61 char **tmp = vect;
62
63 if (tmp) {
64 int i = 0;
65 while (tmp[i])
66 f(tmp[i++]);
67 free(vect);
68 }
69 }