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