1*753a6d45SSherry Moore /*
2*753a6d45SSherry Moore  * CDDL HEADER START
3*753a6d45SSherry Moore  *
4*753a6d45SSherry Moore  * The contents of this file are subject to the terms of the
5*753a6d45SSherry Moore  * Common Development and Distribution License (the "License").
6*753a6d45SSherry Moore  * You may not use this file except in compliance with the License.
7*753a6d45SSherry Moore  *
8*753a6d45SSherry Moore  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*753a6d45SSherry Moore  * or http://www.opensolaris.org/os/licensing.
10*753a6d45SSherry Moore  * See the License for the specific language governing permissions
11*753a6d45SSherry Moore  * and limitations under the License.
12*753a6d45SSherry Moore  *
13*753a6d45SSherry Moore  * When distributing Covered Code, include this CDDL HEADER in each
14*753a6d45SSherry Moore  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*753a6d45SSherry Moore  * If applicable, add the following below this CDDL HEADER, with the
16*753a6d45SSherry Moore  * fields enclosed by brackets "[]" replaced with your own identifying
17*753a6d45SSherry Moore  * information: Portions Copyright [yyyy] [name of copyright owner]
18*753a6d45SSherry Moore  *
19*753a6d45SSherry Moore  * CDDL HEADER END
20*753a6d45SSherry Moore  */
21*753a6d45SSherry Moore /*
22*753a6d45SSherry Moore  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*753a6d45SSherry Moore  * Use is subject to license terms.
24*753a6d45SSherry Moore  */
25*753a6d45SSherry Moore 
26*753a6d45SSherry Moore #include <stdlib.h>
27*753a6d45SSherry Moore #include <string.h>
28*753a6d45SSherry Moore #include <locale.h>
29*753a6d45SSherry Moore #include <libintl.h>
30*753a6d45SSherry Moore #include "libgrub_errno.h"
31*753a6d45SSherry Moore 
32*753a6d45SSherry Moore #define	MAKE_STRING(x)	# x
33*753a6d45SSherry Moore 
34*753a6d45SSherry Moore static const struct {
35*753a6d45SSherry Moore 	int	ge_num;		/* error number */
36*753a6d45SSherry Moore 	char	*ge_name;	/* error name */
37*753a6d45SSherry Moore 	char	*ge_msg;	/* error message */
38*753a6d45SSherry Moore } _grub_errstr[] = {
39*753a6d45SSherry Moore /*
40*753a6d45SSherry Moore  * TRANSLATION_NOTE
41*753a6d45SSherry Moore  * The following message strings that begin with EG_ do not
42*753a6d45SSherry Moore  * need to be translated.
43*753a6d45SSherry Moore  */
44*753a6d45SSherry Moore #define	grub_errno_def(num, desc)	{ num,	MAKE_STRING(num),	desc},
45*753a6d45SSherry Moore #include "libgrub_errno.def"
46*753a6d45SSherry Moore };
47*753a6d45SSherry Moore 
48*753a6d45SSherry Moore #define	GRUB_ERRNO_INDEX(n)	((n) - (EG_START + 1))
49*753a6d45SSherry Moore 
50*753a6d45SSherry Moore const char *
grub_strerror(int err)51*753a6d45SSherry Moore grub_strerror(int err)
52*753a6d45SSherry Moore {
53*753a6d45SSherry Moore 	return (err <= EG_START || err >= EG_END ?
54*753a6d45SSherry Moore 	    strerror(err) :
55*753a6d45SSherry Moore 	    dgettext(TEXT_DOMAIN, _grub_errstr[ GRUB_ERRNO_INDEX(err)].ge_msg));
56*753a6d45SSherry Moore }
57*753a6d45SSherry Moore 
58*753a6d45SSherry Moore const char *
grub_errname(int err)59*753a6d45SSherry Moore grub_errname(int err)
60*753a6d45SSherry Moore {
61*753a6d45SSherry Moore 	return (err <= EG_START || err >= EG_END ?
62*753a6d45SSherry Moore 	    gettext("Not libgrubmgmt specific") :
63*753a6d45SSherry Moore 	    gettext(_grub_errstr[ GRUB_ERRNO_INDEX(err)].ge_name));
64*753a6d45SSherry Moore }