xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/segments.c (revision 4734:a4708faa3e85)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
23*4734Sab196087  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * String conversion routine for segment flags.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate #include	<string.h>
321618Srie #include	<libld.h>
331618Srie #include	"_conv.h"
340Sstevel@tonic-gate #include	"segments_msg.h"
350Sstevel@tonic-gate 
362352Sab196087 #define	SEGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
372352Sab196087 		MSG_FLG_SG_VADDR_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
382352Sab196087 		MSG_FLG_SG_PADDR_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
392352Sab196087 		MSG_FLG_SG_LENGTH_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
402352Sab196087 		MSG_FLG_SG_ALIGN_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
412352Sab196087 		MSG_FLG_SG_ROUND_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
422352Sab196087 		MSG_FLG_SG_FLAGS_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
432352Sab196087 		MSG_FLG_SG_TYPE_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
442352Sab196087 		MSG_FLG_SG_ORDER_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
452352Sab196087 		MSG_FLG_SG_NOHDR_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
462352Sab196087 		MSG_FLG_SG_EMPTY_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
472352Sab196087 		MSG_FLG_SG_KEY_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
482352Sab196087 		MSG_FLG_SG_DISABLED_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
492352Sab196087 		MSG_FLG_SG_PHREQ_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
50*4734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
51*4734Sab196087 
52*4734Sab196087 /*
53*4734Sab196087  * Ensure that Conv_seg_flags_buf_t is large enough:
54*4734Sab196087  *
55*4734Sab196087  * SEGSZ is the real minimum size of the buffer required by conv_seg_flags().
56*4734Sab196087  * However, Conv_seg_flags_buf_t uses CONV_SEG_FLAGS_BUFSIZE to set the
57*4734Sab196087  * buffer size. We do things this way because the definition of SEGSZ uses
58*4734Sab196087  * information that is not available in the environment of other programs
59*4734Sab196087  * that include the conv.h header file.
60*4734Sab196087  */
61*4734Sab196087 #if (CONV_SEG_FLAGS_BUFSIZE < SEGSZ) && !defined(__lint)
62*4734Sab196087 #error "CONV_SEG_FLAGS_BUFSIZE is not large enough"
63*4734Sab196087 #endif
640Sstevel@tonic-gate 
650Sstevel@tonic-gate const char *
66*4734Sab196087 conv_seg_flags(Half flags, Conv_seg_flags_buf_t *seg_flags_buf)
670Sstevel@tonic-gate {
681618Srie 	static Val_desc vda[] = {
691618Srie 		{ FLG_SG_VADDR,		MSG_ORIG(MSG_FLG_SG_VADDR) },
701618Srie 		{ FLG_SG_PADDR,		MSG_ORIG(MSG_FLG_SG_PADDR) },
711618Srie 		{ FLG_SG_LENGTH,	MSG_ORIG(MSG_FLG_SG_LENGTH) },
721618Srie 		{ FLG_SG_ALIGN,		MSG_ORIG(MSG_FLG_SG_ALIGN) },
731618Srie 		{ FLG_SG_ROUND,		MSG_ORIG(MSG_FLG_SG_ROUND) },
741618Srie 		{ FLG_SG_FLAGS,		MSG_ORIG(MSG_FLG_SG_FLAGS) },
751618Srie 		{ FLG_SG_TYPE,		MSG_ORIG(MSG_FLG_SG_TYPE) },
761618Srie 		{ FLG_SG_ORDER,		MSG_ORIG(MSG_FLG_SG_ORDER) },
771618Srie 		{ FLG_SG_NOHDR,		MSG_ORIG(MSG_FLG_SG_NOHDR) },
781618Srie 		{ FLG_SG_EMPTY,		MSG_ORIG(MSG_FLG_SG_EMPTY) },
791618Srie 		{ FLG_SG_KEY,		MSG_ORIG(MSG_FLG_SG_KEY) },
801618Srie 		{ FLG_SG_DISABLED,	MSG_ORIG(MSG_FLG_SG_DISABLED) },
811618Srie 		{ FLG_SG_PHREQ,		MSG_ORIG(MSG_FLG_SG_PHREQ) },
821618Srie 		{ 0,			0 }
831618Srie 	};
84*4734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
85*4734Sab196087 	    NULL, sizeof (seg_flags_buf->buf), vda };
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	if (flags == 0)
880Sstevel@tonic-gate 		return (MSG_ORIG(MSG_GBL_ZERO));
890Sstevel@tonic-gate 
90*4734Sab196087 	conv_arg.buf = seg_flags_buf->buf;
912352Sab196087 	conv_arg.oflags = conv_arg.rflags = flags;
922352Sab196087 	(void) conv_expn_field(&conv_arg);
931618Srie 
94*4734Sab196087 	return ((const char *)seg_flags_buf->buf);
950Sstevel@tonic-gate }
96