17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55aefb655Srie * Common Development and Distribution License (the "License").
65aefb655Srie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
215aefb655Srie
227c478bd9Sstevel@tonic-gate /*
234f680cc6SAli Bahrami * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <stdio.h>
285aefb655Srie #include <strings.h>
29ba2be530Sab #include <_machelf.h>
305aefb655Srie #include "_conv.h"
317c478bd9Sstevel@tonic-gate #include "globals_msg.h"
327c478bd9Sstevel@tonic-gate
33c13de8f6Sab
34c13de8f6Sab /*
354f680cc6SAli Bahrami * Map an integer into a descriptive string.
36c13de8f6Sab *
37c13de8f6Sab * entry:
384f680cc6SAli Bahrami * inv_buf - A buffer into which this routine can format
394f680cc6SAli Bahrami * a result string, if necessary.
404f680cc6SAli Bahrami * val - The value for which a string is desired.
414f680cc6SAli Bahrami * flags - CONV_FMT_* values to be passed to conv_invalid_val() if
424f680cc6SAli Bahrami * necessary. The caller is reponsible for having examined
434f680cc6SAli Bahrami * the CONV_FMT_ALT_* part of flags and passing the proper
444f680cc6SAli Bahrami * msg array.
454f680cc6SAli Bahrami * num_msg - # of Msg entries in msg.
464f680cc6SAli Bahrami * msg - Array of num_msg Msg items corresponding to the possible
474f680cc6SAli Bahrami * strings corresponding to val.
484f680cc6SAli Bahrami * local_sgs_msg - Message string table from module from which
494f680cc6SAli Bahrami * this function is called.
50c13de8f6Sab *
51c13de8f6Sab * exit:
524f680cc6SAli Bahrami * If val lies in the range [0-(num_msg-1)], then the string
534f680cc6SAli Bahrami * corresponding to it is returned. If val is outside the range,
544f680cc6SAli Bahrami * conv_invalid_val() is called to format an ASCII representation
554f680cc6SAli Bahrami * of it into inv_buf, and that is returned.
564f680cc6SAli Bahrami */
574f680cc6SAli Bahrami /*ARGSUSED5*/
584f680cc6SAli Bahrami 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)594f680cc6SAli Bahrami map_msg2str(Conv_inv_buf_t *inv_buf, Conv_elfvalue_t val,
604f680cc6SAli Bahrami Conv_fmt_flags_t flags, size_t num_msg, const Msg *msg,
614f680cc6SAli Bahrami const char *local_sgs_msg)
624f680cc6SAli Bahrami {
634f680cc6SAli Bahrami if ((val < num_msg) && (msg[val] != 0))
644f680cc6SAli Bahrami return (MSG_ORIG_STRTAB(msg[val], local_sgs_msg));
654f680cc6SAli Bahrami
664f680cc6SAli Bahrami /* If we get here, it's an unknown value */
674f680cc6SAli Bahrami return (conv_invalid_val(inv_buf, val, flags));
684f680cc6SAli Bahrami }
694f680cc6SAli Bahrami
704f680cc6SAli Bahrami /*
714f680cc6SAli Bahrami * Map an integer into a descriptive string from a NULL terminated
724f680cc6SAli Bahrami * array of Val_desc or Val_desc2 descriptors.
734f680cc6SAli Bahrami *
744f680cc6SAli Bahrami * entry:
754f680cc6SAli Bahrami * inv_buf - A buffer into which this routine can format
764f680cc6SAli Bahrami * a result string, if necessary.
774f680cc6SAli Bahrami * osabi,mach (_conv_vd22str only) - The osab/mach under which
784f680cc6SAli Bahrami * val is to be interpreted. Items with a non-0 osabi or machine
794f680cc6SAli Bahrami * that do not match are quietly ignored.
804f680cc6SAli Bahrami * val - The value for which a string is desired.
814f680cc6SAli Bahrami * flags - CONV_FMT_* values to be passed to conv_invalid_val() if
824f680cc6SAli Bahrami * necessary. The caller is reponsible for having examined
834f680cc6SAli Bahrami * the CONV_FMT_ALT_* part of flags and passing the proper
844f680cc6SAli Bahrami * descriptor array.
854f680cc6SAli Bahrami * vdp - Pointer to NULL terminated array of Val_desc descriptors.
864f680cc6SAli Bahrami * local_sgs_msg - Message string table from module from which
874f680cc6SAli Bahrami * this function is called.
884f680cc6SAli Bahrami *
894f680cc6SAli Bahrami * exit:
904f680cc6SAli Bahrami * If val is found in the vdp array, and in the osabi version of
914f680cc6SAli Bahrami * this function if the osabi matches, then the string corresponding
924f680cc6SAli Bahrami * val is returned. If a string for val is not found, conv_invalid_val()
934f680cc6SAli Bahrami * is called to format an ASCII representation of it into inv_buf, and
944f680cc6SAli Bahrami * that is returned.
954f680cc6SAli Bahrami */
964f680cc6SAli Bahrami /*ARGSUSED4*/
974f680cc6SAli Bahrami 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)984f680cc6SAli Bahrami map_vd2str(Conv_inv_buf_t *inv_buf, Conv_elfvalue_t val,
994f680cc6SAli Bahrami Conv_fmt_flags_t flags, const Val_desc *vdp, const char *local_sgs_msg)
1004f680cc6SAli Bahrami {
1014f680cc6SAli Bahrami for (; vdp->v_msg; vdp++) {
1024f680cc6SAli Bahrami if (val == vdp->v_val)
1034f680cc6SAli Bahrami return (MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg));
1044f680cc6SAli Bahrami }
1054f680cc6SAli Bahrami
1064f680cc6SAli Bahrami /* If we get here, it's an unknown value */
1074f680cc6SAli Bahrami return (conv_invalid_val(inv_buf, val, flags));
1084f680cc6SAli Bahrami }
1094f680cc6SAli Bahrami
1104f680cc6SAli Bahrami /*ARGSUSED6*/
1114f680cc6SAli Bahrami 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)1124f680cc6SAli Bahrami map_vd22str(Conv_inv_buf_t *inv_buf, uchar_t osabi, Half mach,
1134f680cc6SAli Bahrami Conv_elfvalue_t val, Conv_fmt_flags_t flags, const Val_desc2 *vdp,
1144f680cc6SAli Bahrami const char *local_sgs_msg)
1154f680cc6SAli Bahrami {
1164f680cc6SAli Bahrami for (; vdp->v_msg; vdp++) {
1174f680cc6SAli Bahrami if (CONV_VD2_SKIP(osabi, mach, vdp))
1184f680cc6SAli Bahrami continue;
1194f680cc6SAli Bahrami
1204f680cc6SAli Bahrami if (val == vdp->v_val)
1214f680cc6SAli Bahrami return (MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg));
1224f680cc6SAli Bahrami }
1234f680cc6SAli Bahrami
1244f680cc6SAli Bahrami /* If we get here, it's an unknown value */
1254f680cc6SAli Bahrami return (conv_invalid_val(inv_buf, val, flags));
1264f680cc6SAli Bahrami }
1274f680cc6SAli Bahrami
1284f680cc6SAli Bahrami /*
1294f680cc6SAli Bahrami * Process an array of conv_ds_XXX_t structures and call the appropriate
1304f680cc6SAli Bahrami * map functions for the format of the strings given.
131c13de8f6Sab */
1327c478bd9Sstevel@tonic-gate 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)1334f680cc6SAli Bahrami _conv_map_ds(uchar_t osabi, Half mach, Conv_elfvalue_t value,
1344f680cc6SAli Bahrami const conv_ds_t **dsp, Conv_fmt_flags_t fmt_flags, Conv_inv_buf_t *inv_buf,
1354f680cc6SAli Bahrami const char *local_sgs_msg)
1367c478bd9Sstevel@tonic-gate {
1374f680cc6SAli Bahrami const conv_ds_t *ds;
1384f680cc6SAli Bahrami
1394f680cc6SAli Bahrami for (ds = *dsp; ds != NULL; ds = *(++dsp)) {
1404f680cc6SAli Bahrami if ((value < ds->ds_baseval) || (value > ds->ds_topval))
1414f680cc6SAli Bahrami continue;
1424f680cc6SAli Bahrami
1434f680cc6SAli Bahrami switch (ds->ds_type) {
1444f680cc6SAli Bahrami case CONV_DS_MSGARR:
1454f680cc6SAli Bahrami return (map_msg2str(inv_buf, value - ds->ds_baseval,
1464f680cc6SAli Bahrami fmt_flags, ds->ds_topval - ds->ds_baseval + 1,
1474f680cc6SAli Bahrami /*LINTED*/
1484f680cc6SAli Bahrami ((conv_ds_msg_t *)ds)->ds_msg,
1494f680cc6SAli Bahrami local_sgs_msg));
1504f680cc6SAli Bahrami
1514f680cc6SAli Bahrami case CONV_DS_VD:
1524f680cc6SAli Bahrami return (map_vd2str(inv_buf, value, fmt_flags,
1534f680cc6SAli Bahrami /*LINTED*/
1544f680cc6SAli Bahrami ((conv_ds_vd_t *)ds)->ds_vd,
1554f680cc6SAli Bahrami local_sgs_msg));
1564f680cc6SAli Bahrami
1574f680cc6SAli Bahrami case CONV_DS_VD2:
1584f680cc6SAli Bahrami return (map_vd22str(inv_buf, osabi, mach, value,
1594f680cc6SAli Bahrami fmt_flags,
1604f680cc6SAli Bahrami /*LINTED*/
1614f680cc6SAli Bahrami ((conv_ds_vd2_t *)ds)->ds_vd2,
1624f680cc6SAli Bahrami local_sgs_msg));
1634f680cc6SAli Bahrami }
1645aefb655Srie }
1654f680cc6SAli Bahrami
1664f680cc6SAli Bahrami return (conv_invalid_val(inv_buf, value, fmt_flags));
1677c478bd9Sstevel@tonic-gate }
1685aefb655Srie
1694f680cc6SAli Bahrami /*
1704f680cc6SAli Bahrami * Iterate over every message string in a given array of Msg codes,
1714f680cc6SAli Bahrami * calling a user supplied callback for each one.
1724f680cc6SAli Bahrami *
1734f680cc6SAli Bahrami * entry:
1744f680cc6SAli Bahrami * basevalue - Value corresponding to the first Msg in the array.
1754f680cc6SAli Bahrami * local_sgs_msg - Pointer to the __sgs_msg array for the
1764f680cc6SAli Bahrami * libconv module making the call.
1774f680cc6SAli Bahrami * num_msg - # of items in array referenced by msg
1784f680cc6SAli Bahrami * msg - Array of Msg indexes for the strings to iterate over.
1794f680cc6SAli Bahrami * The value corresponding to each element of msg must be:
1804f680cc6SAli Bahrami * value[i] = basevalue + i
1814f680cc6SAli Bahrami * func, uvalue - User supplied function to be called for each
1824f680cc6SAli Bahrami * string in msg. uvalue is an arbitrary user supplied pointer
1834f680cc6SAli Bahrami * to be passed to func.
1844f680cc6SAli Bahrami * local_sgs_msg - Pointer to the __sgs_msg array for the
1854f680cc6SAli Bahrami * libconv module making the call.
1864f680cc6SAli Bahrami *
1874f680cc6SAli Bahrami * exit:
1884f680cc6SAli Bahrami * The callback function is called for every non-zero item in
1894f680cc6SAli Bahrami * msg[]. If any callback returns CONV_ITER_DONE, execution stops
1904f680cc6SAli Bahrami * with that item and the function returns immediately. Otherwise,
1914f680cc6SAli Bahrami * it continues to the end of the array.
1924f680cc6SAli Bahrami *
1934f680cc6SAli Bahrami * The value from the last callback is returned.
1944f680cc6SAli Bahrami */
1954f680cc6SAli Bahrami /*ARGSUSED5*/
1964f680cc6SAli Bahrami 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)1974f680cc6SAli Bahrami _conv_iter_msgarr(uint32_t basevalue, const Msg *msg, size_t num_msg,
1984f680cc6SAli Bahrami conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
1994f680cc6SAli Bahrami {
2004f680cc6SAli Bahrami for (; num_msg-- > 0; basevalue++, msg++) {
2014f680cc6SAli Bahrami if (*msg != 0)
2024f680cc6SAli Bahrami if ((* func)(MSG_ORIG_STRTAB(*msg, local_sgs_msg),
2034f680cc6SAli Bahrami basevalue, uvalue) == CONV_ITER_DONE)
2044f680cc6SAli Bahrami return (CONV_ITER_DONE);
2054f680cc6SAli Bahrami }
206c13de8f6Sab
2074f680cc6SAli Bahrami return (CONV_ITER_CONT);
2084f680cc6SAli Bahrami }
209c13de8f6Sab
210ba4e3c84Sab /*
2114f680cc6SAli Bahrami * Iterate over every message string in a given array of Val_desc or
2124f680cc6SAli Bahrami * Val_desc2 descriptors, calling a user supplied callback for each one.
213ba4e3c84Sab *
214ba4e3c84Sab * entry:
2154f680cc6SAli Bahrami * osabi,mach (_conv_iter_vd2 only) - The osabi/mach for which
2164f680cc6SAli Bahrami * strings are desired. Strings with a non-0 osabi or machine
2174f680cc6SAli Bahrami * that do not match are quietly ignored.
2184f680cc6SAli Bahrami * vdp - Pointer to NULL terminated array of Val_desc descriptors.
2194f680cc6SAli Bahrami * func, uvalue - User supplied function to be called for each
2204f680cc6SAli Bahrami * string in msg. uvalue is an arbitrary user supplied pointer
2214f680cc6SAli Bahrami * to be passed to func.
2224f680cc6SAli Bahrami * local_sgs_msg - Pointer to the __sgs_msg array for the
2234f680cc6SAli Bahrami * libconv module making the call.
224ba4e3c84Sab *
225ba4e3c84Sab * exit:
2264f680cc6SAli Bahrami * The callback function is called for every descriptor referenced by
2274f680cc6SAli Bahrami * vdp. In the case of the OSABI-version of this function, strings from
2284f680cc6SAli Bahrami * the wrong osabi are not used. If any callback returns CONV_ITER_DONE,
2294f680cc6SAli Bahrami * execution stops with that item and the function returns immediately.
2304f680cc6SAli Bahrami * Otherwise, it continues to the end of the array.
2314f680cc6SAli Bahrami *
2324f680cc6SAli Bahrami * The value from the last callback is returned.
233ba4e3c84Sab */
2344f680cc6SAli Bahrami /*ARGSUSED3*/
2354f680cc6SAli Bahrami conv_iter_ret_t
_conv_iter_vd(const Val_desc * vdp,conv_iter_cb_t func,void * uvalue,const char * local_sgs_msg)2364f680cc6SAli Bahrami _conv_iter_vd(const Val_desc *vdp, conv_iter_cb_t func, void *uvalue,
2374f680cc6SAli Bahrami const char *local_sgs_msg)
238ba4e3c84Sab {
2394f680cc6SAli Bahrami for (; vdp->v_msg; vdp++) {
2404f680cc6SAli Bahrami if ((* func)(MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg),
2414f680cc6SAli Bahrami vdp->v_val, uvalue) == CONV_ITER_DONE)
2424f680cc6SAli Bahrami return (CONV_ITER_DONE);
243ba4e3c84Sab }
244ba4e3c84Sab
2454f680cc6SAli Bahrami return (CONV_ITER_CONT);
2464f680cc6SAli Bahrami }
2474f680cc6SAli Bahrami
2484f680cc6SAli Bahrami /*ARGSUSED5*/
2494f680cc6SAli Bahrami 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)2504f680cc6SAli Bahrami _conv_iter_vd2(conv_iter_osabi_t osabi, Half mach, const Val_desc2 *vdp,
2514f680cc6SAli Bahrami conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
2524f680cc6SAli Bahrami {
2534f680cc6SAli Bahrami for (; vdp->v_msg; vdp++) {
2544f680cc6SAli Bahrami if (CONV_ITER_VD2_SKIP(osabi, mach, vdp))
2554f680cc6SAli Bahrami continue;
2564f680cc6SAli Bahrami
2574f680cc6SAli Bahrami if ((* func)(MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg),
2584f680cc6SAli Bahrami vdp->v_val, uvalue) == CONV_ITER_DONE)
2594f680cc6SAli Bahrami return (CONV_ITER_DONE);
260ba4e3c84Sab }
261ba4e3c84Sab
2624f680cc6SAli Bahrami return (CONV_ITER_CONT);
263ba4e3c84Sab }
264ba4e3c84Sab
2654f680cc6SAli Bahrami /*
2664f680cc6SAli Bahrami * Process an array of conv_ds_XXX_t structures and call the appropriate
2674f680cc6SAli Bahrami * iteration functions for the format of the strings given.
2684f680cc6SAli Bahrami */
2694f680cc6SAli Bahrami 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)2704f680cc6SAli Bahrami _conv_iter_ds(conv_iter_osabi_t osabi, Half mach, const conv_ds_t **dsp,
2714f680cc6SAli Bahrami conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
2724f680cc6SAli Bahrami {
2734f680cc6SAli Bahrami const conv_ds_t *ds;
2744f680cc6SAli Bahrami
2754f680cc6SAli Bahrami for (ds = *dsp; ds != NULL; ds = *(++dsp)) {
2764f680cc6SAli Bahrami switch (ds->ds_type) {
2774f680cc6SAli Bahrami case CONV_DS_MSGARR:
2784f680cc6SAli Bahrami if (_conv_iter_msgarr(ds->ds_baseval,
2794f680cc6SAli Bahrami /*LINTED*/
2804f680cc6SAli Bahrami ((conv_ds_msg_t *)ds)->ds_msg,
2814f680cc6SAli Bahrami ds->ds_topval - ds->ds_baseval + 1, func, uvalue,
2824f680cc6SAli Bahrami local_sgs_msg) == CONV_ITER_DONE)
2834f680cc6SAli Bahrami return (CONV_ITER_DONE);
2844f680cc6SAli Bahrami break;
285ba4e3c84Sab
2864f680cc6SAli Bahrami case CONV_DS_VD:
2874f680cc6SAli Bahrami /*LINTED*/
2884f680cc6SAli Bahrami if (_conv_iter_vd(((conv_ds_vd_t *)ds)->ds_vd,
2894f680cc6SAli Bahrami func, uvalue, local_sgs_msg) == CONV_ITER_DONE)
2904f680cc6SAli Bahrami return (CONV_ITER_DONE);
2914f680cc6SAli Bahrami break;
2924f680cc6SAli Bahrami
2934f680cc6SAli Bahrami case CONV_DS_VD2:
2944f680cc6SAli Bahrami if (_conv_iter_vd2(osabi, mach,
2954f680cc6SAli Bahrami /*LINTED*/
2964f680cc6SAli Bahrami ((conv_ds_vd2_t *)ds)->ds_vd2,
2974f680cc6SAli Bahrami func, uvalue, local_sgs_msg) == CONV_ITER_DONE)
2984f680cc6SAli Bahrami return (CONV_ITER_DONE);
2994f680cc6SAli Bahrami break;
3004f680cc6SAli Bahrami }
3014f680cc6SAli Bahrami }
3024f680cc6SAli Bahrami
3034f680cc6SAli Bahrami return (CONV_ITER_CONT);
3044f680cc6SAli Bahrami }
305ba4e3c84Sab
3065aefb655Srie /*
3074f680cc6SAli Bahrami * Initialize the uvalue block prior to use of an interation function
3084f680cc6SAli Bahrami * employing conv_iter_strtol().
309c13de8f6Sab *
310c13de8f6Sab * entry:
3114f680cc6SAli Bahrami * str - String to be matched to a value
3124f680cc6SAli Bahrami * uvalue - Pointer to uninitialized uvalue block
313c13de8f6Sab *
314c13de8f6Sab * exit:
3154f680cc6SAli Bahrami * Initializes the uvalue block for use. Returns True (1) if a non-empty
3164f680cc6SAli Bahrami * string was supplied, and False (0).
3175aefb655Srie */
3185aefb655Srie int
conv_iter_strtol_init(const char * str,conv_strtol_uvalue_t * uvalue)3194f680cc6SAli Bahrami conv_iter_strtol_init(const char *str, conv_strtol_uvalue_t *uvalue)
3205aefb655Srie {
3214f680cc6SAli Bahrami const char *tail;
3225aefb655Srie
323*e23c41c9SAli Bahrami while (conv_strproc_isspace(*str))
3244f680cc6SAli Bahrami str++;
3254f680cc6SAli Bahrami uvalue->csl_str = str;
3264f680cc6SAli Bahrami uvalue->csl_found = 0;
3275aefb655Srie
3284f680cc6SAli Bahrami tail = str + strlen(str);
329*e23c41c9SAli Bahrami while ((tail > str) && conv_strproc_isspace(*(tail - 1)))
3304f680cc6SAli Bahrami tail--;
3314f680cc6SAli Bahrami uvalue->csl_strlen = tail - str;
3325aefb655Srie
3334f680cc6SAli Bahrami return (uvalue->csl_strlen > 0);
3344f680cc6SAli Bahrami }
3355aefb655Srie
3364f680cc6SAli Bahrami /*
3374f680cc6SAli Bahrami * conv_iter_strtol() is used with iteration functions to map a string
3384f680cc6SAli Bahrami * to the value of its corresponding ELF constant.
3394f680cc6SAli Bahrami *
3404f680cc6SAli Bahrami * entry:
3414f680cc6SAli Bahrami * str - String supplied by this iteration
3424f680cc6SAli Bahrami * value - Value of ELF constant corresponding to str
3434f680cc6SAli Bahrami * uvalue - Pointer to conv_strtol_uvalue_t block previously
3444f680cc6SAli Bahrami * initialized by a call to conv_iter_strtol_init().
3454f680cc6SAli Bahrami */
3464f680cc6SAli Bahrami conv_iter_ret_t
conv_iter_strtol(const char * str,uint32_t value,void * uvalue)3474f680cc6SAli Bahrami conv_iter_strtol(const char *str, uint32_t value, void *uvalue)
3484f680cc6SAli Bahrami {
3494f680cc6SAli Bahrami conv_strtol_uvalue_t *state = (conv_strtol_uvalue_t *)uvalue;
350ba4e3c84Sab
3514f680cc6SAli Bahrami if ((strlen(str) == state->csl_strlen) &&
3524f680cc6SAli Bahrami (strncasecmp(str, state->csl_str, state->csl_strlen) == 0)) {
3534f680cc6SAli Bahrami state->csl_found = 1;
3544f680cc6SAli Bahrami state->csl_value = value;
3554f680cc6SAli Bahrami return (CONV_ITER_DONE); /* Found it. Stop now. */
3564f680cc6SAli Bahrami }
357ba4e3c84Sab
3584f680cc6SAli Bahrami return (CONV_ITER_CONT); /* Keep looking */
3595aefb655Srie }
360