xref: /titanic_50/usr/src/lib/scsi/libscsi/common/mkerrno.sh (revision 35a5a3587fd94b666239c157d3722745250ccbd7)
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#ident	"%Z%%M%	%I%	%E% SMI"
28
29echo "\
30/*
31 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
32 * Use is subject to license terms.
33 */
34
35#pragma ident\t\"%Z%%M%\t%I%\t%E%\tSMI\"
36
37#include <strings.h>
38#include <scsi/libscsi.h>
39
40static const struct {
41\tchar *name;\t\t/* error name */
42\tchar *msg;\t\t/* error message */
43} _libscsi_errstr[] = {"
44
45pattern='^	\(ESCSI_[A-Z0-9_]*\),*'
46replace='	{ "\1",'
47open='	\/\* '
48openrepl='"'
49close=' \*\/$'
50closerepl='" },'
51
52( sed -n "s/$pattern/$replace/p" | sed -n "s/$open/$openrepl/p" |
53    sed -n "s/$close/$closerepl/p" ) || exit 1
54
55echo "\
56};\n\
57\n\
58static int _libscsi_nerrno = sizeof (_libscsi_errstr) /\n\
59    sizeof (_libscsi_errstr[0]);\n\
60\n\
61const char *
62libscsi_strerror(libscsi_errno_t err)
63{
64	return (err < 0 || err >= _libscsi_nerrno ? \"unknown error\" :
65	     _libscsi_errstr[err].msg);
66}
67
68const char *
69libscsi_errname(libscsi_errno_t err)
70{
71	return (err < 0 || err >= _libscsi_nerrno ? NULL :
72	     _libscsi_errstr[err].name);
73}
74
75libscsi_errno_t
76libscsi_errcode(const char *name)
77{
78	libscsi_errno_t err;
79
80	for (err = 0; err < _libscsi_nerrno; err++) {
81		if (strcmp(name, _libscsi_errstr[err].name) == 0)
82			return (err);
83	}
84
85	return (ESCSI_UNKNOWN);
86}"
87
88exit 0
89