8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libsldap / common / ns_error.c
blob1a81cccf1117cdee60d1385ecff3e7c739335bb4
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <stdlib.h>
27 #include <libintl.h>
28 #include "ns_sldap.h"
29 #include "ns_internal.h"
31 struct ns_ldaperror {
32 int e_code;
33 char *e_reason;
36 static mutex_t ns_error_lock = DEFAULTMUTEX;
37 static boolean_t error_inited = B_FALSE;
39 static struct ns_ldaperror ns_ldap_errlist[] = {
40 {NS_LDAP_SUCCESS, NULL},
41 {NS_LDAP_OP_FAILED, NULL},
42 {NS_LDAP_NOTFOUND, NULL},
43 {NS_LDAP_MEMORY, NULL},
44 {NS_LDAP_CONFIG, NULL},
45 {NS_LDAP_PARTIAL, NULL},
46 {NS_LDAP_INTERNAL, NULL},
47 {NS_LDAP_INVALID_PARAM, NULL},
48 {-1, NULL}
52 static void
53 ns_ldaperror_init()
55 int i = 0;
57 (void) mutex_lock(&ns_error_lock);
58 if (!error_inited) {
59 ns_ldap_errlist[i++].e_reason = gettext("Success");
60 ns_ldap_errlist[i++].e_reason = gettext("Operation failed");
61 ns_ldap_errlist[i++].e_reason = gettext("Object not found");
62 ns_ldap_errlist[i++].e_reason = gettext("Memory failure");
63 ns_ldap_errlist[i++].e_reason =
64 gettext("LDAP configuration problem");
65 ns_ldap_errlist[i++].e_reason = gettext("Partial result");
66 ns_ldap_errlist[i++].e_reason = gettext("LDAP error");
67 ns_ldap_errlist[i++].e_reason = gettext("Invalid parameter");
68 ns_ldap_errlist[i++].e_reason = gettext("Unknown error");
69 error_inited = B_TRUE;
71 (void) mutex_unlock(&ns_error_lock);
75 int
76 __ns_ldap_err2str(int err, char **strmsg)
78 int i;
80 if (!error_inited)
81 ns_ldaperror_init();
83 for (i = 0; (ns_ldap_errlist[i].e_code != err) &&
84 (ns_ldap_errlist[i].e_code != -1); i++) {
85 /* empty for loop */
87 *strmsg = ns_ldap_errlist[i].e_reason;
88 return (NS_LDAP_SUCCESS);
92 int
93 __ns_ldap_freeError(ns_ldap_error_t **errorp)
95 ns_ldap_error_t *err;
97 if (errorp == NULL || *errorp == NULL)
98 return (NS_LDAP_SUCCESS);
100 err = *errorp;
101 if (err->message)
102 free(err->message);
104 free(err);
105 *errorp = NULL;
106 return (NS_LDAP_SUCCESS);