Home | History | Annotate | Line # | Download | only in utilities
utclib.c revision 1.1.1.15.6.1
      1           1.1    jruoho /******************************************************************************
      2           1.1    jruoho  *
      3       1.1.1.6  christos  * Module Name: utclib - ACPICA implementations of C library functions
      4           1.1    jruoho  *
      5           1.1    jruoho  *****************************************************************************/
      6           1.1    jruoho 
      7  1.1.1.15.6.1  perseant /******************************************************************************
      8  1.1.1.15.6.1  perseant  *
      9  1.1.1.15.6.1  perseant  * 1. Copyright Notice
     10  1.1.1.15.6.1  perseant  *
     11  1.1.1.15.6.1  perseant  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
     12           1.1    jruoho  * All rights reserved.
     13           1.1    jruoho  *
     14  1.1.1.15.6.1  perseant  * 2. License
     15  1.1.1.15.6.1  perseant  *
     16  1.1.1.15.6.1  perseant  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1.1.15.6.1  perseant  * rights. You may have additional license terms from the party that provided
     18  1.1.1.15.6.1  perseant  * you this software, covering your right to use that party's intellectual
     19  1.1.1.15.6.1  perseant  * property rights.
     20  1.1.1.15.6.1  perseant  *
     21  1.1.1.15.6.1  perseant  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1.1.15.6.1  perseant  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1.1.15.6.1  perseant  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1.1.15.6.1  perseant  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1.1.15.6.1  perseant  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1.1.15.6.1  perseant  * Code in any form, with the right to sublicense such rights; and
     27  1.1.1.15.6.1  perseant  *
     28  1.1.1.15.6.1  perseant  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1.1.15.6.1  perseant  * license (with the right to sublicense), under only those claims of Intel
     30  1.1.1.15.6.1  perseant  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1.1.15.6.1  perseant  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1.1.15.6.1  perseant  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1.1.15.6.1  perseant  * license, and in no event shall the patent license extend to any additions
     34  1.1.1.15.6.1  perseant  * to or modifications of the Original Intel Code. No other license or right
     35  1.1.1.15.6.1  perseant  * is granted directly or by implication, estoppel or otherwise;
     36  1.1.1.15.6.1  perseant  *
     37  1.1.1.15.6.1  perseant  * The above copyright and patent license is granted only if the following
     38  1.1.1.15.6.1  perseant  * conditions are met:
     39  1.1.1.15.6.1  perseant  *
     40  1.1.1.15.6.1  perseant  * 3. Conditions
     41  1.1.1.15.6.1  perseant  *
     42  1.1.1.15.6.1  perseant  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1.1.15.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     44  1.1.1.15.6.1  perseant  * Code or modification with rights to further distribute source must include
     45  1.1.1.15.6.1  perseant  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1.1.15.6.1  perseant  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.1.1.15.6.1  perseant  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1.1.15.6.1  perseant  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1.1.15.6.1  perseant  * Code and the date of any change. Licensee must include in that file the
     50  1.1.1.15.6.1  perseant  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.1.1.15.6.1  perseant  * must include a prominent statement that the modification is derived,
     52  1.1.1.15.6.1  perseant  * directly or indirectly, from Original Intel Code.
     53  1.1.1.15.6.1  perseant  *
     54  1.1.1.15.6.1  perseant  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1.1.15.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     56  1.1.1.15.6.1  perseant  * Code or modification without rights to further distribute source must
     57  1.1.1.15.6.1  perseant  * include the following Disclaimer and Export Compliance provision in the
     58  1.1.1.15.6.1  perseant  * documentation and/or other materials provided with distribution. In
     59  1.1.1.15.6.1  perseant  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1.1.15.6.1  perseant  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1.1.15.6.1  perseant  * license from Licensee to its licensee is limited to the intellectual
     62  1.1.1.15.6.1  perseant  * property embodied in the software Licensee provides to its licensee, and
     63  1.1.1.15.6.1  perseant  * not to intellectual property embodied in modifications its licensee may
     64  1.1.1.15.6.1  perseant  * make.
     65  1.1.1.15.6.1  perseant  *
     66  1.1.1.15.6.1  perseant  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1.1.15.6.1  perseant  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1.1.15.6.1  perseant  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1.1.15.6.1  perseant  * provision in the documentation and/or other materials provided with the
     70  1.1.1.15.6.1  perseant  * distribution.
     71  1.1.1.15.6.1  perseant  *
     72  1.1.1.15.6.1  perseant  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1.1.15.6.1  perseant  * Intel Code.
     74  1.1.1.15.6.1  perseant  *
     75  1.1.1.15.6.1  perseant  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1.1.15.6.1  perseant  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1.1.15.6.1  perseant  * other dealings in products derived from or relating to the Covered Code
     78  1.1.1.15.6.1  perseant  * without prior written authorization from Intel.
     79  1.1.1.15.6.1  perseant  *
     80  1.1.1.15.6.1  perseant  * 4. Disclaimer and Export Compliance
     81  1.1.1.15.6.1  perseant  *
     82  1.1.1.15.6.1  perseant  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1.1.15.6.1  perseant  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1.1.15.6.1  perseant  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.1.1.15.6.1  perseant  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.1.1.15.6.1  perseant  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1.1.15.6.1  perseant  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1.1.15.6.1  perseant  * PARTICULAR PURPOSE.
     89  1.1.1.15.6.1  perseant  *
     90  1.1.1.15.6.1  perseant  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1.1.15.6.1  perseant  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1.1.15.6.1  perseant  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1.1.15.6.1  perseant  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1.1.15.6.1  perseant  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1.1.15.6.1  perseant  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.1.1.15.6.1  perseant  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1.1.15.6.1  perseant  * LIMITED REMEDY.
     98  1.1.1.15.6.1  perseant  *
     99  1.1.1.15.6.1  perseant  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1.1.15.6.1  perseant  * software or system incorporating such software without first obtaining any
    101  1.1.1.15.6.1  perseant  * required license or other approval from the U. S. Department of Commerce or
    102  1.1.1.15.6.1  perseant  * any other agency or department of the United States Government. In the
    103  1.1.1.15.6.1  perseant  * event Licensee exports any such software from the United States or
    104  1.1.1.15.6.1  perseant  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1.1.15.6.1  perseant  * ensure that the distribution and export/re-export of the software is in
    106  1.1.1.15.6.1  perseant  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1.1.15.6.1  perseant  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1.1.15.6.1  perseant  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1.1.15.6.1  perseant  * software, or service, directly or indirectly, to any country for which the
    110  1.1.1.15.6.1  perseant  * United States government or any agency thereof requires an export license,
    111  1.1.1.15.6.1  perseant  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1.1.15.6.1  perseant  * such license, approval or letter.
    113  1.1.1.15.6.1  perseant  *
    114  1.1.1.15.6.1  perseant  *****************************************************************************
    115  1.1.1.15.6.1  perseant  *
    116  1.1.1.15.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    117  1.1.1.15.6.1  perseant  * following license:
    118  1.1.1.15.6.1  perseant  *
    119       1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
    120       1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
    121       1.1.1.2    jruoho  * are met:
    122       1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
    123       1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
    124       1.1.1.2    jruoho  *    without modification.
    125       1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126       1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
    127       1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
    128       1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
    129       1.1.1.2    jruoho  *    binary redistribution.
    130       1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
    131       1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
    132       1.1.1.2    jruoho  *    from this software without specific prior written permission.
    133       1.1.1.2    jruoho  *
    134       1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135       1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136      1.1.1.13  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137       1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.1.1.15.6.1  perseant  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.1.1.15.6.1  perseant  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.1.1.15.6.1  perseant  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.1.1.15.6.1  perseant  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.1.1.15.6.1  perseant  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.1.1.15.6.1  perseant  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.1.1.15.6.1  perseant  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.1.1.15.6.1  perseant  *
    146  1.1.1.15.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    147  1.1.1.15.6.1  perseant  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.1.1.15.6.1  perseant  * Software Foundation.
    149  1.1.1.15.6.1  perseant  *
    150  1.1.1.15.6.1  perseant  *****************************************************************************/
    151           1.1    jruoho 
    152       1.1.1.6  christos #define ACPI_CLIBRARY
    153           1.1    jruoho #include "acpi.h"
    154           1.1    jruoho #include "accommon.h"
    155           1.1    jruoho 
    156           1.1    jruoho /*
    157       1.1.1.6  christos  * This module contains implementations of the standard C library functions
    158       1.1.1.6  christos  * that are required by the ACPICA code at both application level and kernel
    159       1.1.1.6  christos  * level.
    160       1.1.1.6  christos  *
    161       1.1.1.6  christos  * The module is an optional feature that can be used if a local/system
    162       1.1.1.6  christos  * C library is not available. Some operating system kernels may not have
    163       1.1.1.6  christos  * an internal C library.
    164       1.1.1.6  christos  *
    165       1.1.1.6  christos  * In general, these functions are less efficient than an inline or assembly
    166       1.1.1.6  christos  * code implementation.
    167       1.1.1.6  christos  *
    168       1.1.1.6  christos  * These C functions and the associated prototypes are enabled by default
    169       1.1.1.6  christos  * unless the ACPI_USE_SYSTEM_CLIBRARY symbol is defined. This is usually
    170       1.1.1.6  christos  * automatically defined for the ACPICA applications such as iASL and
    171       1.1.1.6  christos  * AcpiExec, so that these user-level applications use the local C library
    172       1.1.1.6  christos  * instead of the functions in this module.
    173           1.1    jruoho  */
    174           1.1    jruoho 
    175       1.1.1.6  christos /*******************************************************************************
    176       1.1.1.6  christos  *
    177       1.1.1.6  christos  * Functions implemented in this module:
    178       1.1.1.6  christos  *
    179       1.1.1.6  christos  * FUNCTION:    memcmp
    180       1.1.1.6  christos  * FUNCTION:    memcpy
    181       1.1.1.6  christos  * FUNCTION:    memset
    182       1.1.1.6  christos  * FUNCTION:    strlen
    183       1.1.1.6  christos  * FUNCTION:    strcpy
    184       1.1.1.6  christos  * FUNCTION:    strncpy
    185       1.1.1.6  christos  * FUNCTION:    strcmp
    186       1.1.1.6  christos  * FUNCTION:    strchr
    187       1.1.1.6  christos  * FUNCTION:    strncmp
    188       1.1.1.6  christos  * FUNCTION:    strcat
    189       1.1.1.6  christos  * FUNCTION:    strncat
    190       1.1.1.6  christos  * FUNCTION:    strstr
    191       1.1.1.6  christos  * FUNCTION:    strtoul
    192       1.1.1.6  christos  * FUNCTION:    toupper
    193       1.1.1.6  christos  * FUNCTION:    tolower
    194       1.1.1.6  christos  * FUNCTION:    is* functions
    195       1.1.1.6  christos  *
    196       1.1.1.6  christos  ******************************************************************************/
    197           1.1    jruoho 
    198       1.1.1.6  christos #define _COMPONENT          ACPI_UTILITIES
    199       1.1.1.6  christos         ACPI_MODULE_NAME    ("utclib")
    200           1.1    jruoho 
    201           1.1    jruoho 
    202       1.1.1.6  christos #ifndef ACPI_USE_SYSTEM_CLIBRARY    /* Entire module */
    203           1.1    jruoho 
    204           1.1    jruoho 
    205           1.1    jruoho /*******************************************************************************
    206           1.1    jruoho  *
    207       1.1.1.6  christos  * FUNCTION:    memcmp
    208           1.1    jruoho  *
    209           1.1    jruoho  * PARAMETERS:  Buffer1         - First Buffer
    210           1.1    jruoho  *              Buffer2         - Second Buffer
    211           1.1    jruoho  *              Count           - Maximum # of bytes to compare
    212           1.1    jruoho  *
    213           1.1    jruoho  * RETURN:      Index where Buffers mismatched, or 0 if Buffers matched
    214           1.1    jruoho  *
    215           1.1    jruoho  * DESCRIPTION: Compare two Buffers, with a maximum length
    216           1.1    jruoho  *
    217           1.1    jruoho  ******************************************************************************/
    218           1.1    jruoho 
    219           1.1    jruoho int
    220       1.1.1.6  christos memcmp (
    221       1.1.1.6  christos     void                    *VBuffer1,
    222       1.1.1.6  christos     void                    *VBuffer2,
    223           1.1    jruoho     ACPI_SIZE               Count)
    224           1.1    jruoho {
    225       1.1.1.6  christos     char                    *Buffer1 = (char *) VBuffer1;
    226       1.1.1.6  christos     char                    *Buffer2 = (char *) VBuffer2;
    227       1.1.1.6  christos 
    228           1.1    jruoho 
    229           1.1    jruoho     for ( ; Count-- && (*Buffer1 == *Buffer2); Buffer1++, Buffer2++)
    230           1.1    jruoho     {
    231           1.1    jruoho     }
    232           1.1    jruoho 
    233           1.1    jruoho     return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *Buffer1 -
    234           1.1    jruoho         (unsigned char) *Buffer2));
    235           1.1    jruoho }
    236           1.1    jruoho 
    237           1.1    jruoho 
    238           1.1    jruoho /*******************************************************************************
    239           1.1    jruoho  *
    240       1.1.1.8  christos  * FUNCTION:    memmove
    241       1.1.1.8  christos  *
    242       1.1.1.8  christos  * PARAMETERS:  Dest        - Target of the copy
    243       1.1.1.8  christos  *              Src         - Source buffer to copy
    244       1.1.1.8  christos  *              Count       - Number of bytes to copy
    245       1.1.1.8  christos  *
    246       1.1.1.8  christos  * RETURN:      Dest
    247       1.1.1.8  christos  *
    248       1.1.1.8  christos  * DESCRIPTION: Copy arbitrary bytes of memory with respect to the overlapping
    249       1.1.1.8  christos  *
    250       1.1.1.8  christos  ******************************************************************************/
    251       1.1.1.8  christos 
    252       1.1.1.8  christos void *
    253       1.1.1.8  christos memmove (
    254       1.1.1.8  christos     void                    *Dest,
    255       1.1.1.8  christos     const void              *Src,
    256       1.1.1.8  christos     ACPI_SIZE               Count)
    257       1.1.1.8  christos {
    258       1.1.1.8  christos     char                    *New = (char *) Dest;
    259       1.1.1.8  christos     char                    *Old = (char *) Src;
    260       1.1.1.8  christos 
    261       1.1.1.8  christos 
    262       1.1.1.8  christos     if (Old > New)
    263       1.1.1.8  christos     {
    264       1.1.1.8  christos         /* Copy from the beginning */
    265       1.1.1.8  christos 
    266       1.1.1.8  christos         while (Count)
    267       1.1.1.8  christos         {
    268       1.1.1.8  christos             *New = *Old;
    269       1.1.1.8  christos             New++;
    270       1.1.1.8  christos             Old++;
    271       1.1.1.8  christos             Count--;
    272       1.1.1.8  christos         }
    273       1.1.1.8  christos     }
    274       1.1.1.8  christos     else if (Old < New)
    275       1.1.1.8  christos     {
    276       1.1.1.8  christos         /* Copy from the end */
    277       1.1.1.8  christos 
    278       1.1.1.8  christos         New = New + Count - 1;
    279       1.1.1.8  christos         Old = Old + Count - 1;
    280       1.1.1.8  christos         while (Count)
    281       1.1.1.8  christos         {
    282       1.1.1.8  christos             *New = *Old;
    283       1.1.1.8  christos             New--;
    284       1.1.1.8  christos             Old--;
    285       1.1.1.8  christos             Count--;
    286       1.1.1.8  christos         }
    287       1.1.1.8  christos     }
    288       1.1.1.8  christos 
    289       1.1.1.8  christos     return (Dest);
    290       1.1.1.8  christos }
    291       1.1.1.8  christos 
    292       1.1.1.8  christos 
    293       1.1.1.8  christos /*******************************************************************************
    294       1.1.1.8  christos  *
    295       1.1.1.6  christos  * FUNCTION:    memcpy
    296           1.1    jruoho  *
    297           1.1    jruoho  * PARAMETERS:  Dest        - Target of the copy
    298           1.1    jruoho  *              Src         - Source buffer to copy
    299           1.1    jruoho  *              Count       - Number of bytes to copy
    300           1.1    jruoho  *
    301           1.1    jruoho  * RETURN:      Dest
    302           1.1    jruoho  *
    303           1.1    jruoho  * DESCRIPTION: Copy arbitrary bytes of memory
    304           1.1    jruoho  *
    305           1.1    jruoho  ******************************************************************************/
    306           1.1    jruoho 
    307           1.1    jruoho void *
    308       1.1.1.6  christos memcpy (
    309           1.1    jruoho     void                    *Dest,
    310           1.1    jruoho     const void              *Src,
    311           1.1    jruoho     ACPI_SIZE               Count)
    312           1.1    jruoho {
    313           1.1    jruoho     char                    *New = (char *) Dest;
    314           1.1    jruoho     char                    *Old = (char *) Src;
    315           1.1    jruoho 
    316           1.1    jruoho 
    317           1.1    jruoho     while (Count)
    318           1.1    jruoho     {
    319           1.1    jruoho         *New = *Old;
    320           1.1    jruoho         New++;
    321           1.1    jruoho         Old++;
    322           1.1    jruoho         Count--;
    323           1.1    jruoho     }
    324           1.1    jruoho 
    325           1.1    jruoho     return (Dest);
    326           1.1    jruoho }
    327           1.1    jruoho 
    328           1.1    jruoho 
    329           1.1    jruoho /*******************************************************************************
    330           1.1    jruoho  *
    331       1.1.1.6  christos  * FUNCTION:    memset
    332           1.1    jruoho  *
    333           1.1    jruoho  * PARAMETERS:  Dest        - Buffer to set
    334           1.1    jruoho  *              Value       - Value to set each byte of memory
    335           1.1    jruoho  *              Count       - Number of bytes to set
    336           1.1    jruoho  *
    337           1.1    jruoho  * RETURN:      Dest
    338           1.1    jruoho  *
    339           1.1    jruoho  * DESCRIPTION: Initialize a buffer to a known value.
    340           1.1    jruoho  *
    341           1.1    jruoho  ******************************************************************************/
    342           1.1    jruoho 
    343           1.1    jruoho void *
    344       1.1.1.6  christos memset (
    345           1.1    jruoho     void                    *Dest,
    346       1.1.1.6  christos     int                     Value,
    347           1.1    jruoho     ACPI_SIZE               Count)
    348           1.1    jruoho {
    349           1.1    jruoho     char                    *New = (char *) Dest;
    350           1.1    jruoho 
    351           1.1    jruoho 
    352           1.1    jruoho     while (Count)
    353           1.1    jruoho     {
    354           1.1    jruoho         *New = (char) Value;
    355           1.1    jruoho         New++;
    356           1.1    jruoho         Count--;
    357           1.1    jruoho     }
    358           1.1    jruoho 
    359           1.1    jruoho     return (Dest);
    360           1.1    jruoho }
    361           1.1    jruoho 
    362           1.1    jruoho 
    363           1.1    jruoho /*******************************************************************************
    364           1.1    jruoho  *
    365       1.1.1.6  christos  * FUNCTION:    strlen
    366           1.1    jruoho  *
    367           1.1    jruoho  * PARAMETERS:  String              - Null terminated string
    368           1.1    jruoho  *
    369           1.1    jruoho  * RETURN:      Length
    370           1.1    jruoho  *
    371           1.1    jruoho  * DESCRIPTION: Returns the length of the input string
    372           1.1    jruoho  *
    373           1.1    jruoho  ******************************************************************************/
    374           1.1    jruoho 
    375           1.1    jruoho 
    376           1.1    jruoho ACPI_SIZE
    377       1.1.1.6  christos strlen (
    378           1.1    jruoho     const char              *String)
    379           1.1    jruoho {
    380           1.1    jruoho     UINT32                  Length = 0;
    381           1.1    jruoho 
    382           1.1    jruoho 
    383           1.1    jruoho     /* Count the string until a null is encountered */
    384           1.1    jruoho 
    385           1.1    jruoho     while (*String)
    386           1.1    jruoho     {
    387           1.1    jruoho         Length++;
    388           1.1    jruoho         String++;
    389           1.1    jruoho     }
    390           1.1    jruoho 
    391           1.1    jruoho     return (Length);
    392           1.1    jruoho }
    393           1.1    jruoho 
    394           1.1    jruoho 
    395           1.1    jruoho /*******************************************************************************
    396           1.1    jruoho  *
    397       1.1.1.8  christos  * FUNCTION:    strpbrk
    398       1.1.1.8  christos  *
    399       1.1.1.8  christos  * PARAMETERS:  String              - Null terminated string
    400       1.1.1.8  christos  *              Delimiters          - Delimiters to match
    401       1.1.1.8  christos  *
    402      1.1.1.11  christos  * RETURN:      The first occurrence in the string of any of the bytes in the
    403       1.1.1.8  christos  *              delimiters
    404       1.1.1.8  christos  *
    405       1.1.1.8  christos  * DESCRIPTION: Search a string for any of a set of the delimiters
    406       1.1.1.8  christos  *
    407       1.1.1.8  christos  ******************************************************************************/
    408       1.1.1.8  christos 
    409       1.1.1.8  christos char *
    410       1.1.1.8  christos strpbrk (
    411       1.1.1.8  christos     const char              *String,
    412       1.1.1.8  christos     const char              *Delimiters)
    413       1.1.1.8  christos {
    414       1.1.1.8  christos     const char              *Delimiter;
    415       1.1.1.8  christos 
    416       1.1.1.8  christos 
    417       1.1.1.8  christos     for ( ; *String != '\0'; ++String)
    418       1.1.1.8  christos     {
    419       1.1.1.8  christos         for (Delimiter = Delimiters; *Delimiter != '\0'; Delimiter++)
    420       1.1.1.8  christos         {
    421       1.1.1.8  christos             if (*String == *Delimiter)
    422       1.1.1.8  christos             {
    423       1.1.1.8  christos                 return (ACPI_CAST_PTR (char, String));
    424       1.1.1.8  christos             }
    425       1.1.1.8  christos         }
    426       1.1.1.8  christos     }
    427       1.1.1.8  christos 
    428       1.1.1.8  christos     return (NULL);
    429       1.1.1.8  christos }
    430       1.1.1.8  christos 
    431       1.1.1.8  christos 
    432       1.1.1.8  christos /*******************************************************************************
    433       1.1.1.8  christos  *
    434       1.1.1.8  christos  * FUNCTION:    strtok
    435       1.1.1.8  christos  *
    436       1.1.1.8  christos  * PARAMETERS:  String              - Null terminated string
    437       1.1.1.8  christos  *              Delimiters          - Delimiters to match
    438       1.1.1.8  christos  *
    439       1.1.1.8  christos  * RETURN:      Pointer to the next token
    440       1.1.1.8  christos  *
    441       1.1.1.8  christos  * DESCRIPTION: Split string into tokens
    442       1.1.1.8  christos  *
    443       1.1.1.8  christos  ******************************************************************************/
    444       1.1.1.8  christos 
    445       1.1.1.8  christos char*
    446       1.1.1.8  christos strtok (
    447       1.1.1.8  christos     char                    *String,
    448       1.1.1.8  christos     const char              *Delimiters)
    449       1.1.1.8  christos {
    450       1.1.1.8  christos     char                    *Begin = String;
    451       1.1.1.8  christos     static char             *SavedPtr;
    452       1.1.1.8  christos 
    453       1.1.1.8  christos 
    454       1.1.1.8  christos     if (Begin == NULL)
    455       1.1.1.8  christos     {
    456       1.1.1.8  christos         if (SavedPtr == NULL)
    457       1.1.1.8  christos         {
    458       1.1.1.8  christos             return (NULL);
    459       1.1.1.8  christos         }
    460       1.1.1.8  christos         Begin = SavedPtr;
    461       1.1.1.8  christos     }
    462       1.1.1.8  christos 
    463       1.1.1.8  christos     SavedPtr = strpbrk (Begin, Delimiters);
    464       1.1.1.8  christos     while (SavedPtr == Begin)
    465       1.1.1.8  christos     {
    466       1.1.1.8  christos         *Begin++ = '\0';
    467       1.1.1.8  christos         SavedPtr = strpbrk (Begin, Delimiters);
    468       1.1.1.8  christos     }
    469       1.1.1.8  christos 
    470       1.1.1.8  christos     if (SavedPtr)
    471       1.1.1.8  christos     {
    472       1.1.1.8  christos         *SavedPtr++ = '\0';
    473       1.1.1.8  christos         return (Begin);
    474       1.1.1.8  christos     }
    475       1.1.1.8  christos     else
    476       1.1.1.8  christos     {
    477       1.1.1.8  christos         return (NULL);
    478       1.1.1.8  christos     }
    479       1.1.1.8  christos }
    480       1.1.1.8  christos 
    481       1.1.1.8  christos 
    482       1.1.1.8  christos /*******************************************************************************
    483       1.1.1.8  christos  *
    484       1.1.1.6  christos  * FUNCTION:    strcpy
    485           1.1    jruoho  *
    486           1.1    jruoho  * PARAMETERS:  DstString       - Target of the copy
    487           1.1    jruoho  *              SrcString       - The source string to copy
    488           1.1    jruoho  *
    489           1.1    jruoho  * RETURN:      DstString
    490           1.1    jruoho  *
    491           1.1    jruoho  * DESCRIPTION: Copy a null terminated string
    492           1.1    jruoho  *
    493           1.1    jruoho  ******************************************************************************/
    494           1.1    jruoho 
    495           1.1    jruoho char *
    496       1.1.1.6  christos strcpy (
    497           1.1    jruoho     char                    *DstString,
    498           1.1    jruoho     const char              *SrcString)
    499           1.1    jruoho {
    500           1.1    jruoho     char                    *String = DstString;
    501           1.1    jruoho 
    502           1.1    jruoho 
    503           1.1    jruoho     /* Move bytes brute force */
    504           1.1    jruoho 
    505           1.1    jruoho     while (*SrcString)
    506           1.1    jruoho     {
    507           1.1    jruoho         *String = *SrcString;
    508           1.1    jruoho 
    509           1.1    jruoho         String++;
    510           1.1    jruoho         SrcString++;
    511           1.1    jruoho     }
    512           1.1    jruoho 
    513           1.1    jruoho     /* Null terminate */
    514           1.1    jruoho 
    515           1.1    jruoho     *String = 0;
    516           1.1    jruoho     return (DstString);
    517           1.1    jruoho }
    518           1.1    jruoho 
    519           1.1    jruoho 
    520           1.1    jruoho /*******************************************************************************
    521           1.1    jruoho  *
    522       1.1.1.6  christos  * FUNCTION:    strncpy
    523           1.1    jruoho  *
    524           1.1    jruoho  * PARAMETERS:  DstString       - Target of the copy
    525           1.1    jruoho  *              SrcString       - The source string to copy
    526           1.1    jruoho  *              Count           - Maximum # of bytes to copy
    527           1.1    jruoho  *
    528           1.1    jruoho  * RETURN:      DstString
    529           1.1    jruoho  *
    530           1.1    jruoho  * DESCRIPTION: Copy a null terminated string, with a maximum length
    531           1.1    jruoho  *
    532           1.1    jruoho  ******************************************************************************/
    533           1.1    jruoho 
    534           1.1    jruoho char *
    535       1.1.1.6  christos strncpy (
    536           1.1    jruoho     char                    *DstString,
    537           1.1    jruoho     const char              *SrcString,
    538           1.1    jruoho     ACPI_SIZE               Count)
    539           1.1    jruoho {
    540           1.1    jruoho     char                    *String = DstString;
    541           1.1    jruoho 
    542           1.1    jruoho 
    543           1.1    jruoho     /* Copy the string */
    544           1.1    jruoho 
    545           1.1    jruoho     for (String = DstString;
    546           1.1    jruoho         Count && (Count--, (*String++ = *SrcString++)); )
    547           1.1    jruoho     {;}
    548           1.1    jruoho 
    549           1.1    jruoho     /* Pad with nulls if necessary */
    550           1.1    jruoho 
    551           1.1    jruoho     while (Count--)
    552           1.1    jruoho     {
    553           1.1    jruoho         *String = 0;
    554           1.1    jruoho         String++;
    555           1.1    jruoho     }
    556           1.1    jruoho 
    557           1.1    jruoho     /* Return original pointer */
    558           1.1    jruoho 
    559           1.1    jruoho     return (DstString);
    560           1.1    jruoho }
    561           1.1    jruoho 
    562           1.1    jruoho 
    563           1.1    jruoho /*******************************************************************************
    564           1.1    jruoho  *
    565       1.1.1.6  christos  * FUNCTION:    strcmp
    566           1.1    jruoho  *
    567           1.1    jruoho  * PARAMETERS:  String1         - First string
    568           1.1    jruoho  *              String2         - Second string
    569           1.1    jruoho  *
    570           1.1    jruoho  * RETURN:      Index where strings mismatched, or 0 if strings matched
    571           1.1    jruoho  *
    572           1.1    jruoho  * DESCRIPTION: Compare two null terminated strings
    573           1.1    jruoho  *
    574           1.1    jruoho  ******************************************************************************/
    575           1.1    jruoho 
    576           1.1    jruoho int
    577       1.1.1.6  christos strcmp (
    578           1.1    jruoho     const char              *String1,
    579           1.1    jruoho     const char              *String2)
    580           1.1    jruoho {
    581           1.1    jruoho 
    582           1.1    jruoho 
    583           1.1    jruoho     for ( ; (*String1 == *String2); String2++)
    584           1.1    jruoho     {
    585           1.1    jruoho         if (!*String1++)
    586           1.1    jruoho         {
    587           1.1    jruoho             return (0);
    588           1.1    jruoho         }
    589           1.1    jruoho     }
    590           1.1    jruoho 
    591           1.1    jruoho     return ((unsigned char) *String1 - (unsigned char) *String2);
    592           1.1    jruoho }
    593           1.1    jruoho 
    594           1.1    jruoho 
    595           1.1    jruoho /*******************************************************************************
    596           1.1    jruoho  *
    597       1.1.1.6  christos  * FUNCTION:    strchr
    598           1.1    jruoho  *
    599           1.1    jruoho  * PARAMETERS:  String          - Search string
    600           1.1    jruoho  *              ch              - character to search for
    601           1.1    jruoho  *
    602           1.1    jruoho  * RETURN:      Ptr to char or NULL if not found
    603           1.1    jruoho  *
    604           1.1    jruoho  * DESCRIPTION: Search a string for a character
    605           1.1    jruoho  *
    606           1.1    jruoho  ******************************************************************************/
    607           1.1    jruoho 
    608           1.1    jruoho char *
    609       1.1.1.6  christos strchr (
    610           1.1    jruoho     const char              *String,
    611           1.1    jruoho     int                     ch)
    612           1.1    jruoho {
    613           1.1    jruoho 
    614           1.1    jruoho 
    615           1.1    jruoho     for ( ; (*String); String++)
    616           1.1    jruoho     {
    617           1.1    jruoho         if ((*String) == (char) ch)
    618           1.1    jruoho         {
    619           1.1    jruoho             return ((char *) String);
    620           1.1    jruoho         }
    621           1.1    jruoho     }
    622           1.1    jruoho 
    623           1.1    jruoho     return (NULL);
    624           1.1    jruoho }
    625       1.1.1.4  christos 
    626           1.1    jruoho 
    627           1.1    jruoho /*******************************************************************************
    628           1.1    jruoho  *
    629       1.1.1.6  christos  * FUNCTION:    strncmp
    630           1.1    jruoho  *
    631           1.1    jruoho  * PARAMETERS:  String1         - First string
    632           1.1    jruoho  *              String2         - Second string
    633           1.1    jruoho  *              Count           - Maximum # of bytes to compare
    634           1.1    jruoho  *
    635           1.1    jruoho  * RETURN:      Index where strings mismatched, or 0 if strings matched
    636           1.1    jruoho  *
    637           1.1    jruoho  * DESCRIPTION: Compare two null terminated strings, with a maximum length
    638           1.1    jruoho  *
    639           1.1    jruoho  ******************************************************************************/
    640           1.1    jruoho 
    641           1.1    jruoho int
    642       1.1.1.6  christos strncmp (
    643           1.1    jruoho     const char              *String1,
    644           1.1    jruoho     const char              *String2,
    645           1.1    jruoho     ACPI_SIZE               Count)
    646           1.1    jruoho {
    647           1.1    jruoho 
    648           1.1    jruoho 
    649           1.1    jruoho     for ( ; Count-- && (*String1 == *String2); String2++)
    650           1.1    jruoho     {
    651           1.1    jruoho         if (!*String1++)
    652           1.1    jruoho         {
    653           1.1    jruoho             return (0);
    654           1.1    jruoho         }
    655           1.1    jruoho     }
    656           1.1    jruoho 
    657           1.1    jruoho     return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *String1 -
    658           1.1    jruoho         (unsigned char) *String2));
    659           1.1    jruoho }
    660           1.1    jruoho 
    661           1.1    jruoho 
    662           1.1    jruoho /*******************************************************************************
    663           1.1    jruoho  *
    664       1.1.1.6  christos  * FUNCTION:    strcat
    665           1.1    jruoho  *
    666           1.1    jruoho  * PARAMETERS:  DstString       - Target of the copy
    667           1.1    jruoho  *              SrcString       - The source string to copy
    668           1.1    jruoho  *
    669           1.1    jruoho  * RETURN:      DstString
    670           1.1    jruoho  *
    671           1.1    jruoho  * DESCRIPTION: Append a null terminated string to a null terminated string
    672           1.1    jruoho  *
    673           1.1    jruoho  ******************************************************************************/
    674           1.1    jruoho 
    675           1.1    jruoho char *
    676       1.1.1.6  christos strcat (
    677           1.1    jruoho     char                    *DstString,
    678           1.1    jruoho     const char              *SrcString)
    679           1.1    jruoho {
    680           1.1    jruoho     char                    *String;
    681           1.1    jruoho 
    682           1.1    jruoho 
    683           1.1    jruoho     /* Find end of the destination string */
    684           1.1    jruoho 
    685           1.1    jruoho     for (String = DstString; *String++; )
    686           1.1    jruoho     { ; }
    687           1.1    jruoho 
    688           1.1    jruoho     /* Concatenate the string */
    689           1.1    jruoho 
    690           1.1    jruoho     for (--String; (*String++ = *SrcString++); )
    691           1.1    jruoho     { ; }
    692           1.1    jruoho 
    693           1.1    jruoho     return (DstString);
    694           1.1    jruoho }
    695           1.1    jruoho 
    696           1.1    jruoho 
    697           1.1    jruoho /*******************************************************************************
    698           1.1    jruoho  *
    699       1.1.1.6  christos  * FUNCTION:    strncat
    700           1.1    jruoho  *
    701           1.1    jruoho  * PARAMETERS:  DstString       - Target of the copy
    702           1.1    jruoho  *              SrcString       - The source string to copy
    703           1.1    jruoho  *              Count           - Maximum # of bytes to copy
    704           1.1    jruoho  *
    705           1.1    jruoho  * RETURN:      DstString
    706           1.1    jruoho  *
    707           1.1    jruoho  * DESCRIPTION: Append a null terminated string to a null terminated string,
    708           1.1    jruoho  *              with a maximum count.
    709           1.1    jruoho  *
    710           1.1    jruoho  ******************************************************************************/
    711           1.1    jruoho 
    712           1.1    jruoho char *
    713       1.1.1.6  christos strncat (
    714           1.1    jruoho     char                    *DstString,
    715           1.1    jruoho     const char              *SrcString,
    716           1.1    jruoho     ACPI_SIZE               Count)
    717           1.1    jruoho {
    718           1.1    jruoho     char                    *String;
    719           1.1    jruoho 
    720           1.1    jruoho 
    721           1.1    jruoho     if (Count)
    722           1.1    jruoho     {
    723           1.1    jruoho         /* Find end of the destination string */
    724           1.1    jruoho 
    725           1.1    jruoho         for (String = DstString; *String++; )
    726           1.1    jruoho         { ; }
    727           1.1    jruoho 
    728           1.1    jruoho         /* Concatenate the string */
    729           1.1    jruoho 
    730           1.1    jruoho         for (--String; (*String++ = *SrcString++) && --Count; )
    731           1.1    jruoho         { ; }
    732           1.1    jruoho 
    733           1.1    jruoho         /* Null terminate if necessary */
    734           1.1    jruoho 
    735           1.1    jruoho         if (!Count)
    736           1.1    jruoho         {
    737           1.1    jruoho             *String = 0;
    738           1.1    jruoho         }
    739           1.1    jruoho     }
    740           1.1    jruoho 
    741           1.1    jruoho     return (DstString);
    742           1.1    jruoho }
    743           1.1    jruoho 
    744           1.1    jruoho 
    745           1.1    jruoho /*******************************************************************************
    746           1.1    jruoho  *
    747       1.1.1.6  christos  * FUNCTION:    strstr
    748           1.1    jruoho  *
    749           1.1    jruoho  * PARAMETERS:  String1         - Target string
    750           1.1    jruoho  *              String2         - Substring to search for
    751           1.1    jruoho  *
    752           1.1    jruoho  * RETURN:      Where substring match starts, Null if no match found
    753           1.1    jruoho  *
    754           1.1    jruoho  * DESCRIPTION: Checks if String2 occurs in String1. This is not really a
    755           1.1    jruoho  *              full implementation of strstr, only sufficient for command
    756           1.1    jruoho  *              matching
    757           1.1    jruoho  *
    758           1.1    jruoho  ******************************************************************************/
    759           1.1    jruoho 
    760           1.1    jruoho char *
    761       1.1.1.6  christos strstr (
    762           1.1    jruoho     char                    *String1,
    763           1.1    jruoho     char                    *String2)
    764           1.1    jruoho {
    765       1.1.1.9  christos     ACPI_SIZE               Length;
    766           1.1    jruoho 
    767           1.1    jruoho 
    768       1.1.1.6  christos     Length = strlen (String2);
    769       1.1.1.5  christos     if (!Length)
    770           1.1    jruoho     {
    771       1.1.1.5  christos         return (String1);
    772           1.1    jruoho     }
    773           1.1    jruoho 
    774       1.1.1.6  christos     while (strlen (String1) >= Length)
    775           1.1    jruoho     {
    776       1.1.1.6  christos         if (memcmp (String1, String2, Length) == 0)
    777           1.1    jruoho         {
    778       1.1.1.5  christos             return (String1);
    779           1.1    jruoho         }
    780       1.1.1.5  christos         String1++;
    781           1.1    jruoho     }
    782           1.1    jruoho 
    783       1.1.1.5  christos     return (NULL);
    784           1.1    jruoho }
    785           1.1    jruoho 
    786           1.1    jruoho 
    787           1.1    jruoho /*******************************************************************************
    788           1.1    jruoho  *
    789       1.1.1.6  christos  * FUNCTION:    strtoul
    790           1.1    jruoho  *
    791           1.1    jruoho  * PARAMETERS:  String          - Null terminated string
    792      1.1.1.11  christos  *              Terminator      - Where a pointer to the terminating byte is
    793           1.1    jruoho  *                                returned
    794           1.1    jruoho  *              Base            - Radix of the string
    795           1.1    jruoho  *
    796           1.1    jruoho  * RETURN:      Converted value
    797           1.1    jruoho  *
    798           1.1    jruoho  * DESCRIPTION: Convert a string into a 32-bit unsigned value.
    799       1.1.1.6  christos  *              Note: use strtoul64 for 64-bit integers.
    800           1.1    jruoho  *
    801           1.1    jruoho  ******************************************************************************/
    802           1.1    jruoho 
    803           1.1    jruoho UINT32
    804       1.1.1.6  christos strtoul (
    805           1.1    jruoho     const char              *String,
    806           1.1    jruoho     char                    **Terminator,
    807           1.1    jruoho     UINT32                  Base)
    808           1.1    jruoho {
    809           1.1    jruoho     UINT32                  converted = 0;
    810           1.1    jruoho     UINT32                  index;
    811           1.1    jruoho     UINT32                  sign;
    812           1.1    jruoho     const char              *StringStart;
    813           1.1    jruoho     UINT32                  ReturnValue = 0;
    814           1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    815           1.1    jruoho 
    816           1.1    jruoho 
    817           1.1    jruoho     /*
    818           1.1    jruoho      * Save the value of the pointer to the buffer's first
    819           1.1    jruoho      * character, save the current errno value, and then
    820           1.1    jruoho      * skip over any white space in the buffer:
    821           1.1    jruoho      */
    822           1.1    jruoho     StringStart = String;
    823       1.1.1.6  christos     while (isspace (*String) || *String == '\t')
    824           1.1    jruoho     {
    825           1.1    jruoho         ++String;
    826           1.1    jruoho     }
    827           1.1    jruoho 
    828           1.1    jruoho     /*
    829           1.1    jruoho      * The buffer may contain an optional plus or minus sign.
    830           1.1    jruoho      * If it does, then skip over it but remember what is was:
    831           1.1    jruoho      */
    832           1.1    jruoho     if (*String == '-')
    833           1.1    jruoho     {
    834       1.1.1.6  christos         sign = ACPI_SIGN_NEGATIVE;
    835           1.1    jruoho         ++String;
    836           1.1    jruoho     }
    837           1.1    jruoho     else if (*String == '+')
    838           1.1    jruoho     {
    839           1.1    jruoho         ++String;
    840       1.1.1.6  christos         sign = ACPI_SIGN_POSITIVE;
    841           1.1    jruoho     }
    842           1.1    jruoho     else
    843           1.1    jruoho     {
    844       1.1.1.6  christos         sign = ACPI_SIGN_POSITIVE;
    845           1.1    jruoho     }
    846           1.1    jruoho 
    847           1.1    jruoho     /*
    848           1.1    jruoho      * If the input parameter Base is zero, then we need to
    849           1.1    jruoho      * determine if it is octal, decimal, or hexadecimal:
    850           1.1    jruoho      */
    851           1.1    jruoho     if (Base == 0)
    852           1.1    jruoho     {
    853           1.1    jruoho         if (*String == '0')
    854           1.1    jruoho         {
    855       1.1.1.6  christos             if (tolower (*(++String)) == 'x')
    856           1.1    jruoho             {
    857           1.1    jruoho                 Base = 16;
    858           1.1    jruoho                 ++String;
    859           1.1    jruoho             }
    860           1.1    jruoho             else
    861           1.1    jruoho             {
    862           1.1    jruoho                 Base = 8;
    863           1.1    jruoho             }
    864           1.1    jruoho         }
    865           1.1    jruoho         else
    866           1.1    jruoho         {
    867           1.1    jruoho             Base = 10;
    868           1.1    jruoho         }
    869           1.1    jruoho     }
    870           1.1    jruoho     else if (Base < 2 || Base > 36)
    871           1.1    jruoho     {
    872           1.1    jruoho         /*
    873           1.1    jruoho          * The specified Base parameter is not in the domain of
    874           1.1    jruoho          * this function:
    875           1.1    jruoho          */
    876           1.1    jruoho         goto done;
    877           1.1    jruoho     }
    878           1.1    jruoho 
    879           1.1    jruoho     /*
    880           1.1    jruoho      * For octal and hexadecimal bases, skip over the leading
    881           1.1    jruoho      * 0 or 0x, if they are present.
    882           1.1    jruoho      */
    883           1.1    jruoho     if (Base == 8 && *String == '0')
    884           1.1    jruoho     {
    885           1.1    jruoho         String++;
    886           1.1    jruoho     }
    887           1.1    jruoho 
    888           1.1    jruoho     if (Base == 16 &&
    889           1.1    jruoho         *String == '0' &&
    890       1.1.1.6  christos         tolower (*(++String)) == 'x')
    891           1.1    jruoho     {
    892           1.1    jruoho         String++;
    893           1.1    jruoho     }
    894           1.1    jruoho 
    895           1.1    jruoho     /*
    896           1.1    jruoho      * Main loop: convert the string to an unsigned long:
    897           1.1    jruoho      */
    898           1.1    jruoho     while (*String)
    899           1.1    jruoho     {
    900       1.1.1.6  christos         if (isdigit (*String))
    901           1.1    jruoho         {
    902           1.1    jruoho             index = (UINT32) ((UINT8) *String - '0');
    903           1.1    jruoho         }
    904           1.1    jruoho         else
    905           1.1    jruoho         {
    906       1.1.1.6  christos             index = (UINT32) toupper (*String);
    907       1.1.1.6  christos             if (isupper (index))
    908           1.1    jruoho             {
    909           1.1    jruoho                 index = index - 'A' + 10;
    910           1.1    jruoho             }
    911           1.1    jruoho             else
    912           1.1    jruoho             {
    913           1.1    jruoho                 goto done;
    914           1.1    jruoho             }
    915           1.1    jruoho         }
    916           1.1    jruoho 
    917           1.1    jruoho         if (index >= Base)
    918           1.1    jruoho         {
    919           1.1    jruoho             goto done;
    920           1.1    jruoho         }
    921           1.1    jruoho 
    922           1.1    jruoho         /*
    923           1.1    jruoho          * Check to see if value is out of range:
    924           1.1    jruoho          */
    925           1.1    jruoho 
    926           1.1    jruoho         if (ReturnValue > ((ACPI_UINT32_MAX - (UINT32) index) /
    927           1.1    jruoho                             (UINT32) Base))
    928           1.1    jruoho         {
    929           1.1    jruoho             Status = AE_ERROR;
    930           1.1    jruoho             ReturnValue = 0;           /* reset */
    931           1.1    jruoho         }
    932           1.1    jruoho         else
    933           1.1    jruoho         {
    934           1.1    jruoho             ReturnValue *= Base;
    935           1.1    jruoho             ReturnValue += index;
    936           1.1    jruoho             converted = 1;
    937           1.1    jruoho         }
    938           1.1    jruoho 
    939           1.1    jruoho         ++String;
    940           1.1    jruoho     }
    941           1.1    jruoho 
    942           1.1    jruoho done:
    943           1.1    jruoho     /*
    944           1.1    jruoho      * If appropriate, update the caller's pointer to the next
    945           1.1    jruoho      * unconverted character in the buffer.
    946           1.1    jruoho      */
    947           1.1    jruoho     if (Terminator)
    948           1.1    jruoho     {
    949           1.1    jruoho         if (converted == 0 && ReturnValue == 0 && String != NULL)
    950           1.1    jruoho         {
    951           1.1    jruoho             *Terminator = (char *) StringStart;
    952           1.1    jruoho         }
    953           1.1    jruoho         else
    954           1.1    jruoho         {
    955           1.1    jruoho             *Terminator = (char *) String;
    956           1.1    jruoho         }
    957           1.1    jruoho     }
    958           1.1    jruoho 
    959           1.1    jruoho     if (Status == AE_ERROR)
    960           1.1    jruoho     {
    961           1.1    jruoho         ReturnValue = ACPI_UINT32_MAX;
    962           1.1    jruoho     }
    963           1.1    jruoho 
    964           1.1    jruoho     /*
    965           1.1    jruoho      * If a minus sign was present, then "the conversion is negated":
    966           1.1    jruoho      */
    967       1.1.1.6  christos     if (sign == ACPI_SIGN_NEGATIVE)
    968           1.1    jruoho     {
    969           1.1    jruoho         ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1;
    970           1.1    jruoho     }
    971           1.1    jruoho 
    972           1.1    jruoho     return (ReturnValue);
    973           1.1    jruoho }
    974           1.1    jruoho 
    975           1.1    jruoho 
    976           1.1    jruoho /*******************************************************************************
    977           1.1    jruoho  *
    978       1.1.1.6  christos  * FUNCTION:    toupper
    979           1.1    jruoho  *
    980           1.1    jruoho  * PARAMETERS:  c           - Character to convert
    981           1.1    jruoho  *
    982           1.1    jruoho  * RETURN:      Converted character as an int
    983           1.1    jruoho  *
    984           1.1    jruoho  * DESCRIPTION: Convert character to uppercase
    985           1.1    jruoho  *
    986           1.1    jruoho  ******************************************************************************/
    987           1.1    jruoho 
    988           1.1    jruoho int
    989       1.1.1.6  christos toupper (
    990           1.1    jruoho     int                     c)
    991           1.1    jruoho {
    992           1.1    jruoho 
    993       1.1.1.6  christos     return (islower(c) ? ((c)-0x20) : (c));
    994           1.1    jruoho }
    995           1.1    jruoho 
    996           1.1    jruoho 
    997           1.1    jruoho /*******************************************************************************
    998           1.1    jruoho  *
    999       1.1.1.6  christos  * FUNCTION:    tolower
   1000           1.1    jruoho  *
   1001           1.1    jruoho  * PARAMETERS:  c           - Character to convert
   1002           1.1    jruoho  *
   1003           1.1    jruoho  * RETURN:      Converted character as an int
   1004           1.1    jruoho  *
   1005           1.1    jruoho  * DESCRIPTION: Convert character to lowercase
   1006           1.1    jruoho  *
   1007           1.1    jruoho  ******************************************************************************/
   1008           1.1    jruoho 
   1009           1.1    jruoho int
   1010       1.1.1.6  christos tolower (
   1011           1.1    jruoho     int                     c)
   1012           1.1    jruoho {
   1013           1.1    jruoho 
   1014       1.1.1.6  christos     return (isupper(c) ? ((c)+0x20) : (c));
   1015           1.1    jruoho }
   1016           1.1    jruoho 
   1017           1.1    jruoho 
   1018           1.1    jruoho /*******************************************************************************
   1019           1.1    jruoho  *
   1020       1.1.1.6  christos  * FUNCTION:    is* function array
   1021           1.1    jruoho  *
   1022           1.1    jruoho  * DESCRIPTION: is* functions use the ctype table below
   1023           1.1    jruoho  *
   1024           1.1    jruoho  ******************************************************************************/
   1025           1.1    jruoho 
   1026       1.1.1.6  christos const UINT8 AcpiGbl_Ctypes[257] = {
   1027       1.1.1.3  christos     _ACPI_CN,            /* 0x00     0 NUL */
   1028       1.1.1.3  christos     _ACPI_CN,            /* 0x01     1 SOH */
   1029       1.1.1.3  christos     _ACPI_CN,            /* 0x02     2 STX */
   1030       1.1.1.3  christos     _ACPI_CN,            /* 0x03     3 ETX */
   1031       1.1.1.3  christos     _ACPI_CN,            /* 0x04     4 EOT */
   1032       1.1.1.3  christos     _ACPI_CN,            /* 0x05     5 ENQ */
   1033       1.1.1.3  christos     _ACPI_CN,            /* 0x06     6 ACK */
   1034       1.1.1.3  christos     _ACPI_CN,            /* 0x07     7 BEL */
   1035       1.1.1.3  christos     _ACPI_CN,            /* 0x08     8 BS  */
   1036       1.1.1.3  christos     _ACPI_CN|_ACPI_SP,   /* 0x09     9 TAB */
   1037       1.1.1.3  christos     _ACPI_CN|_ACPI_SP,   /* 0x0A    10 LF  */
   1038       1.1.1.3  christos     _ACPI_CN|_ACPI_SP,   /* 0x0B    11 VT  */
   1039       1.1.1.3  christos     _ACPI_CN|_ACPI_SP,   /* 0x0C    12 FF  */
   1040       1.1.1.3  christos     _ACPI_CN|_ACPI_SP,   /* 0x0D    13 CR  */
   1041       1.1.1.3  christos     _ACPI_CN,            /* 0x0E    14 SO  */
   1042       1.1.1.3  christos     _ACPI_CN,            /* 0x0F    15 SI  */
   1043       1.1.1.3  christos     _ACPI_CN,            /* 0x10    16 DLE */
   1044       1.1.1.3  christos     _ACPI_CN,            /* 0x11    17 DC1 */
   1045       1.1.1.3  christos     _ACPI_CN,            /* 0x12    18 DC2 */
   1046       1.1.1.3  christos     _ACPI_CN,            /* 0x13    19 DC3 */
   1047       1.1.1.3  christos     _ACPI_CN,            /* 0x14    20 DC4 */
   1048       1.1.1.3  christos     _ACPI_CN,            /* 0x15    21 NAK */
   1049       1.1.1.3  christos     _ACPI_CN,            /* 0x16    22 SYN */
   1050       1.1.1.3  christos     _ACPI_CN,            /* 0x17    23 ETB */
   1051       1.1.1.3  christos     _ACPI_CN,            /* 0x18    24 CAN */
   1052       1.1.1.3  christos     _ACPI_CN,            /* 0x19    25 EM  */
   1053       1.1.1.3  christos     _ACPI_CN,            /* 0x1A    26 SUB */
   1054       1.1.1.3  christos     _ACPI_CN,            /* 0x1B    27 ESC */
   1055       1.1.1.3  christos     _ACPI_CN,            /* 0x1C    28 FS  */
   1056       1.1.1.3  christos     _ACPI_CN,            /* 0x1D    29 GS  */
   1057       1.1.1.3  christos     _ACPI_CN,            /* 0x1E    30 RS  */
   1058       1.1.1.3  christos     _ACPI_CN,            /* 0x1F    31 US  */
   1059       1.1.1.3  christos     _ACPI_XS|_ACPI_SP,   /* 0x20    32 ' ' */
   1060       1.1.1.3  christos     _ACPI_PU,            /* 0x21    33 '!' */
   1061       1.1.1.3  christos     _ACPI_PU,            /* 0x22    34 '"' */
   1062       1.1.1.3  christos     _ACPI_PU,            /* 0x23    35 '#' */
   1063       1.1.1.3  christos     _ACPI_PU,            /* 0x24    36 '$' */
   1064       1.1.1.3  christos     _ACPI_PU,            /* 0x25    37 '%' */
   1065       1.1.1.3  christos     _ACPI_PU,            /* 0x26    38 '&' */
   1066       1.1.1.3  christos     _ACPI_PU,            /* 0x27    39 ''' */
   1067       1.1.1.3  christos     _ACPI_PU,            /* 0x28    40 '(' */
   1068       1.1.1.3  christos     _ACPI_PU,            /* 0x29    41 ')' */
   1069       1.1.1.3  christos     _ACPI_PU,            /* 0x2A    42 '*' */
   1070       1.1.1.3  christos     _ACPI_PU,            /* 0x2B    43 '+' */
   1071       1.1.1.3  christos     _ACPI_PU,            /* 0x2C    44 ',' */
   1072       1.1.1.3  christos     _ACPI_PU,            /* 0x2D    45 '-' */
   1073       1.1.1.3  christos     _ACPI_PU,            /* 0x2E    46 '.' */
   1074       1.1.1.3  christos     _ACPI_PU,            /* 0x2F    47 '/' */
   1075       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x30    48 '0' */
   1076       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x31    49 '1' */
   1077       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x32    50 '2' */
   1078       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x33    51 '3' */
   1079       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x34    52 '4' */
   1080       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x35    53 '5' */
   1081       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x36    54 '6' */
   1082       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x37    55 '7' */
   1083       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x38    56 '8' */
   1084       1.1.1.3  christos     _ACPI_XD|_ACPI_DI,   /* 0x39    57 '9' */
   1085       1.1.1.3  christos     _ACPI_PU,            /* 0x3A    58 ':' */
   1086       1.1.1.3  christos     _ACPI_PU,            /* 0x3B    59 ';' */
   1087       1.1.1.3  christos     _ACPI_PU,            /* 0x3C    60 '<' */
   1088       1.1.1.3  christos     _ACPI_PU,            /* 0x3D    61 '=' */
   1089       1.1.1.3  christos     _ACPI_PU,            /* 0x3E    62 '>' */
   1090       1.1.1.3  christos     _ACPI_PU,            /* 0x3F    63 '?' */
   1091       1.1.1.3  christos     _ACPI_PU,            /* 0x40    64 '@' */
   1092       1.1.1.3  christos     _ACPI_XD|_ACPI_UP,   /* 0x41    65 'A' */
   1093       1.1.1.3  christos     _ACPI_XD|_ACPI_UP,   /* 0x42    66 'B' */
   1094       1.1.1.3  christos     _ACPI_XD|_ACPI_UP,   /* 0x43    67 'C' */
   1095       1.1.1.3  christos     _ACPI_XD|_ACPI_UP,   /* 0x44    68 'D' */
   1096       1.1.1.3  christos     _ACPI_XD|_ACPI_UP,   /* 0x45    69 'E' */
   1097       1.1.1.3  christos     _ACPI_XD|_ACPI_UP,   /* 0x46    70 'F' */
   1098       1.1.1.3  christos     _ACPI_UP,            /* 0x47    71 'G' */
   1099       1.1.1.3  christos     _ACPI_UP,            /* 0x48    72 'H' */
   1100       1.1.1.3  christos     _ACPI_UP,            /* 0x49    73 'I' */
   1101       1.1.1.3  christos     _ACPI_UP,            /* 0x4A    74 'J' */
   1102       1.1.1.3  christos     _ACPI_UP,            /* 0x4B    75 'K' */
   1103       1.1.1.3  christos     _ACPI_UP,            /* 0x4C    76 'L' */
   1104       1.1.1.3  christos     _ACPI_UP,            /* 0x4D    77 'M' */
   1105       1.1.1.3  christos     _ACPI_UP,            /* 0x4E    78 'N' */
   1106       1.1.1.3  christos     _ACPI_UP,            /* 0x4F    79 'O' */
   1107       1.1.1.3  christos     _ACPI_UP,            /* 0x50    80 'P' */
   1108       1.1.1.3  christos     _ACPI_UP,            /* 0x51    81 'Q' */
   1109       1.1.1.3  christos     _ACPI_UP,            /* 0x52    82 'R' */
   1110       1.1.1.3  christos     _ACPI_UP,            /* 0x53    83 'S' */
   1111       1.1.1.3  christos     _ACPI_UP,            /* 0x54    84 'T' */
   1112       1.1.1.3  christos     _ACPI_UP,            /* 0x55    85 'U' */
   1113       1.1.1.3  christos     _ACPI_UP,            /* 0x56    86 'V' */
   1114       1.1.1.3  christos     _ACPI_UP,            /* 0x57    87 'W' */
   1115       1.1.1.3  christos     _ACPI_UP,            /* 0x58    88 'X' */
   1116       1.1.1.3  christos     _ACPI_UP,            /* 0x59    89 'Y' */
   1117       1.1.1.3  christos     _ACPI_UP,            /* 0x5A    90 'Z' */
   1118       1.1.1.3  christos     _ACPI_PU,            /* 0x5B    91 '[' */
   1119       1.1.1.3  christos     _ACPI_PU,            /* 0x5C    92 '\' */
   1120       1.1.1.3  christos     _ACPI_PU,            /* 0x5D    93 ']' */
   1121       1.1.1.3  christos     _ACPI_PU,            /* 0x5E    94 '^' */
   1122       1.1.1.3  christos     _ACPI_PU,            /* 0x5F    95 '_' */
   1123       1.1.1.3  christos     _ACPI_PU,            /* 0x60    96 '`' */
   1124       1.1.1.3  christos     _ACPI_XD|_ACPI_LO,   /* 0x61    97 'a' */
   1125       1.1.1.3  christos     _ACPI_XD|_ACPI_LO,   /* 0x62    98 'b' */
   1126       1.1.1.3  christos     _ACPI_XD|_ACPI_LO,   /* 0x63    99 'c' */
   1127       1.1.1.3  christos     _ACPI_XD|_ACPI_LO,   /* 0x64   100 'd' */
   1128       1.1.1.3  christos     _ACPI_XD|_ACPI_LO,   /* 0x65   101 'e' */
   1129       1.1.1.3  christos     _ACPI_XD|_ACPI_LO,   /* 0x66   102 'f' */
   1130       1.1.1.3  christos     _ACPI_LO,            /* 0x67   103 'g' */
   1131       1.1.1.3  christos     _ACPI_LO,            /* 0x68   104 'h' */
   1132       1.1.1.3  christos     _ACPI_LO,            /* 0x69   105 'i' */
   1133       1.1.1.3  christos     _ACPI_LO,            /* 0x6A   106 'j' */
   1134       1.1.1.3  christos     _ACPI_LO,            /* 0x6B   107 'k' */
   1135       1.1.1.3  christos     _ACPI_LO,            /* 0x6C   108 'l' */
   1136       1.1.1.3  christos     _ACPI_LO,            /* 0x6D   109 'm' */
   1137       1.1.1.3  christos     _ACPI_LO,            /* 0x6E   110 'n' */
   1138       1.1.1.3  christos     _ACPI_LO,            /* 0x6F   111 'o' */
   1139       1.1.1.3  christos     _ACPI_LO,            /* 0x70   112 'p' */
   1140       1.1.1.3  christos     _ACPI_LO,            /* 0x71   113 'q' */
   1141       1.1.1.3  christos     _ACPI_LO,            /* 0x72   114 'r' */
   1142       1.1.1.3  christos     _ACPI_LO,            /* 0x73   115 's' */
   1143       1.1.1.3  christos     _ACPI_LO,            /* 0x74   116 't' */
   1144       1.1.1.3  christos     _ACPI_LO,            /* 0x75   117 'u' */
   1145       1.1.1.3  christos     _ACPI_LO,            /* 0x76   118 'v' */
   1146       1.1.1.3  christos     _ACPI_LO,            /* 0x77   119 'w' */
   1147       1.1.1.3  christos     _ACPI_LO,            /* 0x78   120 'x' */
   1148       1.1.1.3  christos     _ACPI_LO,            /* 0x79   121 'y' */
   1149       1.1.1.3  christos     _ACPI_LO,            /* 0x7A   122 'z' */
   1150       1.1.1.3  christos     _ACPI_PU,            /* 0x7B   123 '{' */
   1151       1.1.1.3  christos     _ACPI_PU,            /* 0x7C   124 '|' */
   1152       1.1.1.3  christos     _ACPI_PU,            /* 0x7D   125 '}' */
   1153       1.1.1.3  christos     _ACPI_PU,            /* 0x7E   126 '~' */
   1154       1.1.1.3  christos     _ACPI_CN,            /* 0x7F   127 DEL */
   1155           1.1    jruoho 
   1156           1.1    jruoho     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0x80 to 0x8F    */
   1157           1.1    jruoho     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0x90 to 0x9F    */
   1158           1.1    jruoho     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xA0 to 0xAF    */
   1159           1.1    jruoho     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xB0 to 0xBF    */
   1160           1.1    jruoho     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xC0 to 0xCF    */
   1161           1.1    jruoho     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xD0 to 0xDF    */
   1162           1.1    jruoho     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xE0 to 0xEF    */
   1163       1.1.1.3  christos     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xF0 to 0xFF    */
   1164       1.1.1.3  christos     0                                 /* 0x100 */
   1165           1.1    jruoho };
   1166           1.1    jruoho 
   1167           1.1    jruoho 
   1168           1.1    jruoho #endif /* ACPI_USE_SYSTEM_CLIBRARY */
   1169