xref: /titanic_51/usr/src/cmd/sgs/libconv/common/group.c (revision 821da340f9590922ba8761a64fadda18843a0e88)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include	<string.h>
29 #include	"rtld.h"
30 #include	"_conv.h"
31 #include	"group_msg.h"
32 
33 #define	HDLSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
34 		MSG_GPH_ZERO_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
35 		MSG_GPH_LDSO_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
36 		MSG_GPH_FIRST_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
37 		MSG_GPH_PARENT_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
38 		MSG_GPH_FILTEE_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
39 		MSG_GPH_INITIAL_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
40 		CONV_INV_BUFSIZE	+ CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
41 
42 /*
43  * Ensure that Conv_grphdl_flags_buf_t is large enough:
44  *
45  * HDLSZ is the real minimum size of the buffer required by conv_grphdl_flags().
46  * However, Conv_grphdl_flags_buf_t uses CONV_GRPHDL_FLAGS_BUFSIZE to set the
47  * buffer size. We do things this way because the definition of HDLSZ uses
48  * information that is not available in the environment of other programs
49  * that include the conv.h header file.
50  */
51 #if (CONV_GRPHDL_FLAGS_BUFSIZE < HDLSZ) && !defined(__lint)
52 #error "CONV_GRPHDL_FLAGS_BUFSIZE is not large enough"
53 #endif
54 
55 /*
56  * String conversion routine for Grp_hdl flags.
57  */
58 const char *
59 conv_grphdl_flags(uint_t flags, Conv_grphdl_flags_buf_t *grphdl_flags_buf)
60 {
61 	static Val_desc vda[] = {
62 		{ GPH_ZERO,		MSG_ORIG(MSG_GPH_ZERO) },
63 		{ GPH_LDSO,		MSG_ORIG(MSG_GPH_LDSO) },
64 		{ GPH_FIRST,		MSG_ORIG(MSG_GPH_FIRST) },
65 		{ GPH_PARENT,		MSG_ORIG(MSG_GPH_PARENT) },
66 		{ GPH_FILTEE,		MSG_ORIG(MSG_GPH_FILTEE) },
67 		{ GPH_INITIAL,		MSG_ORIG(MSG_GPH_INITIAL) },
68 		{ 0,			0 }
69 	};
70 	static CONV_EXPN_FIELD_ARG conv_arg = {
71 	    NULL, sizeof (grphdl_flags_buf->buf), vda };
72 
73 	if (flags == 0)
74 		return (MSG_ORIG(MSG_GBL_NULL));
75 
76 	conv_arg.buf = grphdl_flags_buf->buf;
77 	conv_arg.oflags = conv_arg.rflags = flags;
78 	(void) conv_expn_field(&conv_arg);
79 
80 	return ((const char *)grphdl_flags_buf->buf);
81 }
82 
83 #define	DESCSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
84 		MSG_GPD_DLSYM_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
85 		MSG_GPD_RELOC_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
86 		MSG_GPD_ADDEPS_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
87 		MSG_GPD_PARENT_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
88 		MSG_GPD_FILTER_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
89 		MSG_GPD_REMOVE_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
90 		CONV_INV_BUFSIZE	+ CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
91 
92 /*
93  * Ensure that Conv_grpdesc_flags_buf_t is large enough:
94  *
95  * DESCSZ is the real min size of the buffer required by conv_grpdesc_flags().
96  * However, Conv_grpdesc_flags_buf_t uses CONV_GRPDESC_FLAGS_BUFSIZE to set the
97  * buffer size. We do things this way because the definition of DESCSZ uses
98  * information that is not available in the environment of other programs
99  * that include the conv.h header file.
100  */
101 #if (CONV_GRPDESC_FLAGS_BUFSIZE < DESCSZ) && !defined(__lint)
102 #error "CONV_GRPDESC_FLAGS_BUFSIZE is not large enough"
103 #endif
104 
105 /*
106  * String conversion routine for Grp_desc flags.
107  */
108 const char *
109 conv_grpdesc_flags(uint_t flags, Conv_grpdesc_flags_buf_t *grpdesc_flags_buf)
110 {
111 	static Val_desc vda[] = {
112 		{ GPD_DLSYM,		MSG_ORIG(MSG_GPD_DLSYM) },
113 		{ GPD_RELOC,		MSG_ORIG(MSG_GPD_RELOC) },
114 		{ GPD_ADDEPS,		MSG_ORIG(MSG_GPD_ADDEPS) },
115 		{ GPD_PARENT,		MSG_ORIG(MSG_GPD_PARENT) },
116 		{ GPD_FILTER,		MSG_ORIG(MSG_GPD_FILTER) },
117 		{ GPD_REMOVE,		MSG_ORIG(MSG_GPD_REMOVE) },
118 		{ 0,			0 }
119 	};
120 	static CONV_EXPN_FIELD_ARG conv_arg = {
121 	    NULL, sizeof (grpdesc_flags_buf->buf), vda };
122 
123 	if (flags == 0)
124 		return (MSG_ORIG(MSG_GBL_NULL));
125 
126 	conv_arg.buf = grpdesc_flags_buf->buf;
127 	conv_arg.oflags = conv_arg.rflags = flags;
128 	(void) conv_expn_field(&conv_arg);
129 
130 	return ((const char *)grpdesc_flags_buf->buf);
131 }
132