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 /*
239273SAli.Bahrami@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <stdio.h>
281618Srie #include <strings.h>
296206Sab196087 #include <_machelf.h>
301618Srie #include "_conv.h"
310Sstevel@tonic-gate #include "globals_msg.h"
320Sstevel@tonic-gate
331976Sab196087
341976Sab196087 /*
359273SAli.Bahrami@Sun.COM * Map an integer into a descriptive string.
361976Sab196087 *
371976Sab196087 * entry:
389273SAli.Bahrami@Sun.COM * inv_buf - A buffer into which this routine can format
399273SAli.Bahrami@Sun.COM * a result string, if necessary.
409273SAli.Bahrami@Sun.COM * val - The value for which a string is desired.
419273SAli.Bahrami@Sun.COM * flags - CONV_FMT_* values to be passed to conv_invalid_val() if
429273SAli.Bahrami@Sun.COM * necessary. The caller is reponsible for having examined
439273SAli.Bahrami@Sun.COM * the CONV_FMT_ALT_* part of flags and passing the proper
449273SAli.Bahrami@Sun.COM * msg array.
459273SAli.Bahrami@Sun.COM * num_msg - # of Msg entries in msg.
469273SAli.Bahrami@Sun.COM * msg - Array of num_msg Msg items corresponding to the possible
479273SAli.Bahrami@Sun.COM * strings corresponding to val.
489273SAli.Bahrami@Sun.COM * local_sgs_msg - Message string table from module from which
499273SAli.Bahrami@Sun.COM * this function is called.
501976Sab196087 *
511976Sab196087 * exit:
529273SAli.Bahrami@Sun.COM * If val lies in the range [0-(num_msg-1)], then the string
539273SAli.Bahrami@Sun.COM * corresponding to it is returned. If val is outside the range,
549273SAli.Bahrami@Sun.COM * conv_invalid_val() is called to format an ASCII representation
559273SAli.Bahrami@Sun.COM * of it into inv_buf, and that is returned.
561976Sab196087 */
579273SAli.Bahrami@Sun.COM /*ARGSUSED5*/
589273SAli.Bahrami@Sun.COM static const char *
map_msg2str(Conv_inv_buf_t * inv_buf,Conv_elfvalue_t val,Conv_fmt_flags_t flags,size_t num_msg,const Msg * msg,const char * local_sgs_msg)599273SAli.Bahrami@Sun.COM map_msg2str(Conv_inv_buf_t *inv_buf, Conv_elfvalue_t val,
609273SAli.Bahrami@Sun.COM Conv_fmt_flags_t flags, size_t num_msg, const Msg *msg,
619273SAli.Bahrami@Sun.COM const char *local_sgs_msg)
620Sstevel@tonic-gate {
639273SAli.Bahrami@Sun.COM if ((val < num_msg) && (msg[val] != 0))
649273SAli.Bahrami@Sun.COM return (MSG_ORIG_STRTAB(msg[val], local_sgs_msg));
650Sstevel@tonic-gate
669273SAli.Bahrami@Sun.COM /* If we get here, it's an unknown value */
679273SAli.Bahrami@Sun.COM return (conv_invalid_val(inv_buf, val, flags));
680Sstevel@tonic-gate }
691618Srie
701618Srie /*
719273SAli.Bahrami@Sun.COM * Map an integer into a descriptive string from a NULL terminated
729273SAli.Bahrami@Sun.COM * array of Val_desc or Val_desc2 descriptors.
732352Sab196087 *
742352Sab196087 * entry:
759273SAli.Bahrami@Sun.COM * inv_buf - A buffer into which this routine can format
769273SAli.Bahrami@Sun.COM * a result string, if necessary.
779273SAli.Bahrami@Sun.COM * osabi,mach (_conv_vd22str only) - The osab/mach under which
789273SAli.Bahrami@Sun.COM * val is to be interpreted. Items with a non-0 osabi or machine
799273SAli.Bahrami@Sun.COM * that do not match are quietly ignored.
809273SAli.Bahrami@Sun.COM * val - The value for which a string is desired.
819273SAli.Bahrami@Sun.COM * flags - CONV_FMT_* values to be passed to conv_invalid_val() if
829273SAli.Bahrami@Sun.COM * necessary. The caller is reponsible for having examined
839273SAli.Bahrami@Sun.COM * the CONV_FMT_ALT_* part of flags and passing the proper
849273SAli.Bahrami@Sun.COM * descriptor array.
859273SAli.Bahrami@Sun.COM * vdp - Pointer to NULL terminated array of Val_desc descriptors.
869273SAli.Bahrami@Sun.COM * local_sgs_msg - Message string table from module from which
879273SAli.Bahrami@Sun.COM * this function is called.
882352Sab196087 *
892352Sab196087 * exit:
909273SAli.Bahrami@Sun.COM * If val is found in the vdp array, and in the osabi version of
919273SAli.Bahrami@Sun.COM * this function if the osabi matches, then the string corresponding
929273SAli.Bahrami@Sun.COM * val is returned. If a string for val is not found, conv_invalid_val()
939273SAli.Bahrami@Sun.COM * is called to format an ASCII representation of it into inv_buf, and
949273SAli.Bahrami@Sun.COM * that is returned.
952352Sab196087 */
969273SAli.Bahrami@Sun.COM /*ARGSUSED4*/
979273SAli.Bahrami@Sun.COM static const char *
map_vd2str(Conv_inv_buf_t * inv_buf,Conv_elfvalue_t val,Conv_fmt_flags_t flags,const Val_desc * vdp,const char * local_sgs_msg)989273SAli.Bahrami@Sun.COM map_vd2str(Conv_inv_buf_t *inv_buf, Conv_elfvalue_t val,
999273SAli.Bahrami@Sun.COM Conv_fmt_flags_t flags, const Val_desc *vdp, const char *local_sgs_msg)
1002352Sab196087 {
1019273SAli.Bahrami@Sun.COM for (; vdp->v_msg; vdp++) {
1029273SAli.Bahrami@Sun.COM if (val == vdp->v_val)
1039273SAli.Bahrami@Sun.COM return (MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg));
1042352Sab196087 }
1052352Sab196087
1069273SAli.Bahrami@Sun.COM /* If we get here, it's an unknown value */
1079273SAli.Bahrami@Sun.COM return (conv_invalid_val(inv_buf, val, flags));
1089273SAli.Bahrami@Sun.COM }
1099273SAli.Bahrami@Sun.COM
1109273SAli.Bahrami@Sun.COM /*ARGSUSED6*/
1119273SAli.Bahrami@Sun.COM static const char *
map_vd22str(Conv_inv_buf_t * inv_buf,uchar_t osabi,Half mach,Conv_elfvalue_t val,Conv_fmt_flags_t flags,const Val_desc2 * vdp,const char * local_sgs_msg)1129273SAli.Bahrami@Sun.COM map_vd22str(Conv_inv_buf_t *inv_buf, uchar_t osabi, Half mach,
1139273SAli.Bahrami@Sun.COM Conv_elfvalue_t val, Conv_fmt_flags_t flags, const Val_desc2 *vdp,
1149273SAli.Bahrami@Sun.COM const char *local_sgs_msg)
1159273SAli.Bahrami@Sun.COM {
1169273SAli.Bahrami@Sun.COM for (; vdp->v_msg; vdp++) {
1179273SAli.Bahrami@Sun.COM if (CONV_VD2_SKIP(osabi, mach, vdp))
1189273SAli.Bahrami@Sun.COM continue;
1199273SAli.Bahrami@Sun.COM
1209273SAli.Bahrami@Sun.COM if (val == vdp->v_val)
1219273SAli.Bahrami@Sun.COM return (MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg));
1222352Sab196087 }
1232352Sab196087
1249273SAli.Bahrami@Sun.COM /* If we get here, it's an unknown value */
1259273SAli.Bahrami@Sun.COM return (conv_invalid_val(inv_buf, val, flags));
1262352Sab196087 }
1272352Sab196087
1282352Sab196087 /*
1299273SAli.Bahrami@Sun.COM * Process an array of conv_ds_XXX_t structures and call the appropriate
1309273SAli.Bahrami@Sun.COM * map functions for the format of the strings given.
1311618Srie */
1329273SAli.Bahrami@Sun.COM const char *
_conv_map_ds(uchar_t osabi,Half mach,Conv_elfvalue_t value,const conv_ds_t ** dsp,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf,const char * local_sgs_msg)1339273SAli.Bahrami@Sun.COM _conv_map_ds(uchar_t osabi, Half mach, Conv_elfvalue_t value,
1349273SAli.Bahrami@Sun.COM const conv_ds_t **dsp, Conv_fmt_flags_t fmt_flags, Conv_inv_buf_t *inv_buf,
1359273SAli.Bahrami@Sun.COM const char *local_sgs_msg)
1361618Srie {
1379273SAli.Bahrami@Sun.COM const conv_ds_t *ds;
1389273SAli.Bahrami@Sun.COM
1399273SAli.Bahrami@Sun.COM for (ds = *dsp; ds != NULL; ds = *(++dsp)) {
1409273SAli.Bahrami@Sun.COM if ((value < ds->ds_baseval) || (value > ds->ds_topval))
1419273SAli.Bahrami@Sun.COM continue;
1422352Sab196087
1439273SAli.Bahrami@Sun.COM switch (ds->ds_type) {
1449273SAli.Bahrami@Sun.COM case CONV_DS_MSGARR:
1459273SAli.Bahrami@Sun.COM return (map_msg2str(inv_buf, value - ds->ds_baseval,
1469273SAli.Bahrami@Sun.COM fmt_flags, ds->ds_topval - ds->ds_baseval + 1,
1479273SAli.Bahrami@Sun.COM /*LINTED*/
1489273SAli.Bahrami@Sun.COM ((conv_ds_msg_t *)ds)->ds_msg,
1499273SAli.Bahrami@Sun.COM local_sgs_msg));
1502352Sab196087
1519273SAli.Bahrami@Sun.COM case CONV_DS_VD:
1529273SAli.Bahrami@Sun.COM return (map_vd2str(inv_buf, value, fmt_flags,
1539273SAli.Bahrami@Sun.COM /*LINTED*/
1549273SAli.Bahrami@Sun.COM ((conv_ds_vd_t *)ds)->ds_vd,
1559273SAli.Bahrami@Sun.COM local_sgs_msg));
1562352Sab196087
1579273SAli.Bahrami@Sun.COM case CONV_DS_VD2:
1589273SAli.Bahrami@Sun.COM return (map_vd22str(inv_buf, osabi, mach, value,
1599273SAli.Bahrami@Sun.COM fmt_flags,
1609273SAli.Bahrami@Sun.COM /*LINTED*/
1619273SAli.Bahrami@Sun.COM ((conv_ds_vd2_t *)ds)->ds_vd2,
1629273SAli.Bahrami@Sun.COM local_sgs_msg));
1632352Sab196087 }
1642352Sab196087 }
1651618Srie
1669273SAli.Bahrami@Sun.COM return (conv_invalid_val(inv_buf, value, fmt_flags));
1679273SAli.Bahrami@Sun.COM }
1689273SAli.Bahrami@Sun.COM
1699273SAli.Bahrami@Sun.COM /*
1709273SAli.Bahrami@Sun.COM * Iterate over every message string in a given array of Msg codes,
1719273SAli.Bahrami@Sun.COM * calling a user supplied callback for each one.
1729273SAli.Bahrami@Sun.COM *
1739273SAli.Bahrami@Sun.COM * entry:
1749273SAli.Bahrami@Sun.COM * basevalue - Value corresponding to the first Msg in the array.
1759273SAli.Bahrami@Sun.COM * local_sgs_msg - Pointer to the __sgs_msg array for the
1769273SAli.Bahrami@Sun.COM * libconv module making the call.
1779273SAli.Bahrami@Sun.COM * num_msg - # of items in array referenced by msg
1789273SAli.Bahrami@Sun.COM * msg - Array of Msg indexes for the strings to iterate over.
1799273SAli.Bahrami@Sun.COM * The value corresponding to each element of msg must be:
1809273SAli.Bahrami@Sun.COM * value[i] = basevalue + i
1819273SAli.Bahrami@Sun.COM * func, uvalue - User supplied function to be called for each
1829273SAli.Bahrami@Sun.COM * string in msg. uvalue is an arbitrary user supplied pointer
1839273SAli.Bahrami@Sun.COM * to be passed to func.
1849273SAli.Bahrami@Sun.COM * local_sgs_msg - Pointer to the __sgs_msg array for the
1859273SAli.Bahrami@Sun.COM * libconv module making the call.
1869273SAli.Bahrami@Sun.COM *
1879273SAli.Bahrami@Sun.COM * exit:
1889273SAli.Bahrami@Sun.COM * The callback function is called for every non-zero item in
1899273SAli.Bahrami@Sun.COM * msg[]. If any callback returns CONV_ITER_DONE, execution stops
1909273SAli.Bahrami@Sun.COM * with that item and the function returns immediately. Otherwise,
1919273SAli.Bahrami@Sun.COM * it continues to the end of the array.
1929273SAli.Bahrami@Sun.COM *
1939273SAli.Bahrami@Sun.COM * The value from the last callback is returned.
1949273SAli.Bahrami@Sun.COM */
1959273SAli.Bahrami@Sun.COM /*ARGSUSED5*/
1969273SAli.Bahrami@Sun.COM static conv_iter_ret_t
_conv_iter_msgarr(uint32_t basevalue,const Msg * msg,size_t num_msg,conv_iter_cb_t func,void * uvalue,const char * local_sgs_msg)1979273SAli.Bahrami@Sun.COM _conv_iter_msgarr(uint32_t basevalue, const Msg *msg, size_t num_msg,
1989273SAli.Bahrami@Sun.COM conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
1999273SAli.Bahrami@Sun.COM {
2009273SAli.Bahrami@Sun.COM for (; num_msg-- > 0; basevalue++, msg++) {
2019273SAli.Bahrami@Sun.COM if (*msg != 0)
2029273SAli.Bahrami@Sun.COM if ((* func)(MSG_ORIG_STRTAB(*msg, local_sgs_msg),
2039273SAli.Bahrami@Sun.COM basevalue, uvalue) == CONV_ITER_DONE)
2049273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE);
2059273SAli.Bahrami@Sun.COM }
2069273SAli.Bahrami@Sun.COM
2079273SAli.Bahrami@Sun.COM return (CONV_ITER_CONT);
2089273SAli.Bahrami@Sun.COM }
2091618Srie
2109273SAli.Bahrami@Sun.COM /*
2119273SAli.Bahrami@Sun.COM * Iterate over every message string in a given array of Val_desc or
2129273SAli.Bahrami@Sun.COM * Val_desc2 descriptors, calling a user supplied callback for each one.
2139273SAli.Bahrami@Sun.COM *
2149273SAli.Bahrami@Sun.COM * entry:
2159273SAli.Bahrami@Sun.COM * osabi,mach (_conv_iter_vd2 only) - The osabi/mach for which
2169273SAli.Bahrami@Sun.COM * strings are desired. Strings with a non-0 osabi or machine
2179273SAli.Bahrami@Sun.COM * that do not match are quietly ignored.
2189273SAli.Bahrami@Sun.COM * vdp - Pointer to NULL terminated array of Val_desc descriptors.
2199273SAli.Bahrami@Sun.COM * func, uvalue - User supplied function to be called for each
2209273SAli.Bahrami@Sun.COM * string in msg. uvalue is an arbitrary user supplied pointer
2219273SAli.Bahrami@Sun.COM * to be passed to func.
2229273SAli.Bahrami@Sun.COM * local_sgs_msg - Pointer to the __sgs_msg array for the
2239273SAli.Bahrami@Sun.COM * libconv module making the call.
2249273SAli.Bahrami@Sun.COM *
2259273SAli.Bahrami@Sun.COM * exit:
2269273SAli.Bahrami@Sun.COM * The callback function is called for every descriptor referenced by
2279273SAli.Bahrami@Sun.COM * vdp. In the case of the OSABI-version of this function, strings from
2289273SAli.Bahrami@Sun.COM * the wrong osabi are not used. If any callback returns CONV_ITER_DONE,
2299273SAli.Bahrami@Sun.COM * execution stops with that item and the function returns immediately.
2309273SAli.Bahrami@Sun.COM * Otherwise, it continues to the end of the array.
2319273SAli.Bahrami@Sun.COM *
2329273SAli.Bahrami@Sun.COM * The value from the last callback is returned.
2339273SAli.Bahrami@Sun.COM */
2349273SAli.Bahrami@Sun.COM /*ARGSUSED3*/
2359273SAli.Bahrami@Sun.COM conv_iter_ret_t
_conv_iter_vd(const Val_desc * vdp,conv_iter_cb_t func,void * uvalue,const char * local_sgs_msg)2369273SAli.Bahrami@Sun.COM _conv_iter_vd(const Val_desc *vdp, conv_iter_cb_t func, void *uvalue,
2379273SAli.Bahrami@Sun.COM const char *local_sgs_msg)
2389273SAli.Bahrami@Sun.COM {
2399273SAli.Bahrami@Sun.COM for (; vdp->v_msg; vdp++) {
2409273SAli.Bahrami@Sun.COM if ((* func)(MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg),
2419273SAli.Bahrami@Sun.COM vdp->v_val, uvalue) == CONV_ITER_DONE)
2429273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE);
2439273SAli.Bahrami@Sun.COM }
2449273SAli.Bahrami@Sun.COM
2459273SAli.Bahrami@Sun.COM return (CONV_ITER_CONT);
2469273SAli.Bahrami@Sun.COM }
2479273SAli.Bahrami@Sun.COM
2489273SAli.Bahrami@Sun.COM /*ARGSUSED5*/
2499273SAli.Bahrami@Sun.COM conv_iter_ret_t
_conv_iter_vd2(conv_iter_osabi_t osabi,Half mach,const Val_desc2 * vdp,conv_iter_cb_t func,void * uvalue,const char * local_sgs_msg)2509273SAli.Bahrami@Sun.COM _conv_iter_vd2(conv_iter_osabi_t osabi, Half mach, const Val_desc2 *vdp,
2519273SAli.Bahrami@Sun.COM conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
2529273SAli.Bahrami@Sun.COM {
2539273SAli.Bahrami@Sun.COM for (; vdp->v_msg; vdp++) {
2549273SAli.Bahrami@Sun.COM if (CONV_ITER_VD2_SKIP(osabi, mach, vdp))
2559273SAli.Bahrami@Sun.COM continue;
2569273SAli.Bahrami@Sun.COM
2579273SAli.Bahrami@Sun.COM if ((* func)(MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg),
2589273SAli.Bahrami@Sun.COM vdp->v_val, uvalue) == CONV_ITER_DONE)
2599273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE);
2609273SAli.Bahrami@Sun.COM }
2619273SAli.Bahrami@Sun.COM
2629273SAli.Bahrami@Sun.COM return (CONV_ITER_CONT);
2639273SAli.Bahrami@Sun.COM }
2649273SAli.Bahrami@Sun.COM
2659273SAli.Bahrami@Sun.COM /*
2669273SAli.Bahrami@Sun.COM * Process an array of conv_ds_XXX_t structures and call the appropriate
2679273SAli.Bahrami@Sun.COM * iteration functions for the format of the strings given.
2689273SAli.Bahrami@Sun.COM */
2699273SAli.Bahrami@Sun.COM conv_iter_ret_t
_conv_iter_ds(conv_iter_osabi_t osabi,Half mach,const conv_ds_t ** dsp,conv_iter_cb_t func,void * uvalue,const char * local_sgs_msg)2709273SAli.Bahrami@Sun.COM _conv_iter_ds(conv_iter_osabi_t osabi, Half mach, const conv_ds_t **dsp,
2719273SAli.Bahrami@Sun.COM conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
2729273SAli.Bahrami@Sun.COM {
2739273SAli.Bahrami@Sun.COM const conv_ds_t *ds;
2749273SAli.Bahrami@Sun.COM
2759273SAli.Bahrami@Sun.COM for (ds = *dsp; ds != NULL; ds = *(++dsp)) {
2769273SAli.Bahrami@Sun.COM switch (ds->ds_type) {
2779273SAli.Bahrami@Sun.COM case CONV_DS_MSGARR:
2789273SAli.Bahrami@Sun.COM if (_conv_iter_msgarr(ds->ds_baseval,
2799273SAli.Bahrami@Sun.COM /*LINTED*/
2809273SAli.Bahrami@Sun.COM ((conv_ds_msg_t *)ds)->ds_msg,
2819273SAli.Bahrami@Sun.COM ds->ds_topval - ds->ds_baseval + 1, func, uvalue,
2829273SAli.Bahrami@Sun.COM local_sgs_msg) == CONV_ITER_DONE)
2839273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE);
2849273SAli.Bahrami@Sun.COM break;
2859273SAli.Bahrami@Sun.COM
2869273SAli.Bahrami@Sun.COM case CONV_DS_VD:
2879273SAli.Bahrami@Sun.COM /*LINTED*/
2889273SAli.Bahrami@Sun.COM if (_conv_iter_vd(((conv_ds_vd_t *)ds)->ds_vd,
2899273SAli.Bahrami@Sun.COM func, uvalue, local_sgs_msg) == CONV_ITER_DONE)
2909273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE);
2919273SAli.Bahrami@Sun.COM break;
2929273SAli.Bahrami@Sun.COM
2939273SAli.Bahrami@Sun.COM case CONV_DS_VD2:
2949273SAli.Bahrami@Sun.COM if (_conv_iter_vd2(osabi, mach,
2959273SAli.Bahrami@Sun.COM /*LINTED*/
2969273SAli.Bahrami@Sun.COM ((conv_ds_vd2_t *)ds)->ds_vd2,
2979273SAli.Bahrami@Sun.COM func, uvalue, local_sgs_msg) == CONV_ITER_DONE)
2989273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE);
2999273SAli.Bahrami@Sun.COM break;
3001618Srie }
3011618Srie }
3021618Srie
3039273SAli.Bahrami@Sun.COM return (CONV_ITER_CONT);
3049273SAli.Bahrami@Sun.COM }
3059273SAli.Bahrami@Sun.COM
3069273SAli.Bahrami@Sun.COM /*
3079273SAli.Bahrami@Sun.COM * Initialize the uvalue block prior to use of an interation function
3089273SAli.Bahrami@Sun.COM * employing conv_iter_strtol().
3099273SAli.Bahrami@Sun.COM *
3109273SAli.Bahrami@Sun.COM * entry:
3119273SAli.Bahrami@Sun.COM * str - String to be matched to a value
3129273SAli.Bahrami@Sun.COM * uvalue - Pointer to uninitialized uvalue block
3139273SAli.Bahrami@Sun.COM *
3149273SAli.Bahrami@Sun.COM * exit:
3159273SAli.Bahrami@Sun.COM * Initializes the uvalue block for use. Returns True (1) if a non-empty
3169273SAli.Bahrami@Sun.COM * string was supplied, and False (0).
3179273SAli.Bahrami@Sun.COM */
3189273SAli.Bahrami@Sun.COM int
conv_iter_strtol_init(const char * str,conv_strtol_uvalue_t * uvalue)3199273SAli.Bahrami@Sun.COM conv_iter_strtol_init(const char *str, conv_strtol_uvalue_t *uvalue)
3209273SAli.Bahrami@Sun.COM {
3219273SAli.Bahrami@Sun.COM const char *tail;
3229273SAli.Bahrami@Sun.COM
323*9406SAli.Bahrami@Sun.COM while (conv_strproc_isspace(*str))
3249273SAli.Bahrami@Sun.COM str++;
3259273SAli.Bahrami@Sun.COM uvalue->csl_str = str;
3269273SAli.Bahrami@Sun.COM uvalue->csl_found = 0;
3271618Srie
3289273SAli.Bahrami@Sun.COM tail = str + strlen(str);
329*9406SAli.Bahrami@Sun.COM while ((tail > str) && conv_strproc_isspace(*(tail - 1)))
3309273SAli.Bahrami@Sun.COM tail--;
3319273SAli.Bahrami@Sun.COM uvalue->csl_strlen = tail - str;
3329273SAli.Bahrami@Sun.COM
3339273SAli.Bahrami@Sun.COM return (uvalue->csl_strlen > 0);
3349273SAli.Bahrami@Sun.COM }
3359273SAli.Bahrami@Sun.COM
3369273SAli.Bahrami@Sun.COM /*
3379273SAli.Bahrami@Sun.COM * conv_iter_strtol() is used with iteration functions to map a string
3389273SAli.Bahrami@Sun.COM * to the value of its corresponding ELF constant.
3399273SAli.Bahrami@Sun.COM *
3409273SAli.Bahrami@Sun.COM * entry:
3419273SAli.Bahrami@Sun.COM * str - String supplied by this iteration
3429273SAli.Bahrami@Sun.COM * value - Value of ELF constant corresponding to str
3439273SAli.Bahrami@Sun.COM * uvalue - Pointer to conv_strtol_uvalue_t block previously
3449273SAli.Bahrami@Sun.COM * initialized by a call to conv_iter_strtol_init().
3459273SAli.Bahrami@Sun.COM */
3469273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_strtol(const char * str,uint32_t value,void * uvalue)3479273SAli.Bahrami@Sun.COM conv_iter_strtol(const char *str, uint32_t value, void *uvalue)
3489273SAli.Bahrami@Sun.COM {
3499273SAli.Bahrami@Sun.COM conv_strtol_uvalue_t *state = (conv_strtol_uvalue_t *)uvalue;
3509273SAli.Bahrami@Sun.COM
3519273SAli.Bahrami@Sun.COM if ((strlen(str) == state->csl_strlen) &&
3529273SAli.Bahrami@Sun.COM (strncasecmp(str, state->csl_str, state->csl_strlen) == 0)) {
3539273SAli.Bahrami@Sun.COM state->csl_found = 1;
3549273SAli.Bahrami@Sun.COM state->csl_value = value;
3559273SAli.Bahrami@Sun.COM return (CONV_ITER_DONE); /* Found it. Stop now. */
3561618Srie }
3571618Srie
3589273SAli.Bahrami@Sun.COM return (CONV_ITER_CONT); /* Keep looking */
3591618Srie }
360