1*3446Smrj /****************************************************************************** 2*3446Smrj * 3*3446Smrj * Module Name: cmclib - Local implementation of C library functions 4*3446Smrj * $Revision: 1.59 $ 5*3446Smrj * 6*3446Smrj *****************************************************************************/ 7*3446Smrj 8*3446Smrj /****************************************************************************** 9*3446Smrj * 10*3446Smrj * 1. Copyright Notice 11*3446Smrj * 12*3446Smrj * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp. 13*3446Smrj * All rights reserved. 14*3446Smrj * 15*3446Smrj * 2. License 16*3446Smrj * 17*3446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property 18*3446Smrj * rights. You may have additional license terms from the party that provided 19*3446Smrj * you this software, covering your right to use that party's intellectual 20*3446Smrj * property rights. 21*3446Smrj * 22*3446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23*3446Smrj * copy of the source code appearing in this file ("Covered Code") an 24*3446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25*3446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy, 26*3446Smrj * make derivatives, distribute, use and display any portion of the Covered 27*3446Smrj * Code in any form, with the right to sublicense such rights; and 28*3446Smrj * 29*3446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30*3446Smrj * license (with the right to sublicense), under only those claims of Intel 31*3446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell, 32*3446Smrj * offer to sell, and import the Covered Code and derivative works thereof 33*3446Smrj * solely to the minimum extent necessary to exercise the above copyright 34*3446Smrj * license, and in no event shall the patent license extend to any additions 35*3446Smrj * to or modifications of the Original Intel Code. No other license or right 36*3446Smrj * is granted directly or by implication, estoppel or otherwise; 37*3446Smrj * 38*3446Smrj * The above copyright and patent license is granted only if the following 39*3446Smrj * conditions are met: 40*3446Smrj * 41*3446Smrj * 3. Conditions 42*3446Smrj * 43*3446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44*3446Smrj * Redistribution of source code of any substantial portion of the Covered 45*3446Smrj * Code or modification with rights to further distribute source must include 46*3446Smrj * the above Copyright Notice, the above License, this list of Conditions, 47*3446Smrj * and the following Disclaimer and Export Compliance provision. In addition, 48*3446Smrj * Licensee must cause all Covered Code to which Licensee contributes to 49*3446Smrj * contain a file documenting the changes Licensee made to create that Covered 50*3446Smrj * Code and the date of any change. Licensee must include in that file the 51*3446Smrj * documentation of any changes made by any predecessor Licensee. Licensee 52*3446Smrj * must include a prominent statement that the modification is derived, 53*3446Smrj * directly or indirectly, from Original Intel Code. 54*3446Smrj * 55*3446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56*3446Smrj * Redistribution of source code of any substantial portion of the Covered 57*3446Smrj * Code or modification without rights to further distribute source must 58*3446Smrj * include the following Disclaimer and Export Compliance provision in the 59*3446Smrj * documentation and/or other materials provided with distribution. In 60*3446Smrj * addition, Licensee may not authorize further sublicense of source of any 61*3446Smrj * portion of the Covered Code, and must include terms to the effect that the 62*3446Smrj * license from Licensee to its licensee is limited to the intellectual 63*3446Smrj * property embodied in the software Licensee provides to its licensee, and 64*3446Smrj * not to intellectual property embodied in modifications its licensee may 65*3446Smrj * make. 66*3446Smrj * 67*3446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any 68*3446Smrj * substantial portion of the Covered Code or modification must reproduce the 69*3446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance 70*3446Smrj * provision in the documentation and/or other materials provided with the 71*3446Smrj * distribution. 72*3446Smrj * 73*3446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original 74*3446Smrj * Intel Code. 75*3446Smrj * 76*3446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77*3446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or 78*3446Smrj * other dealings in products derived from or relating to the Covered Code 79*3446Smrj * without prior written authorization from Intel. 80*3446Smrj * 81*3446Smrj * 4. Disclaimer and Export Compliance 82*3446Smrj * 83*3446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84*3446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85*3446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86*3446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87*3446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88*3446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89*3446Smrj * PARTICULAR PURPOSE. 90*3446Smrj * 91*3446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92*3446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93*3446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94*3446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95*3446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96*3446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97*3446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98*3446Smrj * LIMITED REMEDY. 99*3446Smrj * 100*3446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this 101*3446Smrj * software or system incorporating such software without first obtaining any 102*3446Smrj * required license or other approval from the U. S. Department of Commerce or 103*3446Smrj * any other agency or department of the United States Government. In the 104*3446Smrj * event Licensee exports any such software from the United States or 105*3446Smrj * re-exports any such software from a foreign destination, Licensee shall 106*3446Smrj * ensure that the distribution and export/re-export of the software is in 107*3446Smrj * compliance with all laws, regulations, orders, or other restrictions of the 108*3446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109*3446Smrj * any of its subsidiaries will export/re-export any technical data, process, 110*3446Smrj * software, or service, directly or indirectly, to any country for which the 111*3446Smrj * United States government or any agency thereof requires an export license, 112*3446Smrj * other governmental approval, or letter of assurance, without first obtaining 113*3446Smrj * such license, approval or letter. 114*3446Smrj * 115*3446Smrj *****************************************************************************/ 116*3446Smrj 117*3446Smrj 118*3446Smrj #define __CMCLIB_C__ 119*3446Smrj 120*3446Smrj #include "acpi.h" 121*3446Smrj 122*3446Smrj /* 123*3446Smrj * These implementations of standard C Library routines can optionally be 124*3446Smrj * used if a C library is not available. In general, they are less efficient 125*3446Smrj * than an inline or assembly implementation 126*3446Smrj */ 127*3446Smrj 128*3446Smrj #define _COMPONENT ACPI_UTILITIES 129*3446Smrj ACPI_MODULE_NAME ("cmclib") 130*3446Smrj 131*3446Smrj 132*3446Smrj #ifndef ACPI_USE_SYSTEM_CLIBRARY 133*3446Smrj 134*3446Smrj #define NEGATIVE 1 135*3446Smrj #define POSITIVE 0 136*3446Smrj 137*3446Smrj 138*3446Smrj /******************************************************************************* 139*3446Smrj * 140*3446Smrj * FUNCTION: AcpiUtMemcmp (memcmp) 141*3446Smrj * 142*3446Smrj * PARAMETERS: Buffer1 - First Buffer 143*3446Smrj * Buffer2 - Second Buffer 144*3446Smrj * Count - Maximum # of bytes to compare 145*3446Smrj * 146*3446Smrj * RETURN: Index where Buffers mismatched, or 0 if Buffers matched 147*3446Smrj * 148*3446Smrj * DESCRIPTION: Compare two Buffers, with a maximum length 149*3446Smrj * 150*3446Smrj ******************************************************************************/ 151*3446Smrj 152*3446Smrj int 153*3446Smrj AcpiUtMemcmp ( 154*3446Smrj const char *Buffer1, 155*3446Smrj const char *Buffer2, 156*3446Smrj ACPI_SIZE Count) 157*3446Smrj { 158*3446Smrj 159*3446Smrj for ( ; Count-- && (*Buffer1 == *Buffer2); Buffer1++, Buffer2++) 160*3446Smrj { 161*3446Smrj } 162*3446Smrj 163*3446Smrj return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *Buffer1 - 164*3446Smrj (unsigned char) *Buffer2)); 165*3446Smrj } 166*3446Smrj 167*3446Smrj 168*3446Smrj /******************************************************************************* 169*3446Smrj * 170*3446Smrj * FUNCTION: AcpiUtMemcpy (memcpy) 171*3446Smrj * 172*3446Smrj * PARAMETERS: Dest - Target of the copy 173*3446Smrj * Src - Source buffer to copy 174*3446Smrj * Count - Number of bytes to copy 175*3446Smrj * 176*3446Smrj * RETURN: Dest 177*3446Smrj * 178*3446Smrj * DESCRIPTION: Copy arbitrary bytes of memory 179*3446Smrj * 180*3446Smrj ******************************************************************************/ 181*3446Smrj 182*3446Smrj void * 183*3446Smrj AcpiUtMemcpy ( 184*3446Smrj void *Dest, 185*3446Smrj const void *Src, 186*3446Smrj ACPI_SIZE Count) 187*3446Smrj { 188*3446Smrj char *New = (char *) Dest; 189*3446Smrj char *Old = (char *) Src; 190*3446Smrj 191*3446Smrj 192*3446Smrj while (Count) 193*3446Smrj { 194*3446Smrj *New = *Old; 195*3446Smrj New++; 196*3446Smrj Old++; 197*3446Smrj Count--; 198*3446Smrj } 199*3446Smrj 200*3446Smrj return (Dest); 201*3446Smrj } 202*3446Smrj 203*3446Smrj 204*3446Smrj /******************************************************************************* 205*3446Smrj * 206*3446Smrj * FUNCTION: AcpiUtMemset (memset) 207*3446Smrj * 208*3446Smrj * PARAMETERS: Dest - Buffer to set 209*3446Smrj * Value - Value to set each byte of memory 210*3446Smrj * Count - Number of bytes to set 211*3446Smrj * 212*3446Smrj * RETURN: Dest 213*3446Smrj * 214*3446Smrj * DESCRIPTION: Initialize a buffer to a known value. 215*3446Smrj * 216*3446Smrj ******************************************************************************/ 217*3446Smrj 218*3446Smrj void * 219*3446Smrj AcpiUtMemset ( 220*3446Smrj void *Dest, 221*3446Smrj ACPI_NATIVE_UINT Value, 222*3446Smrj ACPI_SIZE Count) 223*3446Smrj { 224*3446Smrj char *New = (char *) Dest; 225*3446Smrj 226*3446Smrj 227*3446Smrj while (Count) 228*3446Smrj { 229*3446Smrj *New = (char) Value; 230*3446Smrj New++; 231*3446Smrj Count--; 232*3446Smrj } 233*3446Smrj 234*3446Smrj return (Dest); 235*3446Smrj } 236*3446Smrj 237*3446Smrj 238*3446Smrj /******************************************************************************* 239*3446Smrj * 240*3446Smrj * FUNCTION: AcpiUtStrlen (strlen) 241*3446Smrj * 242*3446Smrj * PARAMETERS: String - Null terminated string 243*3446Smrj * 244*3446Smrj * RETURN: Length 245*3446Smrj * 246*3446Smrj * DESCRIPTION: Returns the length of the input string 247*3446Smrj * 248*3446Smrj ******************************************************************************/ 249*3446Smrj 250*3446Smrj 251*3446Smrj ACPI_SIZE 252*3446Smrj AcpiUtStrlen ( 253*3446Smrj const char *String) 254*3446Smrj { 255*3446Smrj UINT32 Length = 0; 256*3446Smrj 257*3446Smrj 258*3446Smrj /* Count the string until a null is encountered */ 259*3446Smrj 260*3446Smrj while (*String) 261*3446Smrj { 262*3446Smrj Length++; 263*3446Smrj String++; 264*3446Smrj } 265*3446Smrj 266*3446Smrj return (Length); 267*3446Smrj } 268*3446Smrj 269*3446Smrj 270*3446Smrj /******************************************************************************* 271*3446Smrj * 272*3446Smrj * FUNCTION: AcpiUtStrcpy (strcpy) 273*3446Smrj * 274*3446Smrj * PARAMETERS: DstString - Target of the copy 275*3446Smrj * SrcString - The source string to copy 276*3446Smrj * 277*3446Smrj * RETURN: DstString 278*3446Smrj * 279*3446Smrj * DESCRIPTION: Copy a null terminated string 280*3446Smrj * 281*3446Smrj ******************************************************************************/ 282*3446Smrj 283*3446Smrj char * 284*3446Smrj AcpiUtStrcpy ( 285*3446Smrj char *DstString, 286*3446Smrj const char *SrcString) 287*3446Smrj { 288*3446Smrj char *String = DstString; 289*3446Smrj 290*3446Smrj 291*3446Smrj /* Move bytes brute force */ 292*3446Smrj 293*3446Smrj while (*SrcString) 294*3446Smrj { 295*3446Smrj *String = *SrcString; 296*3446Smrj 297*3446Smrj String++; 298*3446Smrj SrcString++; 299*3446Smrj } 300*3446Smrj 301*3446Smrj /* Null terminate */ 302*3446Smrj 303*3446Smrj *String = 0; 304*3446Smrj return (DstString); 305*3446Smrj } 306*3446Smrj 307*3446Smrj 308*3446Smrj /******************************************************************************* 309*3446Smrj * 310*3446Smrj * FUNCTION: AcpiUtStrncpy (strncpy) 311*3446Smrj * 312*3446Smrj * PARAMETERS: DstString - Target of the copy 313*3446Smrj * SrcString - The source string to copy 314*3446Smrj * Count - Maximum # of bytes to copy 315*3446Smrj * 316*3446Smrj * RETURN: DstString 317*3446Smrj * 318*3446Smrj * DESCRIPTION: Copy a null terminated string, with a maximum length 319*3446Smrj * 320*3446Smrj ******************************************************************************/ 321*3446Smrj 322*3446Smrj char * 323*3446Smrj AcpiUtStrncpy ( 324*3446Smrj char *DstString, 325*3446Smrj const char *SrcString, 326*3446Smrj ACPI_SIZE Count) 327*3446Smrj { 328*3446Smrj char *String = DstString; 329*3446Smrj 330*3446Smrj 331*3446Smrj /* Copy the string */ 332*3446Smrj 333*3446Smrj for (String = DstString; 334*3446Smrj Count && (Count--, (*String++ = *SrcString++)); ) 335*3446Smrj {;} 336*3446Smrj 337*3446Smrj /* Pad with nulls if necessary */ 338*3446Smrj 339*3446Smrj while (Count--) 340*3446Smrj { 341*3446Smrj *String = 0; 342*3446Smrj String++; 343*3446Smrj } 344*3446Smrj 345*3446Smrj /* Return original pointer */ 346*3446Smrj 347*3446Smrj return (DstString); 348*3446Smrj } 349*3446Smrj 350*3446Smrj 351*3446Smrj /******************************************************************************* 352*3446Smrj * 353*3446Smrj * FUNCTION: AcpiUtStrcmp (strcmp) 354*3446Smrj * 355*3446Smrj * PARAMETERS: String1 - First string 356*3446Smrj * String2 - Second string 357*3446Smrj * 358*3446Smrj * RETURN: Index where strings mismatched, or 0 if strings matched 359*3446Smrj * 360*3446Smrj * DESCRIPTION: Compare two null terminated strings 361*3446Smrj * 362*3446Smrj ******************************************************************************/ 363*3446Smrj 364*3446Smrj int 365*3446Smrj AcpiUtStrcmp ( 366*3446Smrj const char *String1, 367*3446Smrj const char *String2) 368*3446Smrj { 369*3446Smrj 370*3446Smrj 371*3446Smrj for ( ; (*String1 == *String2); String2++) 372*3446Smrj { 373*3446Smrj if (!*String1++) 374*3446Smrj { 375*3446Smrj return (0); 376*3446Smrj } 377*3446Smrj } 378*3446Smrj 379*3446Smrj return ((unsigned char) *String1 - (unsigned char) *String2); 380*3446Smrj } 381*3446Smrj 382*3446Smrj 383*3446Smrj #ifdef ACPI_FUTURE_IMPLEMENTATION 384*3446Smrj /* Not used at this time */ 385*3446Smrj /******************************************************************************* 386*3446Smrj * 387*3446Smrj * FUNCTION: AcpiUtStrchr (strchr) 388*3446Smrj * 389*3446Smrj * PARAMETERS: String - Search string 390*3446Smrj * ch - character to search for 391*3446Smrj * 392*3446Smrj * RETURN: Ptr to char or NULL if not found 393*3446Smrj * 394*3446Smrj * DESCRIPTION: Search a string for a character 395*3446Smrj * 396*3446Smrj ******************************************************************************/ 397*3446Smrj 398*3446Smrj char * 399*3446Smrj AcpiUtStrchr ( 400*3446Smrj const char *String, 401*3446Smrj int ch) 402*3446Smrj { 403*3446Smrj 404*3446Smrj 405*3446Smrj for ( ; (*String); String++) 406*3446Smrj { 407*3446Smrj if ((*String) == (char) ch) 408*3446Smrj { 409*3446Smrj return ((char *) String); 410*3446Smrj } 411*3446Smrj } 412*3446Smrj 413*3446Smrj return (NULL); 414*3446Smrj } 415*3446Smrj #endif 416*3446Smrj 417*3446Smrj /******************************************************************************* 418*3446Smrj * 419*3446Smrj * FUNCTION: AcpiUtStrncmp (strncmp) 420*3446Smrj * 421*3446Smrj * PARAMETERS: String1 - First string 422*3446Smrj * String2 - Second string 423*3446Smrj * Count - Maximum # of bytes to compare 424*3446Smrj * 425*3446Smrj * RETURN: Index where strings mismatched, or 0 if strings matched 426*3446Smrj * 427*3446Smrj * DESCRIPTION: Compare two null terminated strings, with a maximum length 428*3446Smrj * 429*3446Smrj ******************************************************************************/ 430*3446Smrj 431*3446Smrj int 432*3446Smrj AcpiUtStrncmp ( 433*3446Smrj const char *String1, 434*3446Smrj const char *String2, 435*3446Smrj ACPI_SIZE Count) 436*3446Smrj { 437*3446Smrj 438*3446Smrj 439*3446Smrj for ( ; Count-- && (*String1 == *String2); String2++) 440*3446Smrj { 441*3446Smrj if (!*String1++) 442*3446Smrj { 443*3446Smrj return (0); 444*3446Smrj } 445*3446Smrj } 446*3446Smrj 447*3446Smrj return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *String1 - 448*3446Smrj (unsigned char) *String2)); 449*3446Smrj } 450*3446Smrj 451*3446Smrj 452*3446Smrj /******************************************************************************* 453*3446Smrj * 454*3446Smrj * FUNCTION: AcpiUtStrcat (Strcat) 455*3446Smrj * 456*3446Smrj * PARAMETERS: DstString - Target of the copy 457*3446Smrj * SrcString - The source string to copy 458*3446Smrj * 459*3446Smrj * RETURN: DstString 460*3446Smrj * 461*3446Smrj * DESCRIPTION: Append a null terminated string to a null terminated string 462*3446Smrj * 463*3446Smrj ******************************************************************************/ 464*3446Smrj 465*3446Smrj char * 466*3446Smrj AcpiUtStrcat ( 467*3446Smrj char *DstString, 468*3446Smrj const char *SrcString) 469*3446Smrj { 470*3446Smrj char *String; 471*3446Smrj 472*3446Smrj 473*3446Smrj /* Find end of the destination string */ 474*3446Smrj 475*3446Smrj for (String = DstString; *String++; ) 476*3446Smrj { ; } 477*3446Smrj 478*3446Smrj /* Concatenate the string */ 479*3446Smrj 480*3446Smrj for (--String; (*String++ = *SrcString++); ) 481*3446Smrj { ; } 482*3446Smrj 483*3446Smrj return (DstString); 484*3446Smrj } 485*3446Smrj 486*3446Smrj 487*3446Smrj /******************************************************************************* 488*3446Smrj * 489*3446Smrj * FUNCTION: AcpiUtStrncat (strncat) 490*3446Smrj * 491*3446Smrj * PARAMETERS: DstString - Target of the copy 492*3446Smrj * SrcString - The source string to copy 493*3446Smrj * Count - Maximum # of bytes to copy 494*3446Smrj * 495*3446Smrj * RETURN: DstString 496*3446Smrj * 497*3446Smrj * DESCRIPTION: Append a null terminated string to a null terminated string, 498*3446Smrj * with a maximum count. 499*3446Smrj * 500*3446Smrj ******************************************************************************/ 501*3446Smrj 502*3446Smrj char * 503*3446Smrj AcpiUtStrncat ( 504*3446Smrj char *DstString, 505*3446Smrj const char *SrcString, 506*3446Smrj ACPI_SIZE Count) 507*3446Smrj { 508*3446Smrj char *String; 509*3446Smrj 510*3446Smrj 511*3446Smrj if (Count) 512*3446Smrj { 513*3446Smrj /* Find end of the destination string */ 514*3446Smrj 515*3446Smrj for (String = DstString; *String++; ) 516*3446Smrj { ; } 517*3446Smrj 518*3446Smrj /* Concatenate the string */ 519*3446Smrj 520*3446Smrj for (--String; (*String++ = *SrcString++) && --Count; ) 521*3446Smrj { ; } 522*3446Smrj 523*3446Smrj /* Null terminate if necessary */ 524*3446Smrj 525*3446Smrj if (!Count) 526*3446Smrj { 527*3446Smrj *String = 0; 528*3446Smrj } 529*3446Smrj } 530*3446Smrj 531*3446Smrj return (DstString); 532*3446Smrj } 533*3446Smrj 534*3446Smrj 535*3446Smrj /******************************************************************************* 536*3446Smrj * 537*3446Smrj * FUNCTION: AcpiUtStrstr (strstr) 538*3446Smrj * 539*3446Smrj * PARAMETERS: String1 - Target string 540*3446Smrj * String2 - Substring to search for 541*3446Smrj * 542*3446Smrj * RETURN: Where substring match starts, Null if no match found 543*3446Smrj * 544*3446Smrj * DESCRIPTION: Checks if String2 occurs in String1. This is not really a 545*3446Smrj * full implementation of strstr, only sufficient for command 546*3446Smrj * matching 547*3446Smrj * 548*3446Smrj ******************************************************************************/ 549*3446Smrj 550*3446Smrj char * 551*3446Smrj AcpiUtStrstr ( 552*3446Smrj char *String1, 553*3446Smrj char *String2) 554*3446Smrj { 555*3446Smrj char *String; 556*3446Smrj 557*3446Smrj 558*3446Smrj if (AcpiUtStrlen (String2) > AcpiUtStrlen (String1)) 559*3446Smrj { 560*3446Smrj return (NULL); 561*3446Smrj } 562*3446Smrj 563*3446Smrj /* Walk entire string, comparing the letters */ 564*3446Smrj 565*3446Smrj for (String = String1; *String2; ) 566*3446Smrj { 567*3446Smrj if (*String2 != *String) 568*3446Smrj { 569*3446Smrj return (NULL); 570*3446Smrj } 571*3446Smrj 572*3446Smrj String2++; 573*3446Smrj String++; 574*3446Smrj } 575*3446Smrj 576*3446Smrj return (String1); 577*3446Smrj } 578*3446Smrj 579*3446Smrj 580*3446Smrj /******************************************************************************* 581*3446Smrj * 582*3446Smrj * FUNCTION: AcpiUtStrtoul (strtoul) 583*3446Smrj * 584*3446Smrj * PARAMETERS: String - Null terminated string 585*3446Smrj * Terminater - Where a pointer to the terminating byte is 586*3446Smrj * returned 587*3446Smrj * Base - Radix of the string 588*3446Smrj * 589*3446Smrj * RETURN: Converted value 590*3446Smrj * 591*3446Smrj * DESCRIPTION: Convert a string into a 32-bit unsigned value. 592*3446Smrj * Note: use AcpiUtStrtoul64 for 64-bit integers. 593*3446Smrj * 594*3446Smrj ******************************************************************************/ 595*3446Smrj 596*3446Smrj UINT32 597*3446Smrj AcpiUtStrtoul ( 598*3446Smrj const char *String, 599*3446Smrj char **Terminator, 600*3446Smrj UINT32 Base) 601*3446Smrj { 602*3446Smrj UINT32 converted = 0; 603*3446Smrj UINT32 index; 604*3446Smrj UINT32 sign; 605*3446Smrj const char *StringStart; 606*3446Smrj UINT32 ReturnValue = 0; 607*3446Smrj ACPI_STATUS Status = AE_OK; 608*3446Smrj 609*3446Smrj 610*3446Smrj /* 611*3446Smrj * Save the value of the pointer to the buffer's first 612*3446Smrj * character, save the current errno value, and then 613*3446Smrj * skip over any white space in the buffer: 614*3446Smrj */ 615*3446Smrj StringStart = String; 616*3446Smrj while (ACPI_IS_SPACE (*String) || *String == '\t') 617*3446Smrj { 618*3446Smrj ++String; 619*3446Smrj } 620*3446Smrj 621*3446Smrj /* 622*3446Smrj * The buffer may contain an optional plus or minus sign. 623*3446Smrj * If it does, then skip over it but remember what is was: 624*3446Smrj */ 625*3446Smrj if (*String == '-') 626*3446Smrj { 627*3446Smrj sign = NEGATIVE; 628*3446Smrj ++String; 629*3446Smrj } 630*3446Smrj else if (*String == '+') 631*3446Smrj { 632*3446Smrj ++String; 633*3446Smrj sign = POSITIVE; 634*3446Smrj } 635*3446Smrj else 636*3446Smrj { 637*3446Smrj sign = POSITIVE; 638*3446Smrj } 639*3446Smrj 640*3446Smrj /* 641*3446Smrj * If the input parameter Base is zero, then we need to 642*3446Smrj * determine if it is octal, decimal, or hexadecimal: 643*3446Smrj */ 644*3446Smrj if (Base == 0) 645*3446Smrj { 646*3446Smrj if (*String == '0') 647*3446Smrj { 648*3446Smrj if (AcpiUtToLower (*(++String)) == 'x') 649*3446Smrj { 650*3446Smrj Base = 16; 651*3446Smrj ++String; 652*3446Smrj } 653*3446Smrj else 654*3446Smrj { 655*3446Smrj Base = 8; 656*3446Smrj } 657*3446Smrj } 658*3446Smrj else 659*3446Smrj { 660*3446Smrj Base = 10; 661*3446Smrj } 662*3446Smrj } 663*3446Smrj else if (Base < 2 || Base > 36) 664*3446Smrj { 665*3446Smrj /* 666*3446Smrj * The specified Base parameter is not in the domain of 667*3446Smrj * this function: 668*3446Smrj */ 669*3446Smrj goto done; 670*3446Smrj } 671*3446Smrj 672*3446Smrj /* 673*3446Smrj * For octal and hexadecimal bases, skip over the leading 674*3446Smrj * 0 or 0x, if they are present. 675*3446Smrj */ 676*3446Smrj if (Base == 8 && *String == '0') 677*3446Smrj { 678*3446Smrj String++; 679*3446Smrj } 680*3446Smrj 681*3446Smrj if (Base == 16 && 682*3446Smrj *String == '0' && 683*3446Smrj AcpiUtToLower (*(++String)) == 'x') 684*3446Smrj { 685*3446Smrj String++; 686*3446Smrj } 687*3446Smrj 688*3446Smrj /* 689*3446Smrj * Main loop: convert the string to an unsigned long: 690*3446Smrj */ 691*3446Smrj while (*String) 692*3446Smrj { 693*3446Smrj if (ACPI_IS_DIGIT (*String)) 694*3446Smrj { 695*3446Smrj index = (UINT32) ((UINT8) *String - '0'); 696*3446Smrj } 697*3446Smrj else 698*3446Smrj { 699*3446Smrj index = (UINT32) AcpiUtToUpper (*String); 700*3446Smrj if (ACPI_IS_UPPER (index)) 701*3446Smrj { 702*3446Smrj index = index - 'A' + 10; 703*3446Smrj } 704*3446Smrj else 705*3446Smrj { 706*3446Smrj goto done; 707*3446Smrj } 708*3446Smrj } 709*3446Smrj 710*3446Smrj if (index >= Base) 711*3446Smrj { 712*3446Smrj goto done; 713*3446Smrj } 714*3446Smrj 715*3446Smrj /* 716*3446Smrj * Check to see if value is out of range: 717*3446Smrj */ 718*3446Smrj 719*3446Smrj if (ReturnValue > ((ACPI_UINT32_MAX - (UINT32) index) / 720*3446Smrj (UINT32) Base)) 721*3446Smrj { 722*3446Smrj Status = AE_ERROR; 723*3446Smrj ReturnValue = 0; /* reset */ 724*3446Smrj } 725*3446Smrj else 726*3446Smrj { 727*3446Smrj ReturnValue *= Base; 728*3446Smrj ReturnValue += index; 729*3446Smrj converted = 1; 730*3446Smrj } 731*3446Smrj 732*3446Smrj ++String; 733*3446Smrj } 734*3446Smrj 735*3446Smrj done: 736*3446Smrj /* 737*3446Smrj * If appropriate, update the caller's pointer to the next 738*3446Smrj * unconverted character in the buffer. 739*3446Smrj */ 740*3446Smrj if (Terminator) 741*3446Smrj { 742*3446Smrj if (converted == 0 && ReturnValue == 0 && String != NULL) 743*3446Smrj { 744*3446Smrj *Terminator = (char *) StringStart; 745*3446Smrj } 746*3446Smrj else 747*3446Smrj { 748*3446Smrj *Terminator = (char *) String; 749*3446Smrj } 750*3446Smrj } 751*3446Smrj 752*3446Smrj if (Status == AE_ERROR) 753*3446Smrj { 754*3446Smrj ReturnValue = ACPI_UINT32_MAX; 755*3446Smrj } 756*3446Smrj 757*3446Smrj /* 758*3446Smrj * If a minus sign was present, then "the conversion is negated": 759*3446Smrj */ 760*3446Smrj if (sign == NEGATIVE) 761*3446Smrj { 762*3446Smrj ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1; 763*3446Smrj } 764*3446Smrj 765*3446Smrj return (ReturnValue); 766*3446Smrj } 767*3446Smrj 768*3446Smrj 769*3446Smrj /******************************************************************************* 770*3446Smrj * 771*3446Smrj * FUNCTION: AcpiUtToUpper (TOUPPER) 772*3446Smrj * 773*3446Smrj * PARAMETERS: c - Character to convert 774*3446Smrj * 775*3446Smrj * RETURN: Converted character as an int 776*3446Smrj * 777*3446Smrj * DESCRIPTION: Convert character to uppercase 778*3446Smrj * 779*3446Smrj ******************************************************************************/ 780*3446Smrj 781*3446Smrj int 782*3446Smrj AcpiUtToUpper ( 783*3446Smrj int c) 784*3446Smrj { 785*3446Smrj 786*3446Smrj return (ACPI_IS_LOWER(c) ? ((c)-0x20) : (c)); 787*3446Smrj } 788*3446Smrj 789*3446Smrj 790*3446Smrj /******************************************************************************* 791*3446Smrj * 792*3446Smrj * FUNCTION: AcpiUtToLower (TOLOWER) 793*3446Smrj * 794*3446Smrj * PARAMETERS: c - Character to convert 795*3446Smrj * 796*3446Smrj * RETURN: Converted character as an int 797*3446Smrj * 798*3446Smrj * DESCRIPTION: Convert character to lowercase 799*3446Smrj * 800*3446Smrj ******************************************************************************/ 801*3446Smrj 802*3446Smrj int 803*3446Smrj AcpiUtToLower ( 804*3446Smrj int c) 805*3446Smrj { 806*3446Smrj 807*3446Smrj return (ACPI_IS_UPPER(c) ? ((c)+0x20) : (c)); 808*3446Smrj } 809*3446Smrj 810*3446Smrj 811*3446Smrj /******************************************************************************* 812*3446Smrj * 813*3446Smrj * FUNCTION: is* functions 814*3446Smrj * 815*3446Smrj * DESCRIPTION: is* functions use the ctype table below 816*3446Smrj * 817*3446Smrj ******************************************************************************/ 818*3446Smrj 819*3446Smrj const UINT8 _acpi_ctype[257] = { 820*3446Smrj _ACPI_CN, /* 0x0 0. */ 821*3446Smrj _ACPI_CN, /* 0x1 1. */ 822*3446Smrj _ACPI_CN, /* 0x2 2. */ 823*3446Smrj _ACPI_CN, /* 0x3 3. */ 824*3446Smrj _ACPI_CN, /* 0x4 4. */ 825*3446Smrj _ACPI_CN, /* 0x5 5. */ 826*3446Smrj _ACPI_CN, /* 0x6 6. */ 827*3446Smrj _ACPI_CN, /* 0x7 7. */ 828*3446Smrj _ACPI_CN, /* 0x8 8. */ 829*3446Smrj _ACPI_CN|_ACPI_SP, /* 0x9 9. */ 830*3446Smrj _ACPI_CN|_ACPI_SP, /* 0xA 10. */ 831*3446Smrj _ACPI_CN|_ACPI_SP, /* 0xB 11. */ 832*3446Smrj _ACPI_CN|_ACPI_SP, /* 0xC 12. */ 833*3446Smrj _ACPI_CN|_ACPI_SP, /* 0xD 13. */ 834*3446Smrj _ACPI_CN, /* 0xE 14. */ 835*3446Smrj _ACPI_CN, /* 0xF 15. */ 836*3446Smrj _ACPI_CN, /* 0x10 16. */ 837*3446Smrj _ACPI_CN, /* 0x11 17. */ 838*3446Smrj _ACPI_CN, /* 0x12 18. */ 839*3446Smrj _ACPI_CN, /* 0x13 19. */ 840*3446Smrj _ACPI_CN, /* 0x14 20. */ 841*3446Smrj _ACPI_CN, /* 0x15 21. */ 842*3446Smrj _ACPI_CN, /* 0x16 22. */ 843*3446Smrj _ACPI_CN, /* 0x17 23. */ 844*3446Smrj _ACPI_CN, /* 0x18 24. */ 845*3446Smrj _ACPI_CN, /* 0x19 25. */ 846*3446Smrj _ACPI_CN, /* 0x1A 26. */ 847*3446Smrj _ACPI_CN, /* 0x1B 27. */ 848*3446Smrj _ACPI_CN, /* 0x1C 28. */ 849*3446Smrj _ACPI_CN, /* 0x1D 29. */ 850*3446Smrj _ACPI_CN, /* 0x1E 30. */ 851*3446Smrj _ACPI_CN, /* 0x1F 31. */ 852*3446Smrj _ACPI_XS|_ACPI_SP, /* 0x20 32. ' ' */ 853*3446Smrj _ACPI_PU, /* 0x21 33. '!' */ 854*3446Smrj _ACPI_PU, /* 0x22 34. '"' */ 855*3446Smrj _ACPI_PU, /* 0x23 35. '#' */ 856*3446Smrj _ACPI_PU, /* 0x24 36. '$' */ 857*3446Smrj _ACPI_PU, /* 0x25 37. '%' */ 858*3446Smrj _ACPI_PU, /* 0x26 38. '&' */ 859*3446Smrj _ACPI_PU, /* 0x27 39. ''' */ 860*3446Smrj _ACPI_PU, /* 0x28 40. '(' */ 861*3446Smrj _ACPI_PU, /* 0x29 41. ')' */ 862*3446Smrj _ACPI_PU, /* 0x2A 42. '*' */ 863*3446Smrj _ACPI_PU, /* 0x2B 43. '+' */ 864*3446Smrj _ACPI_PU, /* 0x2C 44. ',' */ 865*3446Smrj _ACPI_PU, /* 0x2D 45. '-' */ 866*3446Smrj _ACPI_PU, /* 0x2E 46. '.' */ 867*3446Smrj _ACPI_PU, /* 0x2F 47. '/' */ 868*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x30 48. '0' */ 869*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x31 49. '1' */ 870*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x32 50. '2' */ 871*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x33 51. '3' */ 872*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x34 52. '4' */ 873*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x35 53. '5' */ 874*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x36 54. '6' */ 875*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x37 55. '7' */ 876*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x38 56. '8' */ 877*3446Smrj _ACPI_XD|_ACPI_DI, /* 0x39 57. '9' */ 878*3446Smrj _ACPI_PU, /* 0x3A 58. ':' */ 879*3446Smrj _ACPI_PU, /* 0x3B 59. ';' */ 880*3446Smrj _ACPI_PU, /* 0x3C 60. '<' */ 881*3446Smrj _ACPI_PU, /* 0x3D 61. '=' */ 882*3446Smrj _ACPI_PU, /* 0x3E 62. '>' */ 883*3446Smrj _ACPI_PU, /* 0x3F 63. '?' */ 884*3446Smrj _ACPI_PU, /* 0x40 64. '@' */ 885*3446Smrj _ACPI_XD|_ACPI_UP, /* 0x41 65. 'A' */ 886*3446Smrj _ACPI_XD|_ACPI_UP, /* 0x42 66. 'B' */ 887*3446Smrj _ACPI_XD|_ACPI_UP, /* 0x43 67. 'C' */ 888*3446Smrj _ACPI_XD|_ACPI_UP, /* 0x44 68. 'D' */ 889*3446Smrj _ACPI_XD|_ACPI_UP, /* 0x45 69. 'E' */ 890*3446Smrj _ACPI_XD|_ACPI_UP, /* 0x46 70. 'F' */ 891*3446Smrj _ACPI_UP, /* 0x47 71. 'G' */ 892*3446Smrj _ACPI_UP, /* 0x48 72. 'H' */ 893*3446Smrj _ACPI_UP, /* 0x49 73. 'I' */ 894*3446Smrj _ACPI_UP, /* 0x4A 74. 'J' */ 895*3446Smrj _ACPI_UP, /* 0x4B 75. 'K' */ 896*3446Smrj _ACPI_UP, /* 0x4C 76. 'L' */ 897*3446Smrj _ACPI_UP, /* 0x4D 77. 'M' */ 898*3446Smrj _ACPI_UP, /* 0x4E 78. 'N' */ 899*3446Smrj _ACPI_UP, /* 0x4F 79. 'O' */ 900*3446Smrj _ACPI_UP, /* 0x50 80. 'P' */ 901*3446Smrj _ACPI_UP, /* 0x51 81. 'Q' */ 902*3446Smrj _ACPI_UP, /* 0x52 82. 'R' */ 903*3446Smrj _ACPI_UP, /* 0x53 83. 'S' */ 904*3446Smrj _ACPI_UP, /* 0x54 84. 'T' */ 905*3446Smrj _ACPI_UP, /* 0x55 85. 'U' */ 906*3446Smrj _ACPI_UP, /* 0x56 86. 'V' */ 907*3446Smrj _ACPI_UP, /* 0x57 87. 'W' */ 908*3446Smrj _ACPI_UP, /* 0x58 88. 'X' */ 909*3446Smrj _ACPI_UP, /* 0x59 89. 'Y' */ 910*3446Smrj _ACPI_UP, /* 0x5A 90. 'Z' */ 911*3446Smrj _ACPI_PU, /* 0x5B 91. '[' */ 912*3446Smrj _ACPI_PU, /* 0x5C 92. '\' */ 913*3446Smrj _ACPI_PU, /* 0x5D 93. ']' */ 914*3446Smrj _ACPI_PU, /* 0x5E 94. '^' */ 915*3446Smrj _ACPI_PU, /* 0x5F 95. '_' */ 916*3446Smrj _ACPI_PU, /* 0x60 96. '`' */ 917*3446Smrj _ACPI_XD|_ACPI_LO, /* 0x61 97. 'a' */ 918*3446Smrj _ACPI_XD|_ACPI_LO, /* 0x62 98. 'b' */ 919*3446Smrj _ACPI_XD|_ACPI_LO, /* 0x63 99. 'c' */ 920*3446Smrj _ACPI_XD|_ACPI_LO, /* 0x64 100. 'd' */ 921*3446Smrj _ACPI_XD|_ACPI_LO, /* 0x65 101. 'e' */ 922*3446Smrj _ACPI_XD|_ACPI_LO, /* 0x66 102. 'f' */ 923*3446Smrj _ACPI_LO, /* 0x67 103. 'g' */ 924*3446Smrj _ACPI_LO, /* 0x68 104. 'h' */ 925*3446Smrj _ACPI_LO, /* 0x69 105. 'i' */ 926*3446Smrj _ACPI_LO, /* 0x6A 106. 'j' */ 927*3446Smrj _ACPI_LO, /* 0x6B 107. 'k' */ 928*3446Smrj _ACPI_LO, /* 0x6C 108. 'l' */ 929*3446Smrj _ACPI_LO, /* 0x6D 109. 'm' */ 930*3446Smrj _ACPI_LO, /* 0x6E 110. 'n' */ 931*3446Smrj _ACPI_LO, /* 0x6F 111. 'o' */ 932*3446Smrj _ACPI_LO, /* 0x70 112. 'p' */ 933*3446Smrj _ACPI_LO, /* 0x71 113. 'q' */ 934*3446Smrj _ACPI_LO, /* 0x72 114. 'r' */ 935*3446Smrj _ACPI_LO, /* 0x73 115. 's' */ 936*3446Smrj _ACPI_LO, /* 0x74 116. 't' */ 937*3446Smrj _ACPI_LO, /* 0x75 117. 'u' */ 938*3446Smrj _ACPI_LO, /* 0x76 118. 'v' */ 939*3446Smrj _ACPI_LO, /* 0x77 119. 'w' */ 940*3446Smrj _ACPI_LO, /* 0x78 120. 'x' */ 941*3446Smrj _ACPI_LO, /* 0x79 121. 'y' */ 942*3446Smrj _ACPI_LO, /* 0x7A 122. 'z' */ 943*3446Smrj _ACPI_PU, /* 0x7B 123. '{' */ 944*3446Smrj _ACPI_PU, /* 0x7C 124. '|' */ 945*3446Smrj _ACPI_PU, /* 0x7D 125. '}' */ 946*3446Smrj _ACPI_PU, /* 0x7E 126. '~' */ 947*3446Smrj _ACPI_CN, /* 0x7F 127. */ 948*3446Smrj 949*3446Smrj 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x80 to 0x8F */ 950*3446Smrj 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x90 to 0x9F */ 951*3446Smrj 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xA0 to 0xAF */ 952*3446Smrj 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xB0 to 0xBF */ 953*3446Smrj 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xC0 to 0xCF */ 954*3446Smrj 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xD0 to 0xDF */ 955*3446Smrj 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xE0 to 0xEF */ 956*3446Smrj 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xF0 to 0x100 */ 957*3446Smrj }; 958*3446Smrj 959*3446Smrj 960*3446Smrj #endif /* ACPI_USE_SYSTEM_CLIBRARY */ 961*3446Smrj 962