8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libtnf / error.c
blobbad39d7f86f255590617cdc87cb8c186bd1955c5
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include "libtnf.h"
29 #include <libintl.h>
31 #if !defined(TEXT_DOMAIN)
32 #define TEXT_DOMAIN "SYS_TEST"
33 #endif
39 static tnf_error_handler_t *_err_handler = &tnf_default_error_handler;
40 static void *_err_arg = 0;
46 void
47 tnf_set_error_handler(tnf_error_handler_t *handler, void *arg)
49 /* XXX Not MT-safe */
50 _err_arg = arg;
51 _err_handler = handler;
58 void
59 _tnf_error(TNF *tnf, tnf_errcode_t err)
61 (*_err_handler)(_err_arg, tnf, err);
68 char *
69 tnf_error_message(tnf_errcode_t err)
71 if (err == TNF_ERR_NONE)
72 return (dgettext(TEXT_DOMAIN, "no error"));
73 else if (err <= TNF_ERRNO_MAX)
74 return (strerror(err));
75 else {
76 switch (err) {
77 case TNF_ERR_NOTTNF:
78 return (dgettext(TEXT_DOMAIN, "not a TNF file"));
79 case TNF_ERR_BADDATUM:
80 return (dgettext(TEXT_DOMAIN,
81 "operation on bad or NULL data handle"));
82 case TNF_ERR_TYPEMISMATCH:
83 return (dgettext(TEXT_DOMAIN, "type mismatch"));
84 case TNF_ERR_BADINDEX:
85 return (dgettext(TEXT_DOMAIN, "index out of bounds"));
86 case TNF_ERR_BADSLOT:
87 return (dgettext(TEXT_DOMAIN, "no such slot"));
88 case TNF_ERR_BADREFTYPE:
89 return (dgettext(TEXT_DOMAIN, "bad reference type"));
90 case TNF_ERR_ALLOCFAIL:
91 return (dgettext(TEXT_DOMAIN,
92 "memory allocation failure"));
93 case TNF_ERR_BADTNF:
94 return (dgettext(TEXT_DOMAIN, "bad TNF file"));
95 case TNF_ERR_INTERNAL:
96 return (dgettext(TEXT_DOMAIN, "internal error"));
97 default:
98 return (dgettext(TEXT_DOMAIN, "unknown error code"));
107 void
108 /* ARGSUSED */
109 tnf_default_error_handler(void *arg, TNF *tnf, tnf_errcode_t err)
111 fprintf(stderr, dgettext(TEXT_DOMAIN, "error: libtnf: %d: %s\n"),
112 err, tnf_error_message(err));
113 abort();