xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/syminfo.c (revision 99e6869ff7df020d73a2a959aafdf73d3e7b31ca)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * String conversion routines for syminfo attributes.
30  */
31 #include	<stdio.h>
32 #include	<_machelf.h>
33 #include	"_conv.h"
34 #include	"syminfo_msg.h"
35 
36 
37 
38 #define	FLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
39 	MSG_SYMINFO_FLG_DIRECT_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
40 	MSG_SYMINFO_FLG_COPY_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
41 	MSG_SYMINFO_FLG_LAZYLOAD_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
42 	MSG_SYMINFO_FLG_DIRECTBIND_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
43 	CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
44 
45 /*
46  * Ensure that Conv_syminfo_flags_buf_t is large enough:
47  *
48  * FLAGSZ is the real minimum size of the buffer required by
49  * conv_syminfo_flags(). However, Conv_syminfo_flags_buf_t uses
50  * CONV_SYMINFO_FLAGS_BUFSIZE to set the buffer size. We do things
51  * this way because the definition of FLAGSZ uses information that
52  * is not available in the environment of other programs that include
53  * the conv.h header file.
54  */
55 #if (CONV_SYMINFO_FLAGS_BUFSIZE != FLAGSZ) && !defined(__lint)
56 #define	REPORT_BUFSIZE FLAGSZ
57 #include "report_bufsize.h"
58 #error "CONV_SYMINFO_FLAGS_BUFSIZE does not match FLAGSZ"
59 #endif
60 
61 const char *
62 conv_syminfo_flags(Xword flags, Conv_fmt_flags_t fmt_flags,
63     Conv_syminfo_flags_buf_t *syminfo_flags_buf)
64 {
65 	static Val_desc vda[] = {
66 		{ SYMINFO_FLG_DIRECT,	MSG_ORIG(MSG_SYMINFO_FLG_DIRECT) },
67 		{ SYMINFO_FLG_COPY,	MSG_ORIG(MSG_SYMINFO_FLG_COPY) },
68 		{ SYMINFO_FLG_LAZYLOAD,	MSG_ORIG(MSG_SYMINFO_FLG_LAZYLOAD) },
69 		{ SYMINFO_FLG_DIRECTBIND,
70 		    MSG_ORIG(MSG_SYMINFO_FLG_DIRECTBIND) },
71 		{ SYMINFO_FLG_NOEXTDIRECT,
72 		    MSG_ORIG(MSG_SYMINFO_FLG_NOEXTDIRECT) },
73 		{ 0,			0 }
74 	};
75 	static CONV_EXPN_FIELD_ARG conv_arg = {
76 	    NULL, sizeof (syminfo_flags_buf->buf), vda };
77 
78 	if (flags == 0)
79 		return (MSG_ORIG(MSG_GBL_ZERO));
80 
81 	conv_arg.buf = syminfo_flags_buf->buf;
82 	conv_arg.oflags = conv_arg.rflags = flags;
83 	conv_arg.prefix = conv_arg.suffix = NULL;
84 	(void) conv_expn_field(&conv_arg, fmt_flags);
85 
86 	return ((const char *)syminfo_flags_buf->buf);
87 }
88