Misc cleanups to take care of GCC3.x warnings. Missing 'U' and 'LL'
[dragonfly.git] / sys / contrib / dev / acpica / utclib.c
1 /******************************************************************************
2  *
3  * Module Name: cmclib - Local implementation of C library functions
4  * $Revision: 51 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2003, 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 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/utclib.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $                                                               */
117
118
119 #define __CMCLIB_C__
120
121 #include "acpi.h"
122
123 /*
124  * These implementations of standard C Library routines can optionally be
125  * used if a C library is not available.  In general, they are less efficient
126  * than an inline or assembly implementation
127  */
128
129 #define _COMPONENT          ACPI_UTILITIES
130         ACPI_MODULE_NAME    ("cmclib")
131
132
133 #ifndef ACPI_USE_SYSTEM_CLIBRARY
134
135 /*******************************************************************************
136  *
137  * FUNCTION:    strlen
138  *
139  * PARAMETERS:  String              - Null terminated string
140  *
141  * RETURN:      Length
142  *
143  * DESCRIPTION: Returns the length of the input string
144  *
145  ******************************************************************************/
146
147
148 ACPI_SIZE
149 AcpiUtStrlen (
150     const char              *String)
151 {
152     UINT32                  Length = 0;
153
154
155     /* Count the string until a null is encountered */
156
157     while (*String)
158     {
159         Length++;
160         String++;
161     }
162
163     return (Length);
164 }
165
166
167 /*******************************************************************************
168  *
169  * FUNCTION:    strcpy
170  *
171  * PARAMETERS:  DstString       - Target of the copy
172  *              SrcString       - The source string to copy
173  *
174  * RETURN:      DstString
175  *
176  * DESCRIPTION: Copy a null terminated string
177  *
178  ******************************************************************************/
179
180 char *
181 AcpiUtStrcpy (
182     char                    *DstString,
183     const char              *SrcString)
184 {
185     char                    *String = DstString;
186
187
188     /* Move bytes brute force */
189
190     while (*SrcString)
191     {
192         *String = *SrcString;
193
194         String++;
195         SrcString++;
196     }
197
198     /* Null terminate */
199
200     *String = 0;
201     return (DstString);
202 }
203
204
205 /*******************************************************************************
206  *
207  * FUNCTION:    strncpy
208  *
209  * PARAMETERS:  DstString       - Target of the copy
210  *              SrcString       - The source string to copy
211  *              Count           - Maximum # of bytes to copy
212  *
213  * RETURN:      DstString
214  *
215  * DESCRIPTION: Copy a null terminated string, with a maximum length
216  *
217  ******************************************************************************/
218
219 char *
220 AcpiUtStrncpy (
221     char                    *DstString,
222     const char              *SrcString,
223     ACPI_SIZE               Count)
224 {
225     char                    *String = DstString;
226
227
228     /* Copy the string */
229
230     for (String = DstString;
231         Count && (Count--, (*String++ = *SrcString++)); )
232     {;}
233
234     /* Pad with nulls if necessary */
235
236     while (Count--)
237     {
238         *String = 0;
239         String++;
240     }
241
242     /* Return original pointer */
243
244     return (DstString);
245 }
246
247
248 /*******************************************************************************
249  *
250  * FUNCTION:    strcmp
251  *
252  * PARAMETERS:  String1         - First string
253  *              String2         - Second string
254  *
255  * RETURN:      Index where strings mismatched, or 0 if strings matched
256  *
257  * DESCRIPTION: Compare two null terminated strings
258  *
259  ******************************************************************************/
260
261 int
262 AcpiUtStrcmp (
263     const char              *String1,
264     const char              *String2)
265 {
266
267
268     for ( ; (*String1 == *String2); String2++)
269     {
270         if (!*String1++)
271         {
272             return (0);
273         }
274     }
275
276     return ((unsigned char) *String1 - (unsigned char) *String2);
277 }
278
279
280 /*******************************************************************************
281  *
282  * FUNCTION:    strncmp
283  *
284  * PARAMETERS:  String1         - First string
285  *              String2         - Second string
286  *              Count           - Maximum # of bytes to compare
287  *
288  * RETURN:      Index where strings mismatched, or 0 if strings matched
289  *
290  * DESCRIPTION: Compare two null terminated strings, with a maximum length
291  *
292  ******************************************************************************/
293
294 int
295 AcpiUtStrncmp (
296     const char              *String1,
297     const char              *String2,
298     ACPI_SIZE               Count)
299 {
300
301
302     for ( ; Count-- && (*String1 == *String2); String2++)
303     {
304         if (!*String1++)
305         {
306             return (0);
307         }
308     }
309
310     return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *String1 -
311         (unsigned char) *String2));
312 }
313
314
315 /*******************************************************************************
316  *
317  * FUNCTION:    Strcat
318  *
319  * PARAMETERS:  DstString       - Target of the copy
320  *              SrcString       - The source string to copy
321  *
322  * RETURN:      DstString
323  *
324  * DESCRIPTION: Append a null terminated string to a null terminated string
325  *
326  ******************************************************************************/
327
328 char *
329 AcpiUtStrcat (
330     char                    *DstString,
331     const char              *SrcString)
332 {
333     char                    *String;
334
335
336     /* Find end of the destination string */
337
338     for (String = DstString; *String++; )
339     { ; }
340
341     /* Concatenate the string */
342
343     for (--String; (*String++ = *SrcString++); )
344     { ; }
345
346     return (DstString);
347 }
348
349
350 /*******************************************************************************
351  *
352  * FUNCTION:    strncat
353  *
354  * PARAMETERS:  DstString       - Target of the copy
355  *              SrcString       - The source string to copy
356  *              Count           - Maximum # of bytes to copy
357  *
358  * RETURN:      DstString
359  *
360  * DESCRIPTION: Append a null terminated string to a null terminated string,
361  *              with a maximum count.
362  *
363  ******************************************************************************/
364
365 char *
366 AcpiUtStrncat (
367     char                    *DstString,
368     const char              *SrcString,
369     ACPI_SIZE               Count)
370 {
371     char                    *String;
372
373
374     if (Count)
375     {
376         /* Find end of the destination string */
377
378         for (String = DstString; *String++; )
379         { ; }
380
381         /* Concatenate the string */
382
383         for (--String; (*String++ = *SrcString++) && --Count; )
384         { ; }
385
386         /* Null terminate if necessary */
387
388         if (!Count)
389         {
390             *String = 0;
391         }
392     }
393
394     return (DstString);
395 }
396
397
398 /*******************************************************************************
399  *
400  * FUNCTION:    memcpy
401  *
402  * PARAMETERS:  Dest        - Target of the copy
403  *              Src         - Source buffer to copy
404  *              Count       - Number of bytes to copy
405  *
406  * RETURN:      Dest
407  *
408  * DESCRIPTION: Copy arbitrary bytes of memory
409  *
410  ******************************************************************************/
411
412 void *
413 AcpiUtMemcpy (
414     void                    *Dest,
415     const void              *Src,
416     ACPI_SIZE               Count)
417 {
418     char                    *New = (char *) Dest;
419     char                    *Old = (char *) Src;
420
421
422     while (Count)
423     {
424         *New = *Old;
425         New++;
426         Old++;
427         Count--;
428     }
429
430     return (Dest);
431 }
432
433
434 /*******************************************************************************
435  *
436  * FUNCTION:    memset
437  *
438  * PARAMETERS:  Dest        - Buffer to set
439  *              Value       - Value to set each byte of memory
440  *              Count       - Number of bytes to set
441  *
442  * RETURN:      Dest
443  *
444  * DESCRIPTION: Initialize a buffer to a known value.
445  *
446  ******************************************************************************/
447
448 void *
449 AcpiUtMemset (
450     void                    *Dest,
451     ACPI_NATIVE_UINT        Value,
452     ACPI_SIZE               Count)
453 {
454     char                    *New = (char *) Dest;
455
456
457     while (Count)
458     {
459         *New = (char) Value;
460         New++;
461         Count--;
462     }
463
464     return (Dest);
465 }
466
467
468 #define NEGATIVE    1
469 #define POSITIVE    0
470
471 const UINT8 _acpi_ctype[257] = {
472     _ACPI_CN,            /* 0x0      0.     */
473     _ACPI_CN,            /* 0x1      1.     */
474     _ACPI_CN,            /* 0x2      2.     */
475     _ACPI_CN,            /* 0x3      3.     */
476     _ACPI_CN,            /* 0x4      4.     */
477     _ACPI_CN,            /* 0x5      5.     */
478     _ACPI_CN,            /* 0x6      6.     */
479     _ACPI_CN,            /* 0x7      7.     */
480     _ACPI_CN,            /* 0x8      8.     */
481     _ACPI_CN|_ACPI_SP,   /* 0x9      9.     */
482     _ACPI_CN|_ACPI_SP,   /* 0xA     10.     */
483     _ACPI_CN|_ACPI_SP,   /* 0xB     11.     */
484     _ACPI_CN|_ACPI_SP,   /* 0xC     12.     */
485     _ACPI_CN|_ACPI_SP,   /* 0xD     13.     */
486     _ACPI_CN,            /* 0xE     14.     */
487     _ACPI_CN,            /* 0xF     15.     */
488     _ACPI_CN,            /* 0x10    16.     */
489     _ACPI_CN,            /* 0x11    17.     */
490     _ACPI_CN,            /* 0x12    18.     */
491     _ACPI_CN,            /* 0x13    19.     */
492     _ACPI_CN,            /* 0x14    20.     */
493     _ACPI_CN,            /* 0x15    21.     */
494     _ACPI_CN,            /* 0x16    22.     */
495     _ACPI_CN,            /* 0x17    23.     */
496     _ACPI_CN,            /* 0x18    24.     */
497     _ACPI_CN,            /* 0x19    25.     */
498     _ACPI_CN,            /* 0x1A    26.     */
499     _ACPI_CN,            /* 0x1B    27.     */
500     _ACPI_CN,            /* 0x1C    28.     */
501     _ACPI_CN,            /* 0x1D    29.     */
502     _ACPI_CN,            /* 0x1E    30.     */
503     _ACPI_CN,            /* 0x1F    31.     */
504     _ACPI_XS|_ACPI_SP,   /* 0x20    32. ' ' */
505     _ACPI_PU,            /* 0x21    33. '!' */
506     _ACPI_PU,            /* 0x22    34. '"' */
507     _ACPI_PU,            /* 0x23    35. '#' */
508     _ACPI_PU,            /* 0x24    36. '$' */
509     _ACPI_PU,            /* 0x25    37. '%' */
510     _ACPI_PU,            /* 0x26    38. '&' */
511     _ACPI_PU,            /* 0x27    39. ''' */
512     _ACPI_PU,            /* 0x28    40. '(' */
513     _ACPI_PU,            /* 0x29    41. ')' */
514     _ACPI_PU,            /* 0x2A    42. '*' */
515     _ACPI_PU,            /* 0x2B    43. '+' */
516     _ACPI_PU,            /* 0x2C    44. ',' */
517     _ACPI_PU,            /* 0x2D    45. '-' */
518     _ACPI_PU,            /* 0x2E    46. '.' */
519     _ACPI_PU,            /* 0x2F    47. '/' */
520     _ACPI_XD|_ACPI_DI,   /* 0x30    48. '0' */
521     _ACPI_XD|_ACPI_DI,   /* 0x31    49. '1' */
522     _ACPI_XD|_ACPI_DI,   /* 0x32    50. '2' */
523     _ACPI_XD|_ACPI_DI,   /* 0x33    51. '3' */
524     _ACPI_XD|_ACPI_DI,   /* 0x34    52. '4' */
525     _ACPI_XD|_ACPI_DI,   /* 0x35    53. '5' */
526     _ACPI_XD|_ACPI_DI,   /* 0x36    54. '6' */
527     _ACPI_XD|_ACPI_DI,   /* 0x37    55. '7' */
528     _ACPI_XD|_ACPI_DI,   /* 0x38    56. '8' */
529     _ACPI_XD|_ACPI_DI,   /* 0x39    57. '9' */
530     _ACPI_PU,            /* 0x3A    58. ':' */
531     _ACPI_PU,            /* 0x3B    59. ';' */
532     _ACPI_PU,            /* 0x3C    60. '<' */
533     _ACPI_PU,            /* 0x3D    61. '=' */
534     _ACPI_PU,            /* 0x3E    62. '>' */
535     _ACPI_PU,            /* 0x3F    63. '?' */
536     _ACPI_PU,            /* 0x40    64. '@' */
537     _ACPI_XD|_ACPI_UP,   /* 0x41    65. 'A' */
538     _ACPI_XD|_ACPI_UP,   /* 0x42    66. 'B' */
539     _ACPI_XD|_ACPI_UP,   /* 0x43    67. 'C' */
540     _ACPI_XD|_ACPI_UP,   /* 0x44    68. 'D' */
541     _ACPI_XD|_ACPI_UP,   /* 0x45    69. 'E' */
542     _ACPI_XD|_ACPI_UP,   /* 0x46    70. 'F' */
543     _ACPI_UP,            /* 0x47    71. 'G' */
544     _ACPI_UP,            /* 0x48    72. 'H' */
545     _ACPI_UP,            /* 0x49    73. 'I' */
546     _ACPI_UP,            /* 0x4A    74. 'J' */
547     _ACPI_UP,            /* 0x4B    75. 'K' */
548     _ACPI_UP,            /* 0x4C    76. 'L' */
549     _ACPI_UP,            /* 0x4D    77. 'M' */
550     _ACPI_UP,            /* 0x4E    78. 'N' */
551     _ACPI_UP,            /* 0x4F    79. 'O' */
552     _ACPI_UP,            /* 0x50    80. 'P' */
553     _ACPI_UP,            /* 0x51    81. 'Q' */
554     _ACPI_UP,            /* 0x52    82. 'R' */
555     _ACPI_UP,            /* 0x53    83. 'S' */
556     _ACPI_UP,            /* 0x54    84. 'T' */
557     _ACPI_UP,            /* 0x55    85. 'U' */
558     _ACPI_UP,            /* 0x56    86. 'V' */
559     _ACPI_UP,            /* 0x57    87. 'W' */
560     _ACPI_UP,            /* 0x58    88. 'X' */
561     _ACPI_UP,            /* 0x59    89. 'Y' */
562     _ACPI_UP,            /* 0x5A    90. 'Z' */
563     _ACPI_PU,            /* 0x5B    91. '[' */
564     _ACPI_PU,            /* 0x5C    92. '\' */
565     _ACPI_PU,            /* 0x5D    93. ']' */
566     _ACPI_PU,            /* 0x5E    94. '^' */
567     _ACPI_PU,            /* 0x5F    95. '_' */
568     _ACPI_PU,            /* 0x60    96. '`' */
569     _ACPI_XD|_ACPI_LO,   /* 0x61    97. 'a' */
570     _ACPI_XD|_ACPI_LO,   /* 0x62    98. 'b' */
571     _ACPI_XD|_ACPI_LO,   /* 0x63    99. 'c' */
572     _ACPI_XD|_ACPI_LO,   /* 0x64   100. 'd' */
573     _ACPI_XD|_ACPI_LO,   /* 0x65   101. 'e' */
574     _ACPI_XD|_ACPI_LO,   /* 0x66   102. 'f' */
575     _ACPI_LO,            /* 0x67   103. 'g' */
576     _ACPI_LO,            /* 0x68   104. 'h' */
577     _ACPI_LO,            /* 0x69   105. 'i' */
578     _ACPI_LO,            /* 0x6A   106. 'j' */
579     _ACPI_LO,            /* 0x6B   107. 'k' */
580     _ACPI_LO,            /* 0x6C   108. 'l' */
581     _ACPI_LO,            /* 0x6D   109. 'm' */
582     _ACPI_LO,            /* 0x6E   110. 'n' */
583     _ACPI_LO,            /* 0x6F   111. 'o' */
584     _ACPI_LO,            /* 0x70   112. 'p' */
585     _ACPI_LO,            /* 0x71   113. 'q' */
586     _ACPI_LO,            /* 0x72   114. 'r' */
587     _ACPI_LO,            /* 0x73   115. 's' */
588     _ACPI_LO,            /* 0x74   116. 't' */
589     _ACPI_LO,            /* 0x75   117. 'u' */
590     _ACPI_LO,            /* 0x76   118. 'v' */
591     _ACPI_LO,            /* 0x77   119. 'w' */
592     _ACPI_LO,            /* 0x78   120. 'x' */
593     _ACPI_LO,            /* 0x79   121. 'y' */
594     _ACPI_LO,            /* 0x7A   122. 'z' */
595     _ACPI_PU,            /* 0x7B   123. '{' */
596     _ACPI_PU,            /* 0x7C   124. '|' */
597     _ACPI_PU,            /* 0x7D   125. '}' */
598     _ACPI_PU,            /* 0x7E   126. '~' */
599     _ACPI_CN,            /* 0x7F   127.     */
600
601     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0x80 to 0x8F    */
602     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0x90 to 0x9F    */
603     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xA0 to 0xAF    */
604     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xB0 to 0xBF    */
605     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xC0 to 0xCF    */
606     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xD0 to 0xDF    */
607     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /* 0xE0 to 0xEF    */
608     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xF0 to 0x100   */
609 };
610
611 #define IS_UPPER(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_UP))
612 #define IS_LOWER(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO))
613 #define IS_DIGIT(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_DI))
614 #define IS_SPACE(c)  (_acpi_ctype[(unsigned char)(c)] & (_ACPI_SP))
615 #define IS_XDIGIT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_XD))
616
617
618 /*******************************************************************************
619  *
620  * FUNCTION:    AcpiUtToUpper
621  *
622  * PARAMETERS:
623  *
624  * RETURN:
625  *
626  * DESCRIPTION: Convert character to uppercase
627  *
628  ******************************************************************************/
629
630 int
631 AcpiUtToUpper (
632     int                     c)
633 {
634
635     return (IS_LOWER(c) ? ((c)-0x20) : (c));
636 }
637
638
639 /*******************************************************************************
640  *
641  * FUNCTION:    AcpiUtToLower
642  *
643  * PARAMETERS:
644  *
645  * RETURN:
646  *
647  * DESCRIPTION: Convert character to lowercase
648  *
649  ******************************************************************************/
650
651 int
652 AcpiUtToLower (
653     int                     c)
654 {
655
656     return (IS_UPPER(c) ? ((c)+0x20) : (c));
657 }
658
659
660 /*******************************************************************************
661  *
662  * FUNCTION:    strstr
663  *
664  * PARAMETERS:  String1       -
665  *              String2
666  *
667  * RETURN:
668  *
669  * DESCRIPTION: Checks if String2 occurs in String1. This is not really a
670  *              full implementation of strstr, only sufficient for command
671  *              matching
672  *
673  ******************************************************************************/
674
675 char *
676 AcpiUtStrstr (
677     char                    *String1,
678     char                    *String2)
679 {
680     char                    *String;
681
682
683     if (AcpiUtStrlen (String2) > AcpiUtStrlen (String1))
684     {
685         return (NULL);
686     }
687
688     /* Walk entire string, comparing the letters */
689
690     for (String = String1; *String2; )
691     {
692         if (*String2 != *String)
693         {
694             return (NULL);
695         }
696
697         String2++;
698         String++;
699     }
700
701     return (String1);
702 }
703
704
705 /*******************************************************************************
706  *
707  * FUNCTION:    strtoul
708  *
709  * PARAMETERS:  String          - Null terminated string
710  *              Terminater      - Where a pointer to the terminating byte is returned
711  *              Base            - Radix of the string
712  *
713  * RETURN:      Converted value
714  *
715  * DESCRIPTION: Convert a string into an unsigned value.
716  *
717  ******************************************************************************/
718
719 UINT32
720 AcpiUtStrtoul (
721     const char              *String,
722     char                    **Terminator,
723     UINT32                  Base)
724 {
725     UINT32                  converted = 0;
726     UINT32                  index;
727     UINT32                  sign;
728     const char              *StringStart;
729     UINT32                  ReturnValue = 0;
730     ACPI_STATUS             Status = AE_OK;
731
732
733     /*
734      * Save the value of the pointer to the buffer's first
735      * character, save the current errno value, and then
736      * skip over any white space in the buffer:
737      */
738     StringStart = String;
739     while (IS_SPACE (*String) || *String == '\t')
740     {
741         ++String;
742     }
743
744     /*
745      * The buffer may contain an optional plus or minus sign.
746      * If it does, then skip over it but remember what is was:
747      */
748     if (*String == '-')
749     {
750         sign = NEGATIVE;
751         ++String;
752     }
753     else if (*String == '+')
754     {
755         ++String;
756         sign = POSITIVE;
757     }
758     else
759     {
760         sign = POSITIVE;
761     }
762
763     /*
764      * If the input parameter Base is zero, then we need to
765      * determine if it is octal, decimal, or hexadecimal:
766      */
767     if (Base == 0)
768     {
769         if (*String == '0')
770         {
771             if (AcpiUtToLower (*(++String)) == 'x')
772             {
773                 Base = 16;
774                 ++String;
775             }
776             else
777             {
778                 Base = 8;
779             }
780         }
781         else
782         {
783             Base = 10;
784         }
785     }
786     else if (Base < 2 || Base > 36)
787     {
788         /*
789          * The specified Base parameter is not in the domain of
790          * this function:
791          */
792         goto done;
793     }
794
795     /*
796      * For octal and hexadecimal bases, skip over the leading
797      * 0 or 0x, if they are present.
798      */
799     if (Base == 8 && *String == '0')
800     {
801         String++;
802     }
803
804     if (Base == 16 &&
805         *String == '0' &&
806         AcpiUtToLower (*(++String)) == 'x')
807     {
808         String++;
809     }
810
811
812     /*
813      * Main loop: convert the string to an unsigned long:
814      */
815     while (*String)
816     {
817         if (IS_DIGIT (*String))
818         {
819             index = (UINT32) ((UINT8) *String - '0');
820         }
821         else
822         {
823             index = (UINT32) AcpiUtToUpper (*String);
824             if (IS_UPPER (index))
825             {
826                 index = index - 'A' + 10;
827             }
828             else
829             {
830                 goto done;
831             }
832         }
833
834         if (index >= Base)
835         {
836             goto done;
837         }
838
839         /*
840          * Check to see if value is out of range:
841          */
842
843         if (ReturnValue > ((ACPI_UINT32_MAX - (UINT32) index) /
844                             (UINT32) Base))
845         {
846             Status = AE_ERROR;
847             ReturnValue = 0;           /* reset */
848         }
849         else
850         {
851             ReturnValue *= Base;
852             ReturnValue += index;
853             converted = 1;
854         }
855
856         ++String;
857     }
858
859 done:
860     /*
861      * If appropriate, update the caller's pointer to the next
862      * unconverted character in the buffer.
863      */
864     if (Terminator)
865     {
866         if (converted == 0 && ReturnValue == 0 && String != NULL)
867         {
868             *Terminator = (char *) StringStart;
869         }
870         else
871         {
872             *Terminator = (char *) String;
873         }
874     }
875
876     if (Status == AE_ERROR)
877     {
878         ReturnValue = ACPI_UINT32_MAX;
879     }
880
881     /*
882      * If a minus sign was present, then "the conversion is negated":
883      */
884     if (sign == NEGATIVE)
885     {
886         ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1;
887     }
888
889     return (ReturnValue);
890 }
891
892 #endif /* ACPI_USE_SYSTEM_CLIBRARY */
893