Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:03

0001 /******************************************************************************
0002  *
0003  * Module Name: utclib - ACPICA implementations of C library functions
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #define ACPI_CLIBRARY
0153 #include "acpi.h"
0154 #include "accommon.h"
0155 
0156 /*
0157  * This module contains implementations of the standard C library functions
0158  * that are required by the ACPICA code at both application level and kernel
0159  * level.
0160  *
0161  * The module is an optional feature that can be used if a local/system
0162  * C library is not available. Some operating system kernels may not have
0163  * an internal C library.
0164  *
0165  * In general, these functions are less efficient than an inline or assembly
0166  * code implementation.
0167  *
0168  * These C functions and the associated prototypes are enabled by default
0169  * unless the ACPI_USE_SYSTEM_CLIBRARY symbol is defined. This is usually
0170  * automatically defined for the ACPICA applications such as iASL and
0171  * AcpiExec, so that these user-level applications use the local C library
0172  * instead of the functions in this module.
0173  */
0174 
0175 /*******************************************************************************
0176  *
0177  * Functions implemented in this module:
0178  *
0179  * FUNCTION:    memcmp
0180  * FUNCTION:    memcpy
0181  * FUNCTION:    memset
0182  * FUNCTION:    strlen
0183  * FUNCTION:    strcpy
0184  * FUNCTION:    strncpy
0185  * FUNCTION:    strcmp
0186  * FUNCTION:    strchr
0187  * FUNCTION:    strncmp
0188  * FUNCTION:    strcat
0189  * FUNCTION:    strncat
0190  * FUNCTION:    strstr
0191  * FUNCTION:    strtoul
0192  * FUNCTION:    toupper
0193  * FUNCTION:    tolower
0194  * FUNCTION:    is* functions
0195  *
0196  ******************************************************************************/
0197 
0198 #define _COMPONENT          ACPI_UTILITIES
0199         ACPI_MODULE_NAME    ("utclib")
0200 
0201 
0202 #ifndef ACPI_USE_SYSTEM_CLIBRARY    /* Entire module */
0203 
0204 
0205 /*******************************************************************************
0206  *
0207  * FUNCTION:    memcmp
0208  *
0209  * PARAMETERS:  Buffer1         - First Buffer
0210  *              Buffer2         - Second Buffer
0211  *              Count           - Maximum # of bytes to compare
0212  *
0213  * RETURN:      Index where Buffers mismatched, or 0 if Buffers matched
0214  *
0215  * DESCRIPTION: Compare two Buffers, with a maximum length
0216  *
0217  ******************************************************************************/
0218 
0219 int
0220 memcmp (
0221     void                    *VBuffer1,
0222     void                    *VBuffer2,
0223     ACPI_SIZE               Count)
0224 {
0225     char                    *Buffer1 = (char *) VBuffer1;
0226     char                    *Buffer2 = (char *) VBuffer2;
0227 
0228 
0229     for ( ; Count-- && (*Buffer1 == *Buffer2); Buffer1++, Buffer2++)
0230     {
0231     }
0232 
0233     return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *Buffer1 -
0234         (unsigned char) *Buffer2));
0235 }
0236 
0237 
0238 /*******************************************************************************
0239  *
0240  * FUNCTION:    memmove
0241  *
0242  * PARAMETERS:  Dest        - Target of the copy
0243  *              Src         - Source buffer to copy
0244  *              Count       - Number of bytes to copy
0245  *
0246  * RETURN:      Dest
0247  *
0248  * DESCRIPTION: Copy arbitrary bytes of memory with respect to the overlapping
0249  *
0250  ******************************************************************************/
0251 
0252 void *
0253 memmove (
0254     void                    *Dest,
0255     const void              *Src,
0256     ACPI_SIZE               Count)
0257 {
0258     char                    *New = (char *) Dest;
0259     char                    *Old = (char *) Src;
0260 
0261 
0262     if (Old > New)
0263     {
0264         /* Copy from the beginning */
0265 
0266         while (Count)
0267         {
0268             *New = *Old;
0269             New++;
0270             Old++;
0271             Count--;
0272         }
0273     }
0274     else if (Old < New)
0275     {
0276         /* Copy from the end */
0277 
0278         New = New + Count - 1;
0279         Old = Old + Count - 1;
0280         while (Count)
0281         {
0282             *New = *Old;
0283             New--;
0284             Old--;
0285             Count--;
0286         }
0287     }
0288 
0289     return (Dest);
0290 }
0291 
0292 
0293 /*******************************************************************************
0294  *
0295  * FUNCTION:    memcpy
0296  *
0297  * PARAMETERS:  Dest        - Target of the copy
0298  *              Src         - Source buffer to copy
0299  *              Count       - Number of bytes to copy
0300  *
0301  * RETURN:      Dest
0302  *
0303  * DESCRIPTION: Copy arbitrary bytes of memory
0304  *
0305  ******************************************************************************/
0306 
0307 void *
0308 memcpy (
0309     void                    *Dest,
0310     const void              *Src,
0311     ACPI_SIZE               Count)
0312 {
0313     char                    *New = (char *) Dest;
0314     char                    *Old = (char *) Src;
0315 
0316 
0317     while (Count)
0318     {
0319         *New = *Old;
0320         New++;
0321         Old++;
0322         Count--;
0323     }
0324 
0325     return (Dest);
0326 }
0327 
0328 
0329 /*******************************************************************************
0330  *
0331  * FUNCTION:    memset
0332  *
0333  * PARAMETERS:  Dest        - Buffer to set
0334  *              Value       - Value to set each byte of memory
0335  *              Count       - Number of bytes to set
0336  *
0337  * RETURN:      Dest
0338  *
0339  * DESCRIPTION: Initialize a buffer to a known value.
0340  *
0341  ******************************************************************************/
0342 
0343 void *
0344 memset (
0345     void                    *Dest,
0346     int                     Value,
0347     ACPI_SIZE               Count)
0348 {
0349     char                    *New = (char *) Dest;
0350 
0351 
0352     while (Count)
0353     {
0354         *New = (char) Value;
0355         New++;
0356         Count--;
0357     }
0358 
0359     return (Dest);
0360 }
0361 
0362 
0363 /*******************************************************************************
0364  *
0365  * FUNCTION:    strlen
0366  *
0367  * PARAMETERS:  String              - Null terminated string
0368  *
0369  * RETURN:      Length
0370  *
0371  * DESCRIPTION: Returns the length of the input string
0372  *
0373  ******************************************************************************/
0374 
0375 
0376 ACPI_SIZE
0377 strlen (
0378     const char              *String)
0379 {
0380     UINT32                  Length = 0;
0381 
0382 
0383     /* Count the string until a null is encountered */
0384 
0385     while (*String)
0386     {
0387         Length++;
0388         String++;
0389     }
0390 
0391     return (Length);
0392 }
0393 
0394 
0395 /*******************************************************************************
0396  *
0397  * FUNCTION:    strpbrk
0398  *
0399  * PARAMETERS:  String              - Null terminated string
0400  *              Delimiters          - Delimiters to match
0401  *
0402  * RETURN:      The first occurrence in the string of any of the bytes in the
0403  *              delimiters
0404  *
0405  * DESCRIPTION: Search a string for any of a set of the delimiters
0406  *
0407  ******************************************************************************/
0408 
0409 char *
0410 strpbrk (
0411     const char              *String,
0412     const char              *Delimiters)
0413 {
0414     const char              *Delimiter;
0415 
0416 
0417     for ( ; *String != '\0'; ++String)
0418     {
0419         for (Delimiter = Delimiters; *Delimiter != '\0'; Delimiter++)
0420         {
0421             if (*String == *Delimiter)
0422             {
0423                 return (ACPI_CAST_PTR (char, String));
0424             }
0425         }
0426     }
0427 
0428     return (NULL);
0429 }
0430 
0431 
0432 /*******************************************************************************
0433  *
0434  * FUNCTION:    strtok
0435  *
0436  * PARAMETERS:  String              - Null terminated string
0437  *              Delimiters          - Delimiters to match
0438  *
0439  * RETURN:      Pointer to the next token
0440  *
0441  * DESCRIPTION: Split string into tokens
0442  *
0443  ******************************************************************************/
0444 
0445 char*
0446 strtok (
0447     char                    *String,
0448     const char              *Delimiters)
0449 {
0450     char                    *Begin = String;
0451     static char             *SavedPtr;
0452 
0453 
0454     if (Begin == NULL)
0455     {
0456         if (SavedPtr == NULL)
0457         {
0458             return (NULL);
0459         }
0460         Begin = SavedPtr;
0461     }
0462 
0463     SavedPtr = strpbrk (Begin, Delimiters);
0464     while (SavedPtr == Begin)
0465     {
0466         *Begin++ = '\0';
0467         SavedPtr = strpbrk (Begin, Delimiters);
0468     }
0469 
0470     if (SavedPtr)
0471     {
0472         *SavedPtr++ = '\0';
0473         return (Begin);
0474     }
0475     else
0476     {
0477         return (NULL);
0478     }
0479 }
0480 
0481 
0482 /*******************************************************************************
0483  *
0484  * FUNCTION:    strcpy
0485  *
0486  * PARAMETERS:  DstString       - Target of the copy
0487  *              SrcString       - The source string to copy
0488  *
0489  * RETURN:      DstString
0490  *
0491  * DESCRIPTION: Copy a null terminated string
0492  *
0493  ******************************************************************************/
0494 
0495 char *
0496 strcpy (
0497     char                    *DstString,
0498     const char              *SrcString)
0499 {
0500     char                    *String = DstString;
0501 
0502 
0503     /* Move bytes brute force */
0504 
0505     while (*SrcString)
0506     {
0507         *String = *SrcString;
0508 
0509         String++;
0510         SrcString++;
0511     }
0512 
0513     /* Null terminate */
0514 
0515     *String = 0;
0516     return (DstString);
0517 }
0518 
0519 
0520 /*******************************************************************************
0521  *
0522  * FUNCTION:    strncpy
0523  *
0524  * PARAMETERS:  DstString       - Target of the copy
0525  *              SrcString       - The source string to copy
0526  *              Count           - Maximum # of bytes to copy
0527  *
0528  * RETURN:      DstString
0529  *
0530  * DESCRIPTION: Copy a null terminated string, with a maximum length
0531  *
0532  ******************************************************************************/
0533 
0534 char *
0535 strncpy (
0536     char                    *DstString,
0537     const char              *SrcString,
0538     ACPI_SIZE               Count)
0539 {
0540     char                    *String = DstString;
0541 
0542 
0543     /* Copy the string */
0544 
0545     for (String = DstString;
0546         Count && (Count--, (*String++ = *SrcString++)); )
0547     {;}
0548 
0549     /* Pad with nulls if necessary */
0550 
0551     while (Count--)
0552     {
0553         *String = 0;
0554         String++;
0555     }
0556 
0557     /* Return original pointer */
0558 
0559     return (DstString);
0560 }
0561 
0562 
0563 /*******************************************************************************
0564  *
0565  * FUNCTION:    strcmp
0566  *
0567  * PARAMETERS:  String1         - First string
0568  *              String2         - Second string
0569  *
0570  * RETURN:      Index where strings mismatched, or 0 if strings matched
0571  *
0572  * DESCRIPTION: Compare two null terminated strings
0573  *
0574  ******************************************************************************/
0575 
0576 int
0577 strcmp (
0578     const char              *String1,
0579     const char              *String2)
0580 {
0581 
0582 
0583     for ( ; (*String1 == *String2); String2++)
0584     {
0585         if (!*String1++)
0586         {
0587             return (0);
0588         }
0589     }
0590 
0591     return ((unsigned char) *String1 - (unsigned char) *String2);
0592 }
0593 
0594 
0595 /*******************************************************************************
0596  *
0597  * FUNCTION:    strchr
0598  *
0599  * PARAMETERS:  String          - Search string
0600  *              ch              - character to search for
0601  *
0602  * RETURN:      Ptr to char or NULL if not found
0603  *
0604  * DESCRIPTION: Search a string for a character
0605  *
0606  ******************************************************************************/
0607 
0608 char *
0609 strchr (
0610     const char              *String,
0611     int                     ch)
0612 {
0613 
0614 
0615     for ( ; (*String); String++)
0616     {
0617         if ((*String) == (char) ch)
0618         {
0619             return ((char *) String);
0620         }
0621     }
0622 
0623     return (NULL);
0624 }
0625 
0626 
0627 /*******************************************************************************
0628  *
0629  * FUNCTION:    strncmp
0630  *
0631  * PARAMETERS:  String1         - First string
0632  *              String2         - Second string
0633  *              Count           - Maximum # of bytes to compare
0634  *
0635  * RETURN:      Index where strings mismatched, or 0 if strings matched
0636  *
0637  * DESCRIPTION: Compare two null terminated strings, with a maximum length
0638  *
0639  ******************************************************************************/
0640 
0641 int
0642 strncmp (
0643     const char              *String1,
0644     const char              *String2,
0645     ACPI_SIZE               Count)
0646 {
0647 
0648 
0649     for ( ; Count-- && (*String1 == *String2); String2++)
0650     {
0651         if (!*String1++)
0652         {
0653             return (0);
0654         }
0655     }
0656 
0657     return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *String1 -
0658         (unsigned char) *String2));
0659 }
0660 
0661 
0662 /*******************************************************************************
0663  *
0664  * FUNCTION:    strcat
0665  *
0666  * PARAMETERS:  DstString       - Target of the copy
0667  *              SrcString       - The source string to copy
0668  *
0669  * RETURN:      DstString
0670  *
0671  * DESCRIPTION: Append a null terminated string to a null terminated string
0672  *
0673  ******************************************************************************/
0674 
0675 char *
0676 strcat (
0677     char                    *DstString,
0678     const char              *SrcString)
0679 {
0680     char                    *String;
0681 
0682 
0683     /* Find end of the destination string */
0684 
0685     for (String = DstString; *String++; )
0686     { ; }
0687 
0688     /* Concatenate the string */
0689 
0690     for (--String; (*String++ = *SrcString++); )
0691     { ; }
0692 
0693     return (DstString);
0694 }
0695 
0696 
0697 /*******************************************************************************
0698  *
0699  * FUNCTION:    strncat
0700  *
0701  * PARAMETERS:  DstString       - Target of the copy
0702  *              SrcString       - The source string to copy
0703  *              Count           - Maximum # of bytes to copy
0704  *
0705  * RETURN:      DstString
0706  *
0707  * DESCRIPTION: Append a null terminated string to a null terminated string,
0708  *              with a maximum count.
0709  *
0710  ******************************************************************************/
0711 
0712 char *
0713 strncat (
0714     char                    *DstString,
0715     const char              *SrcString,
0716     ACPI_SIZE               Count)
0717 {
0718     char                    *String;
0719 
0720 
0721     if (Count)
0722     {
0723         /* Find end of the destination string */
0724 
0725         for (String = DstString; *String++; )
0726         { ; }
0727 
0728         /* Concatenate the string */
0729 
0730         for (--String; (*String++ = *SrcString++) && --Count; )
0731         { ; }
0732 
0733         /* Null terminate if necessary */
0734 
0735         if (!Count)
0736         {
0737             *String = 0;
0738         }
0739     }
0740 
0741     return (DstString);
0742 }
0743 
0744 
0745 /*******************************************************************************
0746  *
0747  * FUNCTION:    strstr
0748  *
0749  * PARAMETERS:  String1         - Target string
0750  *              String2         - Substring to search for
0751  *
0752  * RETURN:      Where substring match starts, Null if no match found
0753  *
0754  * DESCRIPTION: Checks if String2 occurs in String1. This is not really a
0755  *              full implementation of strstr, only sufficient for command
0756  *              matching
0757  *
0758  ******************************************************************************/
0759 
0760 char *
0761 strstr (
0762     char                    *String1,
0763     char                    *String2)
0764 {
0765     ACPI_SIZE               Length;
0766 
0767 
0768     Length = strlen (String2);
0769     if (!Length)
0770     {
0771         return (String1);
0772     }
0773 
0774     while (strlen (String1) >= Length)
0775     {
0776         if (memcmp (String1, String2, Length) == 0)
0777         {
0778             return (String1);
0779         }
0780         String1++;
0781     }
0782 
0783     return (NULL);
0784 }
0785 
0786 
0787 /*******************************************************************************
0788  *
0789  * FUNCTION:    strtoul
0790  *
0791  * PARAMETERS:  String          - Null terminated string
0792  *              Terminator      - Where a pointer to the terminating byte is
0793  *                                returned
0794  *              Base            - Radix of the string
0795  *
0796  * RETURN:      Converted value
0797  *
0798  * DESCRIPTION: Convert a string into a 32-bit unsigned value.
0799  *              Note: use strtoul64 for 64-bit integers.
0800  *
0801  ******************************************************************************/
0802 
0803 UINT32
0804 strtoul (
0805     const char              *String,
0806     char                    **Terminator,
0807     UINT32                  Base)
0808 {
0809     UINT32                  converted = 0;
0810     UINT32                  index;
0811     UINT32                  sign;
0812     const char              *StringStart;
0813     UINT32                  ReturnValue = 0;
0814     ACPI_STATUS             Status = AE_OK;
0815 
0816 
0817     /*
0818      * Save the value of the pointer to the buffer's first
0819      * character, save the current errno value, and then
0820      * skip over any white space in the buffer:
0821      */
0822     StringStart = String;
0823     while (isspace (*String) || *String == '\t')
0824     {
0825         ++String;
0826     }
0827 
0828     /*
0829      * The buffer may contain an optional plus or minus sign.
0830      * If it does, then skip over it but remember what is was:
0831      */
0832     if (*String == '-')
0833     {
0834         sign = ACPI_SIGN_NEGATIVE;
0835         ++String;
0836     }
0837     else if (*String == '+')
0838     {
0839         ++String;
0840         sign = ACPI_SIGN_POSITIVE;
0841     }
0842     else
0843     {
0844         sign = ACPI_SIGN_POSITIVE;
0845     }
0846 
0847     /*
0848      * If the input parameter Base is zero, then we need to
0849      * determine if it is octal, decimal, or hexadecimal:
0850      */
0851     if (Base == 0)
0852     {
0853         if (*String == '0')
0854         {
0855             if (tolower (*(++String)) == 'x')
0856             {
0857                 Base = 16;
0858                 ++String;
0859             }
0860             else
0861             {
0862                 Base = 8;
0863             }
0864         }
0865         else
0866         {
0867             Base = 10;
0868         }
0869     }
0870     else if (Base < 2 || Base > 36)
0871     {
0872         /*
0873          * The specified Base parameter is not in the domain of
0874          * this function:
0875          */
0876         goto done;
0877     }
0878 
0879     /*
0880      * For octal and hexadecimal bases, skip over the leading
0881      * 0 or 0x, if they are present.
0882      */
0883     if (Base == 8 && *String == '0')
0884     {
0885         String++;
0886     }
0887 
0888     if (Base == 16 &&
0889         *String == '0' &&
0890         tolower (*(++String)) == 'x')
0891     {
0892         String++;
0893     }
0894 
0895     /*
0896      * Main loop: convert the string to an unsigned long:
0897      */
0898     while (*String)
0899     {
0900         if (isdigit (*String))
0901         {
0902             index = (UINT32) ((UINT8) *String - '0');
0903         }
0904         else
0905         {
0906             index = (UINT32) toupper (*String);
0907             if (isupper (index))
0908             {
0909                 index = index - 'A' + 10;
0910             }
0911             else
0912             {
0913                 goto done;
0914             }
0915         }
0916 
0917         if (index >= Base)
0918         {
0919             goto done;
0920         }
0921 
0922         /*
0923          * Check to see if value is out of range:
0924          */
0925 
0926         if (ReturnValue > ((ACPI_UINT32_MAX - (UINT32) index) /
0927                             (UINT32) Base))
0928         {
0929             Status = AE_ERROR;
0930             ReturnValue = 0;           /* reset */
0931         }
0932         else
0933         {
0934             ReturnValue *= Base;
0935             ReturnValue += index;
0936             converted = 1;
0937         }
0938 
0939         ++String;
0940     }
0941 
0942 done:
0943     /*
0944      * If appropriate, update the caller's pointer to the next
0945      * unconverted character in the buffer.
0946      */
0947     if (Terminator)
0948     {
0949         if (converted == 0 && ReturnValue == 0 && String != NULL)
0950         {
0951             *Terminator = (char *) StringStart;
0952         }
0953         else
0954         {
0955             *Terminator = (char *) String;
0956         }
0957     }
0958 
0959     if (Status == AE_ERROR)
0960     {
0961         ReturnValue = ACPI_UINT32_MAX;
0962     }
0963 
0964     /*
0965      * If a minus sign was present, then "the conversion is negated":
0966      */
0967     if (sign == ACPI_SIGN_NEGATIVE)
0968     {
0969         ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1;
0970     }
0971 
0972     return (ReturnValue);
0973 }
0974 
0975 
0976 /*******************************************************************************
0977  *
0978  * FUNCTION:    toupper
0979  *
0980  * PARAMETERS:  c           - Character to convert
0981  *
0982  * RETURN:      Converted character as an int
0983  *
0984  * DESCRIPTION: Convert character to uppercase
0985  *
0986  ******************************************************************************/
0987 
0988 int
0989 toupper (
0990     int                     c)
0991 {
0992 
0993     return (islower(c) ? ((c)-0x20) : (c));
0994 }
0995 
0996 
0997 /*******************************************************************************
0998  *
0999  * FUNCTION:    tolower
1000  *
1001  * PARAMETERS:  c           - Character to convert
1002  *
1003  * RETURN:      Converted character as an int
1004  *
1005  * DESCRIPTION: Convert character to lowercase
1006  *
1007  ******************************************************************************/
1008 
1009 int
1010 tolower (
1011     int                     c)
1012 {
1013 
1014     return (isupper(c) ? ((c)+0x20) : (c));
1015 }
1016 
1017 
1018 /*******************************************************************************
1019  *
1020  * FUNCTION:    is* function array
1021  *
1022  * DESCRIPTION: is* functions use the ctype table below
1023  *
1024  ******************************************************************************/
1025 
1026 const UINT8 AcpiGbl_Ctypes[257] = {
1027     _ACPI_CN,            /* 0x00     0 NUL */
1028     _ACPI_CN,            /* 0x01     1 SOH */
1029     _ACPI_CN,            /* 0x02     2 STX */
1030     _ACPI_CN,            /* 0x03     3 ETX */
1031     _ACPI_CN,            /* 0x04     4 EOT */
1032     _ACPI_CN,            /* 0x05     5 ENQ */
1033     _ACPI_CN,            /* 0x06     6 ACK */
1034     _ACPI_CN,            /* 0x07     7 BEL */
1035     _ACPI_CN,            /* 0x08     8 BS  */
1036     _ACPI_CN|_ACPI_SP,   /* 0x09     9 TAB */
1037     _ACPI_CN|_ACPI_SP,   /* 0x0A    10 LF  */
1038     _ACPI_CN|_ACPI_SP,   /* 0x0B    11 VT  */
1039     _ACPI_CN|_ACPI_SP,   /* 0x0C    12 FF  */
1040     _ACPI_CN|_ACPI_SP,   /* 0x0D    13 CR  */
1041     _ACPI_CN,            /* 0x0E    14 SO  */
1042     _ACPI_CN,            /* 0x0F    15 SI  */
1043     _ACPI_CN,            /* 0x10    16 DLE */
1044     _ACPI_CN,            /* 0x11    17 DC1 */
1045     _ACPI_CN,            /* 0x12    18 DC2 */
1046     _ACPI_CN,            /* 0x13    19 DC3 */
1047     _ACPI_CN,            /* 0x14    20 DC4 */
1048     _ACPI_CN,            /* 0x15    21 NAK */
1049     _ACPI_CN,            /* 0x16    22 SYN */
1050     _ACPI_CN,            /* 0x17    23 ETB */
1051     _ACPI_CN,            /* 0x18    24 CAN */
1052     _ACPI_CN,            /* 0x19    25 EM  */
1053     _ACPI_CN,            /* 0x1A    26 SUB */
1054     _ACPI_CN,            /* 0x1B    27 ESC */
1055     _ACPI_CN,            /* 0x1C    28 FS  */
1056     _ACPI_CN,            /* 0x1D    29 GS  */
1057     _ACPI_CN,            /* 0x1E    30 RS  */
1058     _ACPI_CN,            /* 0x1F    31 US  */
1059     _ACPI_XS|_ACPI_SP,   /* 0x20    32 ' ' */
1060     _ACPI_PU,            /* 0x21    33 '!' */
1061     _ACPI_PU,            /* 0x22    34 '"' */
1062     _ACPI_PU,            /* 0x23    35 '#' */
1063     _ACPI_PU,            /* 0x24    36 '$' */
1064     _ACPI_PU,            /* 0x25    37 '%' */
1065     _ACPI_PU,            /* 0x26    38 '&' */
1066     _ACPI_PU,            /* 0x27    39 ''' */
1067     _ACPI_PU,            /* 0x28    40 '(' */
1068     _ACPI_PU,            /* 0x29    41 ')' */
1069     _ACPI_PU,            /* 0x2A    42 '*' */
1070     _ACPI_PU,            /* 0x2B    43 '+' */
1071     _ACPI_PU,            /* 0x2C    44 ',' */
1072     _ACPI_PU,            /* 0x2D    45 '-' */
1073     _ACPI_PU,            /* 0x2E    46 '.' */
1074     _ACPI_PU,            /* 0x2F    47 '/' */
1075     _ACPI_XD|_ACPI_DI,   /* 0x30    48 '0' */
1076     _ACPI_XD|_ACPI_DI,   /* 0x31    49 '1' */
1077     _ACPI_XD|_ACPI_DI,   /* 0x32    50 '2' */
1078     _ACPI_XD|_ACPI_DI,   /* 0x33    51 '3' */
1079     _ACPI_XD|_ACPI_DI,   /* 0x34    52 '4' */
1080     _ACPI_XD|_ACPI_DI,   /* 0x35    53 '5' */
1081     _ACPI_XD|_ACPI_DI,   /* 0x36    54 '6' */
1082     _ACPI_XD|_ACPI_DI,   /* 0x37    55 '7' */
1083     _ACPI_XD|_ACPI_DI,   /* 0x38    56 '8' */
1084     _ACPI_XD|_ACPI_DI,   /* 0x39    57 '9' */
1085     _ACPI_PU,            /* 0x3A    58 ':' */
1086     _ACPI_PU,            /* 0x3B    59 ';' */
1087     _ACPI_PU,            /* 0x3C    60 '<' */
1088     _ACPI_PU,            /* 0x3D    61 '=' */
1089     _ACPI_PU,            /* 0x3E    62 '>' */
1090     _ACPI_PU,            /* 0x3F    63 '?' */
1091     _ACPI_PU,            /* 0x40    64 '@' */
1092     _ACPI_XD|_ACPI_UP,   /* 0x41    65 'A' */
1093     _ACPI_XD|_ACPI_UP,   /* 0x42    66 'B' */
1094     _ACPI_XD|_ACPI_UP,   /* 0x43    67 'C' */
1095     _ACPI_XD|_ACPI_UP,   /* 0x44    68 'D' */
1096     _ACPI_XD|_ACPI_UP,   /* 0x45    69 'E' */
1097     _ACPI_XD|_ACPI_UP,   /* 0x46    70 'F' */
1098     _ACPI_UP,            /* 0x47    71 'G' */
1099     _ACPI_UP,            /* 0x48    72 'H' */
1100     _ACPI_UP,            /* 0x49    73 'I' */
1101     _ACPI_UP,            /* 0x4A    74 'J' */
1102     _ACPI_UP,            /* 0x4B    75 'K' */
1103     _ACPI_UP,            /* 0x4C    76 'L' */
1104     _ACPI_UP,            /* 0x4D    77 'M' */
1105     _ACPI_UP,            /* 0x4E    78 'N' */
1106     _ACPI_UP,            /* 0x4F    79 'O' */
1107     _ACPI_UP,            /* 0x50    80 'P' */
1108     _ACPI_UP,            /* 0x51    81 'Q' */
1109     _ACPI_UP,            /* 0x52    82 'R' */
1110     _ACPI_UP,            /* 0x53    83 'S' */
1111     _ACPI_UP,            /* 0x54    84 'T' */
1112     _ACPI_UP,            /* 0x55    85 'U' */
1113     _ACPI_UP,            /* 0x56    86 'V' */
1114     _ACPI_UP,            /* 0x57    87 'W' */
1115     _ACPI_UP,            /* 0x58    88 'X' */
1116     _ACPI_UP,            /* 0x59    89 'Y' */
1117     _ACPI_UP,            /* 0x5A    90 'Z' */
1118     _ACPI_PU,            /* 0x5B    91 '[' */
1119     _ACPI_PU,            /* 0x5C    92 '\' */
1120     _ACPI_PU,            /* 0x5D    93 ']' */
1121     _ACPI_PU,            /* 0x5E    94 '^' */
1122     _ACPI_PU,            /* 0x5F    95 '_' */
1123     _ACPI_PU,            /* 0x60    96 '`' */
1124     _ACPI_XD|_ACPI_LO,   /* 0x61    97 'a' */
1125     _ACPI_XD|_ACPI_LO,   /* 0x62    98 'b' */
1126     _ACPI_XD|_ACPI_LO,   /* 0x63    99 'c' */
1127     _ACPI_XD|_ACPI_LO,   /* 0x64   100 'd' */
1128     _ACPI_XD|_ACPI_LO,   /* 0x65   101 'e' */
1129     _ACPI_XD|_ACPI_LO,   /* 0x66   102 'f' */
1130     _ACPI_LO,            /* 0x67   103 'g' */
1131     _ACPI_LO,            /* 0x68   104 'h' */
1132     _ACPI_LO,            /* 0x69   105 'i' */
1133     _ACPI_LO,            /* 0x6A   106 'j' */
1134     _ACPI_LO,            /* 0x6B   107 'k' */
1135     _ACPI_LO,            /* 0x6C   108 'l' */
1136     _ACPI_LO,            /* 0x6D   109 'm' */
1137     _ACPI_LO,            /* 0x6E   110 'n' */
1138     _ACPI_LO,            /* 0x6F   111 'o' */
1139     _ACPI_LO,            /* 0x70   112 'p' */
1140     _ACPI_LO,            /* 0x71   113 'q' */
1141     _ACPI_LO,            /* 0x72   114 'r' */
1142     _ACPI_LO,            /* 0x73   115 's' */
1143     _ACPI_LO,            /* 0x74   116 't' */
1144     _ACPI_LO,            /* 0x75   117 'u' */
1145     _ACPI_LO,            /* 0x76   118 'v' */
1146     _ACPI_LO,            /* 0x77   119 'w' */
1147     _ACPI_LO,            /* 0x78   120 'x' */
1148     _ACPI_LO,            /* 0x79   121 'y' */
1149     _ACPI_LO,            /* 0x7A   122 'z' */
1150     _ACPI_PU,            /* 0x7B   123 '{' */
1151     _ACPI_PU,            /* 0x7C   124 '|' */
1152     _ACPI_PU,            /* 0x7D   125 '}' */
1153     _ACPI_PU,            /* 0x7E   126 '~' */
1154     _ACPI_CN,            /* 0x7F   127 DEL */
1155 
1156     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0x80 to 0x8F    */
1157     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0x90 to 0x9F    */
1158     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xA0 to 0xAF    */
1159     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xB0 to 0xBF    */
1160     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xC0 to 0xCF    */
1161     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xD0 to 0xDF    */
1162     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xE0 to 0xEF    */
1163     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xF0 to 0xFF    */
1164     0                                 /* 0x100 */
1165 };
1166 
1167 
1168 #endif /* ACPI_USE_SYSTEM_CLIBRARY */