xref: /titanic_50/usr/src/lib/scsi/libsmp/common/mkerrno.sh (revision ac88567a7a5bb7f01cf22cf366bc9d6203e24d7a)
1*ac88567aSHyon Kim#!/bin/sh
2*ac88567aSHyon Kim#
3*ac88567aSHyon Kim# CDDL HEADER START
4*ac88567aSHyon Kim#
5*ac88567aSHyon Kim# The contents of this file are subject to the terms of the
6*ac88567aSHyon Kim# Common Development and Distribution License (the "License").
7*ac88567aSHyon Kim# You may not use this file except in compliance with the License.
8*ac88567aSHyon Kim#
9*ac88567aSHyon Kim# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*ac88567aSHyon Kim# or http://www.opensolaris.org/os/licensing.
11*ac88567aSHyon Kim# See the License for the specific language governing permissions
12*ac88567aSHyon Kim# and limitations under the License.
13*ac88567aSHyon Kim#
14*ac88567aSHyon Kim# When distributing Covered Code, include this CDDL HEADER in each
15*ac88567aSHyon Kim# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*ac88567aSHyon Kim# If applicable, add the following below this CDDL HEADER, with the
17*ac88567aSHyon Kim# fields enclosed by brackets "[]" replaced with your own identifying
18*ac88567aSHyon Kim# information: Portions Copyright [yyyy] [name of copyright owner]
19*ac88567aSHyon Kim#
20*ac88567aSHyon Kim# CDDL HEADER END
21*ac88567aSHyon Kim#
22*ac88567aSHyon Kim
23*ac88567aSHyon Kim#
24*ac88567aSHyon Kim# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
25*ac88567aSHyon Kim#
26*ac88567aSHyon Kim
27*ac88567aSHyon Kimecho "\
28*ac88567aSHyon Kim/*
29*ac88567aSHyon Kim * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
30*ac88567aSHyon Kim */
31*ac88567aSHyon Kim
32*ac88567aSHyon Kim#pragma ident\t\"@(#)mkerrno.sh\t1.2\t08/07/31\tSMI\"
33*ac88567aSHyon Kim
34*ac88567aSHyon Kim#include <strings.h>
35*ac88567aSHyon Kim#include <scsi/libsmp.h>
36*ac88567aSHyon Kim
37*ac88567aSHyon Kimstatic const struct {
38*ac88567aSHyon Kim\tchar *name;\t\t/* error name */
39*ac88567aSHyon Kim\tchar *msg;\t\t/* error message */
40*ac88567aSHyon Kim} _smp_errstr[] = {"
41*ac88567aSHyon Kim
42*ac88567aSHyon Kimpattern='^	\(ESMP_[A-Z0-9_]*\),*'
43*ac88567aSHyon Kimreplace='	{ "\1",'
44*ac88567aSHyon Kimopen='	\/\* '
45*ac88567aSHyon Kimopenrepl='"'
46*ac88567aSHyon Kimclose=' \*\/$'
47*ac88567aSHyon Kimcloserepl='" },'
48*ac88567aSHyon Kim
49*ac88567aSHyon Kim( sed -n "s/$pattern/$replace/p" | sed -n "s/$open/$openrepl/p" |
50*ac88567aSHyon Kim    sed -n "s/$close/$closerepl/p" ) || exit 1
51*ac88567aSHyon Kim
52*ac88567aSHyon Kimecho "\
53*ac88567aSHyon Kim};\n\
54*ac88567aSHyon Kim\n\
55*ac88567aSHyon Kimstatic int _smp_nerrno = sizeof (_smp_errstr) /\n\
56*ac88567aSHyon Kim    sizeof (_smp_errstr[0]);\n\
57*ac88567aSHyon Kim\n\
58*ac88567aSHyon Kimconst char *
59*ac88567aSHyon Kimsmp_strerror(smp_errno_t err)
60*ac88567aSHyon Kim{
61*ac88567aSHyon Kim	return (err < 0 || err >= _smp_nerrno ? \"unknown error\" :
62*ac88567aSHyon Kim	     _smp_errstr[err].msg);
63*ac88567aSHyon Kim}
64*ac88567aSHyon Kim
65*ac88567aSHyon Kimconst char *
66*ac88567aSHyon Kimsmp_errname(smp_errno_t err)
67*ac88567aSHyon Kim{
68*ac88567aSHyon Kim	return (err < 0 || err >= _smp_nerrno ? NULL :
69*ac88567aSHyon Kim	     _smp_errstr[err].name);
70*ac88567aSHyon Kim}
71*ac88567aSHyon Kim
72*ac88567aSHyon Kimsmp_errno_t
73*ac88567aSHyon Kimsmp_errcode(const char *name)
74*ac88567aSHyon Kim{
75*ac88567aSHyon Kim	smp_errno_t err;
76*ac88567aSHyon Kim
77*ac88567aSHyon Kim	for (err = 0; err < _smp_nerrno; err++) {
78*ac88567aSHyon Kim		if (strcmp(name, _smp_errstr[err].name) == 0)
79*ac88567aSHyon Kim			return (err);
80*ac88567aSHyon Kim	}
81*ac88567aSHyon Kim
82*ac88567aSHyon Kim	return (ESMP_UNKNOWN);
83*ac88567aSHyon Kim}"
84*ac88567aSHyon Kim
85*ac88567aSHyon Kimexit 0
86