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
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]
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
31 #if !defined(TEXT_DOMAIN)
32 #define TEXT_DOMAIN "SYS_TEST"
39 static tnf_error_handler_t
*_err_handler
= &tnf_default_error_handler
;
40 static void *_err_arg
= 0;
47 tnf_set_error_handler(tnf_error_handler_t
*handler
, void *arg
)
51 _err_handler
= handler
;
59 _tnf_error(TNF
*tnf
, tnf_errcode_t err
)
61 (*_err_handler
)(_err_arg
, tnf
, err
);
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
));
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"));
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"));
94 return (dgettext(TEXT_DOMAIN
, "bad TNF file"));
95 case TNF_ERR_INTERNAL
:
96 return (dgettext(TEXT_DOMAIN
, "internal error"));
98 return (dgettext(TEXT_DOMAIN
, "unknown error code"));
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
));