xref: /titanic_51/usr/src/lib/scsi/libses/common/mkerrno.sh (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1*275c9da8Seschrock#!/bin/sh
2*275c9da8Seschrock#
3*275c9da8Seschrock# CDDL HEADER START
4*275c9da8Seschrock#
5*275c9da8Seschrock# The contents of this file are subject to the terms of the
6*275c9da8Seschrock# Common Development and Distribution License (the "License").
7*275c9da8Seschrock# You may not use this file except in compliance with the License.
8*275c9da8Seschrock#
9*275c9da8Seschrock# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*275c9da8Seschrock# or http://www.opensolaris.org/os/licensing.
11*275c9da8Seschrock# See the License for the specific language governing permissions
12*275c9da8Seschrock# and limitations under the License.
13*275c9da8Seschrock#
14*275c9da8Seschrock# When distributing Covered Code, include this CDDL HEADER in each
15*275c9da8Seschrock# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*275c9da8Seschrock# If applicable, add the following below this CDDL HEADER, with the
17*275c9da8Seschrock# fields enclosed by brackets "[]" replaced with your own identifying
18*275c9da8Seschrock# information: Portions Copyright [yyyy] [name of copyright owner]
19*275c9da8Seschrock#
20*275c9da8Seschrock# CDDL HEADER END
21*275c9da8Seschrock#
22*275c9da8Seschrock
23*275c9da8Seschrock#
24*275c9da8Seschrock# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25*275c9da8Seschrock# Use is subject to license terms.
26*275c9da8Seschrock#
27*275c9da8Seschrock#pragma ident	"%Z%%M%	%I%	%E% SMI"
28*275c9da8Seschrock
29*275c9da8Seschrockecho "/*
30*275c9da8Seschrock * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
31*275c9da8Seschrock * Use is subject to license terms.
32*275c9da8Seschrock */
33*275c9da8Seschrock
34*275c9da8Seschrock#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"
35*275c9da8Seschrock
36*275c9da8Seschrock#include <strings.h>
37*275c9da8Seschrock#include <scsi/libses.h>
38*275c9da8Seschrock
39*275c9da8Seschrockstatic const struct {
40*275c9da8Seschrock\tchar *se_name;\t\t/* error name */
41*275c9da8Seschrock\tchar *se_msg;\t\t/* error message */
42*275c9da8Seschrock} _ses_errstr[] = {"
43*275c9da8Seschrock
44*275c9da8Seschrockpattern='^	\(ESES_[A-Z0-9_]*\),*'
45*275c9da8Seschrockreplace='	{ "\1",'
46*275c9da8Seschrockopen='	\/\* '
47*275c9da8Seschrockopenrepl='"'
48*275c9da8Seschrockclose=' \*\/$'
49*275c9da8Seschrockcloserepl='" },'
50*275c9da8Seschrock
51*275c9da8Seschrock( sed -n "s/$pattern/$replace/p" | sed -n "s/$open/$openrepl/p" |
52*275c9da8Seschrock    sed -n "s/$close/$closerepl/p" ) || exit 1
53*275c9da8Seschrock
54*275c9da8Seschrockecho "\
55*275c9da8Seschrock};\n\
56*275c9da8Seschrock\n\
57*275c9da8Seschrockstatic int _ses_nerrno = sizeof (_ses_errstr) / sizeof (_ses_errstr[0]);\n\
58*275c9da8Seschrock\n\
59*275c9da8Seschrockconst char *
60*275c9da8Seschrockses_strerror(ses_errno_t err)
61*275c9da8Seschrock{
62*275c9da8Seschrock	return (err < 0 || err >= _ses_nerrno ? \"unknown error\" :
63*275c9da8Seschrock	     _ses_errstr[err].se_msg);
64*275c9da8Seschrock}
65*275c9da8Seschrock
66*275c9da8Seschrockconst char *
67*275c9da8Seschrockses_errname(ses_errno_t err)
68*275c9da8Seschrock{
69*275c9da8Seschrock	return (err < 0 || err >= _ses_nerrno ? NULL :
70*275c9da8Seschrock	     _ses_errstr[err].se_name);
71*275c9da8Seschrock}
72*275c9da8Seschrock
73*275c9da8Seschrockses_errno_t
74*275c9da8Seschrockses_errcode(const char *name)
75*275c9da8Seschrock{
76*275c9da8Seschrock	ses_errno_t err;
77*275c9da8Seschrock
78*275c9da8Seschrock	for (err = 0; err < _ses_nerrno; err++) {
79*275c9da8Seschrock		if (strcmp(name, _ses_errstr[err].se_name) == 0)
80*275c9da8Seschrock			return (err);
81*275c9da8Seschrock	}
82*275c9da8Seschrock
83*275c9da8Seschrock	return (ESES_UNKNOWN);
84*275c9da8Seschrock}"
85*275c9da8Seschrock
86*275c9da8Seschrockexit 0
87