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