1*54925bf6Swillf /*
2*54925bf6Swillf  * kadmin/ldap_util/kdb5_ldap_list.c
3*54925bf6Swillf  */
4*54925bf6Swillf 
5*54925bf6Swillf /* Copyright (c) 2004-2005, Novell, Inc.
6*54925bf6Swillf  * All rights reserved.
7*54925bf6Swillf  *
8*54925bf6Swillf  * Redistribution and use in source and binary forms, with or without
9*54925bf6Swillf  * modification, are permitted provided that the following conditions are met:
10*54925bf6Swillf  *
11*54925bf6Swillf  *   * Redistributions of source code must retain the above copyright notice,
12*54925bf6Swillf  *       this list of conditions and the following disclaimer.
13*54925bf6Swillf  *   * Redistributions in binary form must reproduce the above copyright
14*54925bf6Swillf  *       notice, this list of conditions and the following disclaimer in the
15*54925bf6Swillf  *       documentation and/or other materials provided with the distribution.
16*54925bf6Swillf  *   * The copyright holder's name is not used to endorse or promote products
17*54925bf6Swillf  *       derived from this software without specific prior written permission.
18*54925bf6Swillf  *
19*54925bf6Swillf  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20*54925bf6Swillf  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*54925bf6Swillf  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*54925bf6Swillf  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23*54925bf6Swillf  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*54925bf6Swillf  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*54925bf6Swillf  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*54925bf6Swillf  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*54925bf6Swillf  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*54925bf6Swillf  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*54925bf6Swillf  * POSSIBILITY OF SUCH DAMAGE.
30*54925bf6Swillf  */
31*54925bf6Swillf 
32*54925bf6Swillf /*
33*54925bf6Swillf  * Miscellaneous functions for managing the string and integer lists
34*54925bf6Swillf  */
35*54925bf6Swillf 
36*54925bf6Swillf #include <k5-int.h>
37*54925bf6Swillf #include "kdb5_ldap_list.h"
38*54925bf6Swillf 
39*54925bf6Swillf /*
40*54925bf6Swillf  * Counts the number of entries in the given array of strings
41*54925bf6Swillf  */
list_count_str_array(char ** list)42*54925bf6Swillf int list_count_str_array(char **list)
43*54925bf6Swillf {
44*54925bf6Swillf     int i = 0;
45*54925bf6Swillf 
46*54925bf6Swillf     if (list == NULL)
47*54925bf6Swillf 	return 0;
48*54925bf6Swillf 
49*54925bf6Swillf     for (i = 0; *list != NULL; list++) {
50*54925bf6Swillf 	i++;
51*54925bf6Swillf     }
52*54925bf6Swillf 
53*54925bf6Swillf     return i;
54*54925bf6Swillf }
55*54925bf6Swillf 
56*54925bf6Swillf 
57*54925bf6Swillf /*
58*54925bf6Swillf  * Counts the number of entries in the given array of integers
59*54925bf6Swillf  */
list_count_int_array(int * list)60*54925bf6Swillf int list_count_int_array(int *list)
61*54925bf6Swillf {
62*54925bf6Swillf     int i = 0;
63*54925bf6Swillf 
64*54925bf6Swillf     if (list == NULL)
65*54925bf6Swillf 	return 0;
66*54925bf6Swillf 
67*54925bf6Swillf     for (i = 0; *list != END_OF_LIST; list++) {
68*54925bf6Swillf 	i++;
69*54925bf6Swillf     }
70*54925bf6Swillf 
71*54925bf6Swillf     return i;
72*54925bf6Swillf }
73*54925bf6Swillf 
74*54925bf6Swillf 
75*54925bf6Swillf /*
76*54925bf6Swillf  * Frees the entries in a given list and not the list pointer
77*54925bf6Swillf  */
krb5_free_list_entries(list)78*54925bf6Swillf void krb5_free_list_entries(list)
79*54925bf6Swillf     char **list;
80*54925bf6Swillf {
81*54925bf6Swillf     if (list == NULL)
82*54925bf6Swillf 	return;
83*54925bf6Swillf     for (; *list != NULL; list++) {
84*54925bf6Swillf 	free(*list);
85*54925bf6Swillf 	*list = NULL;
86*54925bf6Swillf     }
87*54925bf6Swillf 
88*54925bf6Swillf     return;
89*54925bf6Swillf }
90*54925bf6Swillf 
91