2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * Define and access error strings for the libpower library
2N/A */
2N/A
2N/A#include <sys/types.h>
2N/A#include <errno.h>
2N/A#include <string.h>
2N/A#include <libintl.h>
2N/A#include <locale.h>
2N/A#include <libscf.h>
2N/A#include <libpower.h>
2N/A
2N/Astatic struct pm_error_info {
2N/A pm_error_t e_code;
2N/A const char *e_desc;
2N/A} pm_errors[] = {
2N/A {PM_SUCCESS, "no error"},
2N/A {PM_ERROR_USAGE, "invalid command line arguments"},
2N/A {PM_ERROR_INVALID_ARGUMENT, "one or more arguments are invalid"},
2N/A {PM_ERROR_INVALID_AUTHORITY, "the specified authority is invalid"},
2N/A {PM_ERROR_INVALID_BOOLEAN,
2N/A "a string could not be converted to a valid boolean"},
2N/A {PM_ERROR_INVALID_INTEGER,
2N/A "a string could not be converted to a valid integer"},
2N/A {PM_ERROR_INVALID_PROPERTY_NAME,
2N/A "one or more property names are invalid"},
2N/A {PM_ERROR_INVALID_PROPERTY_VALUE,
2N/A "one or more property values are invalid"},
2N/A {PM_ERROR_INVALID_TYPE, "an invalid data type was encountered"},
2N/A {PM_ERROR_MISSING_PROPERTY_NAME, "a property name is required"},
2N/A {PM_ERROR_MISSING_PROPERTY_VALUE, "a property value is required"},
2N/A {PM_ERROR_NVLIST, "an internal nvlist error occurred"},
2N/A {PM_ERROR_NOT_SUPPORTED, "operation not supported by pm driver"},
2N/A {PM_ERROR_PROPERTY_NOT_FOUND, "the requested property was not found"},
2N/A {PM_ERROR_PROPERTY_GROUP_NOT_FOUND,
2N/A "a property group name was not found"},
2N/A {PM_ERROR_SCF, "an SCF error occurred"},
2N/A {PM_ERROR_SYSTEM, "an OS error occurred"},
2N/A};
2N/A
2N/A
2N/Aconst char *
2N/Apm_strerror(pm_error_t code)
2N/A{
2N/A const char *result = NULL;
2N/A int i;
2N/A size_t nel;
2N/A
2N/A /* Search the above array for the given pm_error_t */
2N/A nel = sizeof (pm_errors) / sizeof (struct pm_error_info);
2N/A i = 0;
2N/A while (i < nel && pm_errors[i].e_code != code) {
2N/A i++;
2N/A }
2N/A if (i < nel) {
2N/A /* Determine what string to return based on the pm_error_t */
2N/A switch (code) {
2N/A case PM_ERROR_SCF:
2N/A /*
2N/A * The error is in the SMF layer. Get the string from
2N/A * SMF. These are already localized by libscf.
2N/A */
2N/A result = scf_strerror(scf_error());
2N/A break;
2N/A
2N/A case PM_ERROR_NVLIST:
2N/A case PM_ERROR_SYSTEM:
2N/A /*
2N/A * The error is in the system layer. Get the string
2N/A * from the system. These are already localized by
2N/A * the system.
2N/A */
2N/A result = strerror(errno);
2N/A break;
2N/A
2N/A default:
2N/A /*
2N/A * The error is in the libpower layer. Get the
2N/A * localized string.
2N/A */
2N/A result = gettext(pm_errors[i].e_desc);
2N/A break;
2N/A }
2N/A }
2N/A
2N/A return (result);
2N/A}