xref: /illumos-gate/usr/src/lib/scsi/libsmp/common/mkerrno.sh (revision 0ccfe5834c3b867c1b6c273cae02ec8922bc0fd2)
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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
25#
26
27echo "\
28/*
29 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
30 */
31
32#include <strings.h>
33#include <scsi/libsmp.h>
34
35static const struct {
36\tchar *name;\t\t/* error name */
37\tchar *msg;\t\t/* error message */
38} _smp_errstr[] = {"
39
40pattern='^	\(ESMP_[A-Z0-9_]*\),*'
41replace='	{ "\1",'
42open='	\/\* '
43openrepl='"'
44close=' \*\/$'
45closerepl='" },'
46
47( sed -n "s/$pattern/$replace/p" | sed -n "s/$open/$openrepl/p" |
48    sed -n "s/$close/$closerepl/p" ) || exit 1
49
50echo "\
51};\n\
52\n\
53static int _smp_nerrno = sizeof (_smp_errstr) /\n\
54    sizeof (_smp_errstr[0]);\n\
55\n\
56const char *
57smp_strerror(smp_errno_t err)
58{
59	return (err < 0 || err >= _smp_nerrno ? \"unknown error\" :
60	     _smp_errstr[err].msg);
61}
62
63const char *
64smp_errname(smp_errno_t err)
65{
66	return (err < 0 || err >= _smp_nerrno ? NULL :
67	     _smp_errstr[err].name);
68}
69
70smp_errno_t
71smp_errcode(const char *name)
72{
73	smp_errno_t err;
74
75	for (err = 0; err < _smp_nerrno; err++) {
76		if (strcmp(name, _smp_errstr[err].name) == 0)
77			return (err);
78	}
79
80	return (ESMP_UNKNOWN);
81}"
82
83exit 0
84