753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER START
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * The contents of this file are subject to the terms of the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Common Development and Distribution License (the "License").
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You may not use this file except in compliance with the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * or http://www.opensolaris.org/os/licensing.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * See the License for the specific language governing permissions
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * and limitations under the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * When distributing Covered Code, include this CDDL HEADER in each
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If applicable, add the following below this CDDL HEADER, with the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fields enclosed by brackets "[]" replaced with your own identifying
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * information: Portions Copyright [yyyy] [name of copyright owner]
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER END
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Use is subject to license terms.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <stdlib.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <string.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <locale.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <libintl.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include "libgrub_errno.h"
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define MAKE_STRING(x) # x
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorestatic const struct {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int ge_num; /* error number */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char *ge_name; /* error name */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char *ge_msg; /* error message */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore} _grub_errstr[] = {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * TRANSLATION_NOTE
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * The following message strings that begin with EG_ do not
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * need to be translated.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define grub_errno_def(num, desc) { num, MAKE_STRING(num), desc},
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include "libgrub_errno.def"
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore};
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define GRUB_ERRNO_INDEX(n) ((n) - (EG_START + 1))
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreconst char *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooregrub_strerror(int err)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore{
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err <= EG_START || err >= EG_END ?
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore strerror(err) :
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore dgettext(TEXT_DOMAIN, _grub_errstr[ GRUB_ERRNO_INDEX(err)].ge_msg));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore}
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreconst char *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooregrub_errname(int err)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore{
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (err <= EG_START || err >= EG_END ?
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore gettext("Not libgrubmgmt specific") :
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore gettext(_grub_errstr[ GRUB_ERRNO_INDEX(err)].ge_name));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore}