xref: /illumos-gate/usr/src/cmd/fm/fmd/common/mkerror.sh (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28input="`cat`"
29[ -z "$input" ] && exit 1
30
31echo "\
32/*\n\
33 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.\n\
34 * Use is subject to license terms.\n\
35 */\n\
36\n\
37#include <strings.h>
38#include <fmd_error.h>
39\n\
40static const char *const _fmd_ereports[] = {"
41
42pattern='^[ ]*EFMD_\([A-Z0-9_]*\).*,*'
43replace='	"ereport.fm.fmd.\1",'
44
45echo "$input" | sed -n "s/$pattern/$replace/p" | tr '[A-Z]' '[a-z]' || exit 1
46
47echo "\
48};\n\
49\n\
50static const char *const _fmd_errstrs[] = {"
51
52pattern='^[ ]*EFMD_[A-Z0-9_]*.*\* \(.*\) \*.*'
53replace='	"\1",'
54
55echo "$input" | sed -n "s/$pattern/$replace/p" || exit 1
56
57echo "\
58};\n\
59\n\
60static const int _fmd_nereports =\n\
61    sizeof (_fmd_ereports) / sizeof (_fmd_ereports[0]);\n\
62\n\
63static const int _fmd_nerrstrs =\n\
64    sizeof (_fmd_errstrs) / sizeof (_fmd_errstrs[0]);\n\
65\n\
66const char *
67fmd_errclass(int err)
68{
69	const char *c;
70
71	if (err >= EFMD_UNKNOWN && (err - EFMD_UNKNOWN) < _fmd_nereports)
72		c = _fmd_ereports[err - EFMD_UNKNOWN];
73	else
74		c = _fmd_ereports[0];
75
76	return (c);
77}
78
79const char *
80fmd_strerror(int err)
81{
82	const char *s;
83
84	if (err >= EFMD_UNKNOWN && (err - EFMD_UNKNOWN) < _fmd_nerrstrs)
85		s = _fmd_errstrs[err - EFMD_UNKNOWN];
86	else if (err < 0 || (s = strerror(err)) == NULL)
87		s = _fmd_errstrs[0];
88
89	return (s);
90}
91
92int
93fmd_set_errno(int err)
94{
95	errno = err;
96	return (-1);
97}"
98
99exit 0
100