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