]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getvalues.c
Happy New Year!
[openldap] / libraries / libldap / getvalues.c
index 954397e9d1ada3c0440f3675b40ccbb43e0d13a0..cc09462816f3596867e6ceb666e215a0f251260d 100644 (file)
@@ -1,13 +1,19 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
- */
-/*  Portions
- *  Copyright (c) 1990 Regents of the University of Michigan.
- *  All rights reserved.
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2005 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
  *
- *  getvalues.c
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1990 Regents of the University of Michigan.
+ * All rights reserved.
  */
 
 #include "portable.h"
@@ -167,3 +173,39 @@ ldap_value_free_len( struct berval **vals )
 {
        ber_bvecfree( vals );
 }
+
+char **
+ldap_value_dup( char *const *vals )
+{
+       char **new;
+       int i;
+
+       if( vals == NULL ) {
+               return NULL;
+       }
+
+       for( i=0; vals[i]; i++ ) {
+               ;   /* Count the number of values */
+       }
+
+       if( i == 0 ) {
+               return NULL;
+       }
+
+       new = LDAP_MALLOC( (i+1)*sizeof(char *) );  /* Alloc array of pointers */
+       if( new == NULL ) {
+               return NULL;
+       }
+
+       for( i=0; vals[i]; i++ ) {
+               new[i] = LDAP_STRDUP( vals[i] );   /* Dup each value */
+               if( new[i] == NULL ) {
+                       LDAP_VFREE( new );
+                       return NULL;
+               }
+       }
+       new[i] = NULL;
+
+       return new;
+}
+