xref: /illumos-gate/usr/src/lib/scsi/libses/common/mkerrno.sh (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
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
28*275c9da8Seschrockecho "/*
29*275c9da8Seschrock * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
30*275c9da8Seschrock * Use is subject to license terms.
31*275c9da8Seschrock */
32*275c9da8Seschrock
33*275c9da8Seschrock#include <strings.h>
34*275c9da8Seschrock#include <scsi/libses.h>
35*275c9da8Seschrock
36*275c9da8Seschrockstatic const struct {
37*275c9da8Seschrock\tchar *se_name;\t\t/* error name */
38*275c9da8Seschrock\tchar *se_msg;\t\t/* error message */
39*275c9da8Seschrock} _ses_errstr[] = {"
40*275c9da8Seschrock
41*275c9da8Seschrockpattern='^	\(ESES_[A-Z0-9_]*\),*'
42*275c9da8Seschrockreplace='	{ "\1",'
43*275c9da8Seschrockopen='	\/\* '
44*275c9da8Seschrockopenrepl='"'
45*275c9da8Seschrockclose=' \*\/$'
46*275c9da8Seschrockcloserepl='" },'
47*275c9da8Seschrock
48*275c9da8Seschrock( sed -n "s/$pattern/$replace/p" | sed -n "s/$open/$openrepl/p" |
49*275c9da8Seschrock    sed -n "s/$close/$closerepl/p" ) || exit 1
50*275c9da8Seschrock
51*275c9da8Seschrockecho "\
52*275c9da8Seschrock};\n\
53*275c9da8Seschrock\n\
54*275c9da8Seschrockstatic int _ses_nerrno = sizeof (_ses_errstr) / sizeof (_ses_errstr[0]);\n\
55*275c9da8Seschrock\n\
56*275c9da8Seschrockconst char *
57*275c9da8Seschrockses_strerror(ses_errno_t err)
58*275c9da8Seschrock{
59*275c9da8Seschrock	return (err < 0 || err >= _ses_nerrno ? \"unknown error\" :
60*275c9da8Seschrock	     _ses_errstr[err].se_msg);
61*275c9da8Seschrock}
62*275c9da8Seschrock
63*275c9da8Seschrockconst char *
64*275c9da8Seschrockses_errname(ses_errno_t err)
65*275c9da8Seschrock{
66*275c9da8Seschrock	return (err < 0 || err >= _ses_nerrno ? NULL :
67*275c9da8Seschrock	     _ses_errstr[err].se_name);
68*275c9da8Seschrock}
69*275c9da8Seschrock
70*275c9da8Seschrockses_errno_t
71*275c9da8Seschrockses_errcode(const char *name)
72*275c9da8Seschrock{
73*275c9da8Seschrock	ses_errno_t err;
74*275c9da8Seschrock
75*275c9da8Seschrock	for (err = 0; err < _ses_nerrno; err++) {
76*275c9da8Seschrock		if (strcmp(name, _ses_errstr[err].se_name) == 0)
77*275c9da8Seschrock			return (err);
78*275c9da8Seschrock	}
79*275c9da8Seschrock
80*275c9da8Seschrock	return (ESES_UNKNOWN);
81*275c9da8Seschrock}"
82*275c9da8Seschrock
83*275c9da8Seschrockexit 0
84