xref: /illumos-gate/usr/src/cmd/fm/fminject/common/inj_util.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * 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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <inj.h>
28 #include <inj_err.h>
29 #include <assert.h>
30 
31 const char *
inj_item2str(inj_itemtype_t item)32 inj_item2str(inj_itemtype_t item)
33 {
34 	static const char *const names[] = { "event", "fmri", "auth", "list" };
35 
36 	return (item >= 0 &&
37 	    item < sizeof (names) / sizeof (char *) ? names[item] : "???");
38 }
39 
40 inj_memtype_t
inj_item2mem(inj_itemtype_t item)41 inj_item2mem(inj_itemtype_t item)
42 {
43 	static const inj_memtype_t mems[] = {
44 		MEMTYPE_EVENT, MEMTYPE_FMRI, MEMTYPE_AUTH, MEMTYPE_LIST
45 	};
46 
47 	assert(item >= 0 && item < sizeof (mems) / sizeof (inj_memtype_t));
48 	return (mems[item]);
49 }
50 
51 /*
52  * Convert a *subset* of inj_memtype_t's to inj_itemtype_t's.
53  */
54 inj_itemtype_t
inj_mem2item(inj_memtype_t mem)55 inj_mem2item(inj_memtype_t mem)
56 {
57 	switch (mem) {
58 	case MEMTYPE_EVENT:
59 		return (ITEMTYPE_EVENT);
60 	case MEMTYPE_FMRI:
61 		return (ITEMTYPE_FMRI);
62 	case MEMTYPE_AUTH:
63 		return (ITEMTYPE_AUTH);
64 	case MEMTYPE_LIST:
65 		return (ITEMTYPE_LIST);
66 	default:
67 		return (-1);
68 	}
69 }
70 
71 const char *
inj_mem2str(inj_memtype_t mem)72 inj_mem2str(inj_memtype_t mem)
73 {
74 	static const char *names[] = {
75 		"UNKNOWN",
76 		"int8", "int16", "int32", "int64",
77 		"uint8", "uint16", "uint32", "uint64",
78 		"bool", "string", "enum",
79 		"event", "fmri", "auth"
80 	};
81 
82 	return (mem >= 0 &&
83 	    mem < sizeof (names) / sizeof (char *) ? names[mem] : "???");
84 }
85