xref: /netbsd-src/external/bsd/openldap/dist/servers/lloadd/value.c (revision afab4e300d3a9fb07dd8c80daf53d0feb3345706)
1 /*	$NetBSD: value.c,v 1.2 2021/08/14 16:14:58 christos Exp $	*/
2 
3 /* value.c - routines for dealing with values */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6  *
7  * Copyright 1998-2021 The OpenLDAP Foundation.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /*
19  * Copyright (c) 1995 Regents of the University of Michigan.
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms are permitted
23  * provided that this notice is preserved and that due credit is given
24  * to the University of Michigan at Ann Arbor. The name of the University
25  * may not be used to endorse or promote products derived from this
26  * software without specific prior written permission. This software
27  * is provided ``as is'' without express or implied warranty.
28  */
29 
30 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: value.c,v 1.2 2021/08/14 16:14:58 christos Exp $");
32 
33 #include "portable.h"
34 
35 #include "lload.h"
36 
37 int
38 value_add_one( BerVarray *vals, struct berval *addval )
39 {
40     int n;
41     BerVarray v2;
42 
43     if ( *vals == NULL ) {
44         *vals = (BerVarray)SLAP_MALLOC( 2 * sizeof(struct berval) );
45         if ( *vals == NULL ) {
46             Debug( LDAP_DEBUG_TRACE, "value_add_one: "
47                     "SLAP_MALLOC failed.\n" );
48             return LBER_ERROR_MEMORY;
49         }
50         n = 0;
51 
52     } else {
53         for ( n = 0; !BER_BVISNULL( &(*vals)[n] ); n++ ) {
54             ; /* Empty */
55         }
56         *vals = (BerVarray)SLAP_REALLOC(
57                 (char *)*vals, ( n + 2 ) * sizeof(struct berval) );
58         if ( *vals == NULL ) {
59             Debug( LDAP_DEBUG_TRACE, "value_add_one: "
60                     "SLAP_MALLOC failed.\n" );
61             return LBER_ERROR_MEMORY;
62         }
63     }
64 
65     v2 = &(*vals)[n];
66     ber_dupbv( v2, addval );
67 
68     v2++;
69     BER_BVZERO( v2 );
70 
71     return LDAP_SUCCESS;
72 }
73