inj_util.c (7c478bd9) inj_util.c (7aec1d6e)
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 *

--- 6 unchanged lines hidden (view full) ---

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/*
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 *

--- 6 unchanged lines hidden (view full) ---

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 2004 Sun Microsystems, Inc. All rights reserved.
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident "%Z%%M% %I% %E% SMI"
28
29#include <inj.h>
30#include <inj_err.h>
31#include <assert.h>
32
33const char *
34inj_item2str(inj_itemtype_t item)
35{
24 * Use is subject to license terms.
25 */
26
27#pragma ident "%Z%%M% %I% %E% SMI"
28
29#include <inj.h>
30#include <inj_err.h>
31#include <assert.h>
32
33const char *
34inj_item2str(inj_itemtype_t item)
35{
36 static const char *const names[] = { "event", "fmri", "auth" };
36 static const char *const names[] = { "event", "fmri", "auth", "list" };
37
38 return (item >= 0 &&
39 item < sizeof (names) / sizeof (char *) ? names[item] : "???");
40}
41
42inj_memtype_t
43inj_item2mem(inj_itemtype_t item)
44{
45 static const inj_memtype_t mems[] = {
37
38 return (item >= 0 &&
39 item < sizeof (names) / sizeof (char *) ? names[item] : "???");
40}
41
42inj_memtype_t
43inj_item2mem(inj_itemtype_t item)
44{
45 static const inj_memtype_t mems[] = {
46 MEMTYPE_EVENT, MEMTYPE_FMRI, MEMTYPE_AUTH
46 MEMTYPE_EVENT, MEMTYPE_FMRI, MEMTYPE_AUTH, MEMTYPE_LIST
47 };
48
49 assert(item >= 0 && item < sizeof (mems) / sizeof (inj_memtype_t));
50 return (mems[item]);
51}
52
53/*
54 * Convert a *subset* of inj_memtype_t's to inj_itemtype_t's.
55 */
56inj_itemtype_t
57inj_mem2item(inj_memtype_t mem)
58{
59 switch (mem) {
60 case MEMTYPE_EVENT:
61 return (ITEMTYPE_EVENT);
62 case MEMTYPE_FMRI:
63 return (ITEMTYPE_FMRI);
64 case MEMTYPE_AUTH:
65 return (ITEMTYPE_AUTH);
47 };
48
49 assert(item >= 0 && item < sizeof (mems) / sizeof (inj_memtype_t));
50 return (mems[item]);
51}
52
53/*
54 * Convert a *subset* of inj_memtype_t's to inj_itemtype_t's.
55 */
56inj_itemtype_t
57inj_mem2item(inj_memtype_t mem)
58{
59 switch (mem) {
60 case MEMTYPE_EVENT:
61 return (ITEMTYPE_EVENT);
62 case MEMTYPE_FMRI:
63 return (ITEMTYPE_FMRI);
64 case MEMTYPE_AUTH:
65 return (ITEMTYPE_AUTH);
66 case MEMTYPE_LIST:
67 return (ITEMTYPE_LIST);
66 default:
67 return (-1);
68 }
69}
70
71const char *
72inj_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}
68 default:
69 return (-1);
70 }
71}
72
73const char *
74inj_mem2str(inj_memtype_t mem)
75{
76 static const char *names[] = {
77 "UNKNOWN",
78 "int8", "int16", "int32", "int64",
79 "uint8", "uint16", "uint32", "uint64",
80 "bool", "string", "enum",
81 "event", "fmri", "auth"
82 };
83
84 return (mem >= 0 &&
85 mem < sizeof (names) / sizeof (char *) ? names[mem] : "???");
86}