summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sgs/libconv/common/entry.c
blob: 6c8c4e0850d4ba91008340d13e2493bb67a7e2fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * String conversion routine for segment flags.
 */
#include	<string.h>
#include	<libld.h>
#include	"_conv.h"
#include	"entry_msg.h"

#define	ENTSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
		MSG_FLG_EC_BUILTIN_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
		MSG_FLG_EC_USED_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
		MSG_FLG_EC_CATCHALL_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE

/*
 * Ensure that Conv_ent_flags_buf_t is large enough:
 *
 * ENTSZ is the real minimum size of the buffer required by conv_ent_flags().
 * However, Conv_ent_flags_buf_t uses CONV_ENT_FLAGS_BUFSIZE to set the
 * buffer size. We do things this way because the definition of ENTSZ uses
 * information that is not available in the environment of other programs
 * that include the conv.h header file.
 */
#if (CONV_ENT_FLAGS_BUFSIZE != ENTSZ) && !defined(__lint)
#define	REPORT_BUFSIZE ENTSZ
#include "report_bufsize.h"
#error "CONV_ENT_FLAGS_BUFSIZE does not match ENTSZ"
#endif

const char *
conv_ent_flags(ec_flags_t flags, Conv_ent_flags_buf_t *ent_flags_buf)
{
	static Val_desc vda[] = {
		{ FLG_EC_BUILTIN,	MSG_FLG_EC_BUILTIN },
		{ FLG_EC_USED,		MSG_FLG_EC_USED },
		{ FLG_EC_CATCHALL,	MSG_FLG_EC_CATCHALL },
		{ 0,			0 }
	};
	static CONV_EXPN_FIELD_ARG conv_arg = {
	    NULL, sizeof (ent_flags_buf->buf) };

	if (flags == 0)
		return (MSG_ORIG(MSG_GBL_ZERO));

	conv_arg.buf = ent_flags_buf->buf;
	conv_arg.oflags = conv_arg.rflags = flags;
	(void) conv_expn_field(&conv_arg, vda, 0);

	return ((const char *)ent_flags_buf->buf);
}


#define	ECFSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
		MSG_TYP_ECF_PATH_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
		MSG_TYP_ECF_BASENAME_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
		MSG_TYP_ECF_OBJNAME_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
		MSG_FLG_ECF_ARMEMBER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE

/*
 * Ensure that Conv_ent_flags_buf_t is large enough:
 *
 * ENTSZ is the real minimum size of the buffer required by conv_ent_flags().
 * However, Conv_ent_flags_buf_t uses CONV_ENT_FLAGS_BUFSIZE to set the
 * buffer size. We do things this way because the definition of ENTSZ uses
 * information that is not available in the environment of other programs
 * that include the conv.h header file.
 */
#if (CONV_ENT_FILES_FLAGS_BUFSIZE != ECFSZ) && !defined(__lint)
#define	REPORT_BUFSIZE ECFSZ
#include "report_bufsize.h"
#error "CONV_ENT_FILES_FLAGS_BUFSIZE does not match ECFSZ"
#endif

/*
 * Make a string representation of the End_desc_file edf_flags field.
 */
const char *
conv_ent_files_flags(Word flags, Conv_fmt_flags_t fmt_flags,
    Conv_ent_files_flags_buf_t *flags_buf)
{
	static const Msg	types[] = {
		MSG_TYP_ECF_PATH, MSG_TYP_ECF_BASENAME, MSG_TYP_ECF_OBJNAME
	};
#if TYP_ECF_NUM != (TYP_ECF_OBJNAME + 1)
#error "types has grown"
#endif

	static Val_desc vda[] = {
		{ FLG_ECF_ARMEMBER,	MSG_FLG_ECF_ARMEMBER },
		{ 0,			0 }
	};

	static const char *leading_str_arr[2];
	static CONV_EXPN_FIELD_ARG conv_arg = {
	    NULL, sizeof (flags_buf->buf), leading_str_arr };

	Word	type_idx;

	type_idx = flags & TYP_ECF_MASK;
	if (type_idx < TYP_ECF_NUM) {
		leading_str_arr[0] = MSG_ORIG(types[type_idx]);
		flags &= ~TYP_ECF_MASK;
	} else {
		leading_str_arr[0] = NULL;
	}

	conv_arg.buf = flags_buf->buf;
	conv_arg.oflags = conv_arg.rflags = flags;

	(void) conv_expn_field(&conv_arg, vda, fmt_flags);

	return (conv_arg.buf);
}