xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/entry.c (revision 69112edd)
1*69112eddSAli Bahrami /*
2*69112eddSAli Bahrami  * CDDL HEADER START
3*69112eddSAli Bahrami  *
4*69112eddSAli Bahrami  * The contents of this file are subject to the terms of the
5*69112eddSAli Bahrami  * Common Development and Distribution License (the "License").
6*69112eddSAli Bahrami  * You may not use this file except in compliance with the License.
7*69112eddSAli Bahrami  *
8*69112eddSAli Bahrami  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*69112eddSAli Bahrami  * or http://www.opensolaris.org/os/licensing.
10*69112eddSAli Bahrami  * See the License for the specific language governing permissions
11*69112eddSAli Bahrami  * and limitations under the License.
12*69112eddSAli Bahrami  *
13*69112eddSAli Bahrami  * When distributing Covered Code, include this CDDL HEADER in each
14*69112eddSAli Bahrami  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*69112eddSAli Bahrami  * If applicable, add the following below this CDDL HEADER, with the
16*69112eddSAli Bahrami  * fields enclosed by brackets "[]" replaced with your own identifying
17*69112eddSAli Bahrami  * information: Portions Copyright [yyyy] [name of copyright owner]
18*69112eddSAli Bahrami  *
19*69112eddSAli Bahrami  * CDDL HEADER END
20*69112eddSAli Bahrami  */
21*69112eddSAli Bahrami 
22*69112eddSAli Bahrami /*
23*69112eddSAli Bahrami  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24*69112eddSAli Bahrami  * Use is subject to license terms.
25*69112eddSAli Bahrami  */
26*69112eddSAli Bahrami 
27*69112eddSAli Bahrami /*
28*69112eddSAli Bahrami  * String conversion routine for segment flags.
29*69112eddSAli Bahrami  */
30*69112eddSAli Bahrami #include	<string.h>
31*69112eddSAli Bahrami #include	<libld.h>
32*69112eddSAli Bahrami #include	"_conv.h"
33*69112eddSAli Bahrami #include	"entry_msg.h"
34*69112eddSAli Bahrami 
35*69112eddSAli Bahrami #define	ENTSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
36*69112eddSAli Bahrami 		MSG_FLG_EC_BUILTIN_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
37*69112eddSAli Bahrami 		MSG_FLG_EC_USED_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
38*69112eddSAli Bahrami 		MSG_FLG_EC_CATCHALL_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
39*69112eddSAli Bahrami 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
40*69112eddSAli Bahrami 
41*69112eddSAli Bahrami /*
42*69112eddSAli Bahrami  * Ensure that Conv_ent_flags_buf_t is large enough:
43*69112eddSAli Bahrami  *
44*69112eddSAli Bahrami  * ENTSZ is the real minimum size of the buffer required by conv_ent_flags().
45*69112eddSAli Bahrami  * However, Conv_ent_flags_buf_t uses CONV_ENT_FLAGS_BUFSIZE to set the
46*69112eddSAli Bahrami  * buffer size. We do things this way because the definition of ENTSZ uses
47*69112eddSAli Bahrami  * information that is not available in the environment of other programs
48*69112eddSAli Bahrami  * that include the conv.h header file.
49*69112eddSAli Bahrami  */
50*69112eddSAli Bahrami #if (CONV_ENT_FLAGS_BUFSIZE != ENTSZ) && !defined(__lint)
51*69112eddSAli Bahrami #define	REPORT_BUFSIZE ENTSZ
52*69112eddSAli Bahrami #include "report_bufsize.h"
53*69112eddSAli Bahrami #error "CONV_ENT_FLAGS_BUFSIZE does not match ENTSZ"
54*69112eddSAli Bahrami #endif
55*69112eddSAli Bahrami 
56*69112eddSAli Bahrami const char *
conv_ent_flags(ec_flags_t flags,Conv_ent_flags_buf_t * ent_flags_buf)57*69112eddSAli Bahrami conv_ent_flags(ec_flags_t flags, Conv_ent_flags_buf_t *ent_flags_buf)
58*69112eddSAli Bahrami {
59*69112eddSAli Bahrami 	static Val_desc vda[] = {
60*69112eddSAli Bahrami 		{ FLG_EC_BUILTIN,	MSG_FLG_EC_BUILTIN },
61*69112eddSAli Bahrami 		{ FLG_EC_USED,		MSG_FLG_EC_USED },
62*69112eddSAli Bahrami 		{ FLG_EC_CATCHALL,	MSG_FLG_EC_CATCHALL },
63*69112eddSAli Bahrami 		{ 0,			0 }
64*69112eddSAli Bahrami 	};
65*69112eddSAli Bahrami 	static CONV_EXPN_FIELD_ARG conv_arg = {
66*69112eddSAli Bahrami 	    NULL, sizeof (ent_flags_buf->buf) };
67*69112eddSAli Bahrami 
68*69112eddSAli Bahrami 	if (flags == 0)
69*69112eddSAli Bahrami 		return (MSG_ORIG(MSG_GBL_ZERO));
70*69112eddSAli Bahrami 
71*69112eddSAli Bahrami 	conv_arg.buf = ent_flags_buf->buf;
72*69112eddSAli Bahrami 	conv_arg.oflags = conv_arg.rflags = flags;
73*69112eddSAli Bahrami 	(void) conv_expn_field(&conv_arg, vda, 0);
74*69112eddSAli Bahrami 
75*69112eddSAli Bahrami 	return ((const char *)ent_flags_buf->buf);
76*69112eddSAli Bahrami }
77*69112eddSAli Bahrami 
78*69112eddSAli Bahrami 
79*69112eddSAli Bahrami #define	ECFSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
80*69112eddSAli Bahrami 		MSG_TYP_ECF_PATH_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
81*69112eddSAli Bahrami 		MSG_TYP_ECF_BASENAME_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
82*69112eddSAli Bahrami 		MSG_TYP_ECF_OBJNAME_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
83*69112eddSAli Bahrami 		MSG_FLG_ECF_ARMEMBER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
84*69112eddSAli Bahrami 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
85*69112eddSAli Bahrami 
86*69112eddSAli Bahrami /*
87*69112eddSAli Bahrami  * Ensure that Conv_ent_flags_buf_t is large enough:
88*69112eddSAli Bahrami  *
89*69112eddSAli Bahrami  * ENTSZ is the real minimum size of the buffer required by conv_ent_flags().
90*69112eddSAli Bahrami  * However, Conv_ent_flags_buf_t uses CONV_ENT_FLAGS_BUFSIZE to set the
91*69112eddSAli Bahrami  * buffer size. We do things this way because the definition of ENTSZ uses
92*69112eddSAli Bahrami  * information that is not available in the environment of other programs
93*69112eddSAli Bahrami  * that include the conv.h header file.
94*69112eddSAli Bahrami  */
95*69112eddSAli Bahrami #if (CONV_ENT_FILES_FLAGS_BUFSIZE != ECFSZ) && !defined(__lint)
96*69112eddSAli Bahrami #define	REPORT_BUFSIZE ECFSZ
97*69112eddSAli Bahrami #include "report_bufsize.h"
98*69112eddSAli Bahrami #error "CONV_ENT_FILES_FLAGS_BUFSIZE does not match ECFSZ"
99*69112eddSAli Bahrami #endif
100*69112eddSAli Bahrami 
101*69112eddSAli Bahrami /*
102*69112eddSAli Bahrami  * Make a string representation of the End_desc_file edf_flags field.
103*69112eddSAli Bahrami  */
104*69112eddSAli Bahrami const char *
conv_ent_files_flags(Word flags,Conv_fmt_flags_t fmt_flags,Conv_ent_files_flags_buf_t * flags_buf)105*69112eddSAli Bahrami conv_ent_files_flags(Word flags, Conv_fmt_flags_t fmt_flags,
106*69112eddSAli Bahrami     Conv_ent_files_flags_buf_t *flags_buf)
107*69112eddSAli Bahrami {
108*69112eddSAli Bahrami 	static const Msg	types[] = {
109*69112eddSAli Bahrami 		MSG_TYP_ECF_PATH, MSG_TYP_ECF_BASENAME, MSG_TYP_ECF_OBJNAME
110*69112eddSAli Bahrami 	};
111*69112eddSAli Bahrami #if TYP_ECF_NUM != (TYP_ECF_OBJNAME + 1)
112*69112eddSAli Bahrami #error "types has grown"
113*69112eddSAli Bahrami #endif
114*69112eddSAli Bahrami 
115*69112eddSAli Bahrami 	static Val_desc vda[] = {
116*69112eddSAli Bahrami 		{ FLG_ECF_ARMEMBER,	MSG_FLG_ECF_ARMEMBER },
117*69112eddSAli Bahrami 		{ 0,			0 }
118*69112eddSAli Bahrami 	};
119*69112eddSAli Bahrami 
120*69112eddSAli Bahrami 	static const char *leading_str_arr[2];
121*69112eddSAli Bahrami 	static CONV_EXPN_FIELD_ARG conv_arg = {
122*69112eddSAli Bahrami 	    NULL, sizeof (flags_buf->buf), leading_str_arr };
123*69112eddSAli Bahrami 
124*69112eddSAli Bahrami 	Word	type_idx;
125*69112eddSAli Bahrami 
126*69112eddSAli Bahrami 	type_idx = flags & TYP_ECF_MASK;
127*69112eddSAli Bahrami 	if (type_idx < TYP_ECF_NUM) {
128*69112eddSAli Bahrami 		leading_str_arr[0] = MSG_ORIG(types[type_idx]);
129*69112eddSAli Bahrami 		flags &= ~TYP_ECF_MASK;
130*69112eddSAli Bahrami 	} else {
131*69112eddSAli Bahrami 		leading_str_arr[0] = NULL;
132*69112eddSAli Bahrami 	}
133*69112eddSAli Bahrami 
134*69112eddSAli Bahrami 	conv_arg.buf = flags_buf->buf;
135*69112eddSAli Bahrami 	conv_arg.oflags = conv_arg.rflags = flags;
136*69112eddSAli Bahrami 
137*69112eddSAli Bahrami 	(void) conv_expn_field(&conv_arg, vda, fmt_flags);
138*69112eddSAli Bahrami 
139*69112eddSAli Bahrami 	return (conv_arg.buf);
140*69112eddSAli Bahrami }
141