xref: /titanic_44/usr/src/cmd/sgs/libconv/common/entry.c (revision 68c47f65208790c466e5e484f2293d3baed71c6a)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * String conversion routine for segment flags.
29  */
30 #include	<string.h>
31 #include	<libld.h>
32 #include	"_conv.h"
33 #include	"entry_msg.h"
34 
35 #define	ENTSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
36 		MSG_FLG_EC_BUILTIN_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
37 		MSG_FLG_EC_USED_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
38 		MSG_FLG_EC_CATCHALL_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
39 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
40 
41 /*
42  * Ensure that Conv_ent_flags_buf_t is large enough:
43  *
44  * ENTSZ is the real minimum size of the buffer required by conv_ent_flags().
45  * However, Conv_ent_flags_buf_t uses CONV_ENT_FLAGS_BUFSIZE to set the
46  * buffer size. We do things this way because the definition of ENTSZ uses
47  * information that is not available in the environment of other programs
48  * that include the conv.h header file.
49  */
50 #if (CONV_ENT_FLAGS_BUFSIZE != ENTSZ) && !defined(__lint)
51 #define	REPORT_BUFSIZE ENTSZ
52 #include "report_bufsize.h"
53 #error "CONV_ENT_FLAGS_BUFSIZE does not match ENTSZ"
54 #endif
55 
56 const char *
57 conv_ent_flags(ec_flags_t flags, Conv_ent_flags_buf_t *ent_flags_buf)
58 {
59 	static Val_desc vda[] = {
60 		{ FLG_EC_BUILTIN,	MSG_FLG_EC_BUILTIN },
61 		{ FLG_EC_USED,		MSG_FLG_EC_USED },
62 		{ FLG_EC_CATCHALL,	MSG_FLG_EC_CATCHALL },
63 		{ 0,			0 }
64 	};
65 	static CONV_EXPN_FIELD_ARG conv_arg = {
66 	    NULL, sizeof (ent_flags_buf->buf) };
67 
68 	if (flags == 0)
69 		return (MSG_ORIG(MSG_GBL_ZERO));
70 
71 	conv_arg.buf = ent_flags_buf->buf;
72 	conv_arg.oflags = conv_arg.rflags = flags;
73 	(void) conv_expn_field(&conv_arg, vda, 0);
74 
75 	return ((const char *)ent_flags_buf->buf);
76 }
77 
78 
79 #define	ECFSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
80 		MSG_TYP_ECF_PATH_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
81 		MSG_TYP_ECF_BASENAME_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
82 		MSG_TYP_ECF_OBJNAME_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
83 		MSG_FLG_ECF_ARMEMBER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
84 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
85 
86 /*
87  * Ensure that Conv_ent_flags_buf_t is large enough:
88  *
89  * ENTSZ is the real minimum size of the buffer required by conv_ent_flags().
90  * However, Conv_ent_flags_buf_t uses CONV_ENT_FLAGS_BUFSIZE to set the
91  * buffer size. We do things this way because the definition of ENTSZ uses
92  * information that is not available in the environment of other programs
93  * that include the conv.h header file.
94  */
95 #if (CONV_ENT_FILES_FLAGS_BUFSIZE != ECFSZ) && !defined(__lint)
96 #define	REPORT_BUFSIZE ECFSZ
97 #include "report_bufsize.h"
98 #error "CONV_ENT_FILES_FLAGS_BUFSIZE does not match ECFSZ"
99 #endif
100 
101 /*
102  * Make a string representation of the End_desc_file edf_flags field.
103  */
104 const char *
105 conv_ent_files_flags(Word flags, Conv_fmt_flags_t fmt_flags,
106     Conv_ent_files_flags_buf_t *flags_buf)
107 {
108 	static const Msg	types[] = {
109 		MSG_TYP_ECF_PATH, MSG_TYP_ECF_BASENAME, MSG_TYP_ECF_OBJNAME
110 	};
111 #if TYP_ECF_NUM != (TYP_ECF_OBJNAME + 1)
112 #error "types has grown"
113 #endif
114 
115 	static Val_desc vda[] = {
116 		{ FLG_ECF_ARMEMBER,	MSG_FLG_ECF_ARMEMBER },
117 		{ 0,			0 }
118 	};
119 
120 	static const char *leading_str_arr[2];
121 	static CONV_EXPN_FIELD_ARG conv_arg = {
122 	    NULL, sizeof (flags_buf->buf), leading_str_arr };
123 
124 	Word	type_idx;
125 
126 	type_idx = flags & TYP_ECF_MASK;
127 	if (type_idx < TYP_ECF_NUM) {
128 		leading_str_arr[0] = MSG_ORIG(types[type_idx]);
129 		flags &= ~TYP_ECF_MASK;
130 	} else {
131 		leading_str_arr[0] = NULL;
132 	}
133 
134 	conv_arg.buf = flags_buf->buf;
135 	conv_arg.oflags = conv_arg.rflags = flags;
136 
137 	(void) conv_expn_field(&conv_arg, vda, fmt_flags);
138 
139 	return (conv_arg.buf);
140 }
141