Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / lib / scsi / libsmp / common / mkerrno.sh
blob3351c1d32d603fa39a80f1556fb43da13759eaaf
1 #!/bin/sh
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
27 echo "\
29 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
32 #pragma ident\t\"@(#)mkerrno.sh\t1.2\t08/07/31\tSMI\"
34 #include <strings.h>
35 #include <scsi/libsmp.h>
37 static const struct {
38 \tchar *name;\t\t/* error name */
39 \tchar *msg;\t\t/* error message */
40 } _smp_errstr[] = {"
42 pattern='^ \(ESMP_[A-Z0-9_]*\),*'
43 replace=' { "\1",'
44 open=' \/\* '
45 openrepl='"'
46 close=' \*\/$'
47 closerepl='" },'
49 ( sed -n "s/$pattern/$replace/p" | sed -n "s/$open/$openrepl/p" |
50 sed -n "s/$close/$closerepl/p" ) || exit 1
52 echo "\
53 };\n\
54 \n\
55 static int _smp_nerrno = sizeof (_smp_errstr) /\n\
56 sizeof (_smp_errstr[0]);\n\
57 \n\
58 const char *
59 smp_strerror(smp_errno_t err)
61 return (err < 0 || err >= _smp_nerrno ? \"unknown error\" :
62 _smp_errstr[err].msg);
65 const char *
66 smp_errname(smp_errno_t err)
68 return (err < 0 || err >= _smp_nerrno ? NULL :
69 _smp_errstr[err].name);
72 smp_errno_t
73 smp_errcode(const char *name)
75 smp_errno_t err;
77 for (err = 0; err < _smp_nerrno; err++) {
78 if (strcmp(name, _smp_errstr[err].name) == 0)
79 return (err);
82 return (ESMP_UNKNOWN);
85 exit 0