utstring.c revision 1.1.1.3 1 1.1 christos /*******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: utstring - Common functions for strings and characters
4 1.1 christos *
5 1.1 christos ******************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1.1.3 christos * Copyright (C) 2000 - 2015, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "acpi.h"
45 1.1 christos #include "accommon.h"
46 1.1 christos #include "acnamesp.h"
47 1.1 christos
48 1.1 christos
49 1.1 christos #define _COMPONENT ACPI_UTILITIES
50 1.1 christos ACPI_MODULE_NAME ("utstring")
51 1.1 christos
52 1.1 christos
53 1.1 christos /*
54 1.1 christos * Non-ANSI C library functions - strlwr, strupr, stricmp, and a 64-bit
55 1.1 christos * version of strtoul.
56 1.1 christos */
57 1.1 christos
58 1.1 christos #ifdef ACPI_ASL_COMPILER
59 1.1 christos /*******************************************************************************
60 1.1 christos *
61 1.1 christos * FUNCTION: AcpiUtStrlwr (strlwr)
62 1.1 christos *
63 1.1 christos * PARAMETERS: SrcString - The source string to convert
64 1.1 christos *
65 1.1 christos * RETURN: None
66 1.1 christos *
67 1.1 christos * DESCRIPTION: Convert string to lowercase
68 1.1 christos *
69 1.1 christos * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
70 1.1 christos *
71 1.1 christos ******************************************************************************/
72 1.1 christos
73 1.1 christos void
74 1.1 christos AcpiUtStrlwr (
75 1.1 christos char *SrcString)
76 1.1 christos {
77 1.1 christos char *String;
78 1.1 christos
79 1.1 christos
80 1.1 christos ACPI_FUNCTION_ENTRY ();
81 1.1 christos
82 1.1 christos
83 1.1 christos if (!SrcString)
84 1.1 christos {
85 1.1 christos return;
86 1.1 christos }
87 1.1 christos
88 1.1 christos /* Walk entire string, lowercasing the letters */
89 1.1 christos
90 1.1 christos for (String = SrcString; *String; String++)
91 1.1 christos {
92 1.1 christos *String = (char) ACPI_TOLOWER (*String);
93 1.1 christos }
94 1.1 christos
95 1.1 christos return;
96 1.1 christos }
97 1.1 christos
98 1.1 christos
99 1.1 christos /******************************************************************************
100 1.1 christos *
101 1.1 christos * FUNCTION: AcpiUtStricmp (stricmp)
102 1.1 christos *
103 1.1 christos * PARAMETERS: String1 - first string to compare
104 1.1 christos * String2 - second string to compare
105 1.1 christos *
106 1.1 christos * RETURN: int that signifies string relationship. Zero means strings
107 1.1 christos * are equal.
108 1.1 christos *
109 1.1 christos * DESCRIPTION: Implementation of the non-ANSI stricmp function (compare
110 1.1 christos * strings with no case sensitivity)
111 1.1 christos *
112 1.1 christos ******************************************************************************/
113 1.1 christos
114 1.1 christos int
115 1.1 christos AcpiUtStricmp (
116 1.1 christos char *String1,
117 1.1 christos char *String2)
118 1.1 christos {
119 1.1 christos int c1;
120 1.1 christos int c2;
121 1.1 christos
122 1.1 christos
123 1.1 christos do
124 1.1 christos {
125 1.1 christos c1 = tolower ((int) *String1);
126 1.1 christos c2 = tolower ((int) *String2);
127 1.1 christos
128 1.1 christos String1++;
129 1.1 christos String2++;
130 1.1 christos }
131 1.1 christos while ((c1 == c2) && (c1));
132 1.1 christos
133 1.1 christos return (c1 - c2);
134 1.1 christos }
135 1.1 christos #endif
136 1.1 christos
137 1.1 christos
138 1.1 christos /*******************************************************************************
139 1.1 christos *
140 1.1 christos * FUNCTION: AcpiUtStrupr (strupr)
141 1.1 christos *
142 1.1 christos * PARAMETERS: SrcString - The source string to convert
143 1.1 christos *
144 1.1 christos * RETURN: None
145 1.1 christos *
146 1.1 christos * DESCRIPTION: Convert string to uppercase
147 1.1 christos *
148 1.1 christos * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
149 1.1 christos *
150 1.1 christos ******************************************************************************/
151 1.1 christos
152 1.1 christos void
153 1.1 christos AcpiUtStrupr (
154 1.1 christos char *SrcString)
155 1.1 christos {
156 1.1 christos char *String;
157 1.1 christos
158 1.1 christos
159 1.1 christos ACPI_FUNCTION_ENTRY ();
160 1.1 christos
161 1.1 christos
162 1.1 christos if (!SrcString)
163 1.1 christos {
164 1.1 christos return;
165 1.1 christos }
166 1.1 christos
167 1.1 christos /* Walk entire string, uppercasing the letters */
168 1.1 christos
169 1.1 christos for (String = SrcString; *String; String++)
170 1.1 christos {
171 1.1 christos *String = (char) ACPI_TOUPPER (*String);
172 1.1 christos }
173 1.1 christos
174 1.1 christos return;
175 1.1 christos }
176 1.1 christos
177 1.1 christos
178 1.1 christos /*******************************************************************************
179 1.1 christos *
180 1.1 christos * FUNCTION: AcpiUtStrtoul64
181 1.1 christos *
182 1.1 christos * PARAMETERS: String - Null terminated string
183 1.1 christos * Base - Radix of the string: 16 or ACPI_ANY_BASE;
184 1.1 christos * ACPI_ANY_BASE means 'in behalf of ToInteger'
185 1.1 christos * RetInteger - Where the converted integer is returned
186 1.1 christos *
187 1.1 christos * RETURN: Status and Converted value
188 1.1 christos *
189 1.1 christos * DESCRIPTION: Convert a string into an unsigned value. Performs either a
190 1.1 christos * 32-bit or 64-bit conversion, depending on the current mode
191 1.1 christos * of the interpreter.
192 1.1 christos * NOTE: Does not support Octal strings, not needed.
193 1.1 christos *
194 1.1 christos ******************************************************************************/
195 1.1 christos
196 1.1 christos ACPI_STATUS
197 1.1 christos AcpiUtStrtoul64 (
198 1.1 christos char *String,
199 1.1 christos UINT32 Base,
200 1.1 christos UINT64 *RetInteger)
201 1.1 christos {
202 1.1 christos UINT32 ThisDigit = 0;
203 1.1 christos UINT64 ReturnValue = 0;
204 1.1 christos UINT64 Quotient;
205 1.1 christos UINT64 Dividend;
206 1.1 christos UINT32 ToIntegerOp = (Base == ACPI_ANY_BASE);
207 1.1 christos UINT32 Mode32 = (AcpiGbl_IntegerByteWidth == 4);
208 1.1 christos UINT8 ValidDigits = 0;
209 1.1 christos UINT8 SignOf0x = 0;
210 1.1 christos UINT8 Term = 0;
211 1.1 christos
212 1.1 christos
213 1.1 christos ACPI_FUNCTION_TRACE_STR (UtStroul64, String);
214 1.1 christos
215 1.1 christos
216 1.1 christos switch (Base)
217 1.1 christos {
218 1.1 christos case ACPI_ANY_BASE:
219 1.1 christos case 16:
220 1.1 christos
221 1.1 christos break;
222 1.1 christos
223 1.1 christos default:
224 1.1 christos
225 1.1 christos /* Invalid Base */
226 1.1 christos
227 1.1 christos return_ACPI_STATUS (AE_BAD_PARAMETER);
228 1.1 christos }
229 1.1 christos
230 1.1 christos if (!String)
231 1.1 christos {
232 1.1 christos goto ErrorExit;
233 1.1 christos }
234 1.1 christos
235 1.1 christos /* Skip over any white space in the buffer */
236 1.1 christos
237 1.1 christos while ((*String) && (ACPI_IS_SPACE (*String) || *String == '\t'))
238 1.1 christos {
239 1.1 christos String++;
240 1.1 christos }
241 1.1 christos
242 1.1 christos if (ToIntegerOp)
243 1.1 christos {
244 1.1 christos /*
245 1.1 christos * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
246 1.1 christos * We need to determine if it is decimal or hexadecimal.
247 1.1 christos */
248 1.1 christos if ((*String == '0') && (ACPI_TOLOWER (*(String + 1)) == 'x'))
249 1.1 christos {
250 1.1 christos SignOf0x = 1;
251 1.1 christos Base = 16;
252 1.1 christos
253 1.1 christos /* Skip over the leading '0x' */
254 1.1 christos String += 2;
255 1.1 christos }
256 1.1 christos else
257 1.1 christos {
258 1.1 christos Base = 10;
259 1.1 christos }
260 1.1 christos }
261 1.1 christos
262 1.1 christos /* Any string left? Check that '0x' is not followed by white space. */
263 1.1 christos
264 1.1 christos if (!(*String) || ACPI_IS_SPACE (*String) || *String == '\t')
265 1.1 christos {
266 1.1 christos if (ToIntegerOp)
267 1.1 christos {
268 1.1 christos goto ErrorExit;
269 1.1 christos }
270 1.1 christos else
271 1.1 christos {
272 1.1 christos goto AllDone;
273 1.1 christos }
274 1.1 christos }
275 1.1 christos
276 1.1 christos /*
277 1.1 christos * Perform a 32-bit or 64-bit conversion, depending upon the current
278 1.1 christos * execution mode of the interpreter
279 1.1 christos */
280 1.1 christos Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
281 1.1 christos
282 1.1 christos /* Main loop: convert the string to a 32- or 64-bit integer */
283 1.1 christos
284 1.1 christos while (*String)
285 1.1 christos {
286 1.1 christos if (ACPI_IS_DIGIT (*String))
287 1.1 christos {
288 1.1 christos /* Convert ASCII 0-9 to Decimal value */
289 1.1 christos
290 1.1 christos ThisDigit = ((UINT8) *String) - '0';
291 1.1 christos }
292 1.1 christos else if (Base == 10)
293 1.1 christos {
294 1.1 christos /* Digit is out of range; possible in ToInteger case only */
295 1.1 christos
296 1.1 christos Term = 1;
297 1.1 christos }
298 1.1 christos else
299 1.1 christos {
300 1.1 christos ThisDigit = (UINT8) ACPI_TOUPPER (*String);
301 1.1 christos if (ACPI_IS_XDIGIT ((char) ThisDigit))
302 1.1 christos {
303 1.1 christos /* Convert ASCII Hex char to value */
304 1.1 christos
305 1.1 christos ThisDigit = ThisDigit - 'A' + 10;
306 1.1 christos }
307 1.1 christos else
308 1.1 christos {
309 1.1 christos Term = 1;
310 1.1 christos }
311 1.1 christos }
312 1.1 christos
313 1.1 christos if (Term)
314 1.1 christos {
315 1.1 christos if (ToIntegerOp)
316 1.1 christos {
317 1.1 christos goto ErrorExit;
318 1.1 christos }
319 1.1 christos else
320 1.1 christos {
321 1.1 christos break;
322 1.1 christos }
323 1.1 christos }
324 1.1 christos else if ((ValidDigits == 0) && (ThisDigit == 0) && !SignOf0x)
325 1.1 christos {
326 1.1 christos /* Skip zeros */
327 1.1 christos String++;
328 1.1 christos continue;
329 1.1 christos }
330 1.1 christos
331 1.1 christos ValidDigits++;
332 1.1 christos
333 1.1 christos if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32)))
334 1.1 christos {
335 1.1 christos /*
336 1.1 christos * This is ToInteger operation case.
337 1.1 christos * No any restrictions for string-to-integer conversion,
338 1.1 christos * see ACPI spec.
339 1.1 christos */
340 1.1 christos goto ErrorExit;
341 1.1 christos }
342 1.1 christos
343 1.1 christos /* Divide the digit into the correct position */
344 1.1 christos
345 1.1 christos (void) AcpiUtShortDivide ((Dividend - (UINT64) ThisDigit),
346 1.1 christos Base, &Quotient, NULL);
347 1.1 christos
348 1.1 christos if (ReturnValue > Quotient)
349 1.1 christos {
350 1.1 christos if (ToIntegerOp)
351 1.1 christos {
352 1.1 christos goto ErrorExit;
353 1.1 christos }
354 1.1 christos else
355 1.1 christos {
356 1.1 christos break;
357 1.1 christos }
358 1.1 christos }
359 1.1 christos
360 1.1 christos ReturnValue *= Base;
361 1.1 christos ReturnValue += ThisDigit;
362 1.1 christos String++;
363 1.1 christos }
364 1.1 christos
365 1.1 christos /* All done, normal exit */
366 1.1 christos
367 1.1 christos AllDone:
368 1.1 christos
369 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
370 1.1 christos ACPI_FORMAT_UINT64 (ReturnValue)));
371 1.1 christos
372 1.1 christos *RetInteger = ReturnValue;
373 1.1 christos return_ACPI_STATUS (AE_OK);
374 1.1 christos
375 1.1 christos
376 1.1 christos ErrorExit:
377 1.1 christos /* Base was set/validated above */
378 1.1 christos
379 1.1 christos if (Base == 10)
380 1.1 christos {
381 1.1 christos return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
382 1.1 christos }
383 1.1 christos else
384 1.1 christos {
385 1.1 christos return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
386 1.1 christos }
387 1.1 christos }
388 1.1 christos
389 1.1 christos
390 1.1 christos /*******************************************************************************
391 1.1 christos *
392 1.1 christos * FUNCTION: AcpiUtPrintString
393 1.1 christos *
394 1.1 christos * PARAMETERS: String - Null terminated ASCII string
395 1.1 christos * MaxLength - Maximum output length. Used to constrain the
396 1.1 christos * length of strings during debug output only.
397 1.1 christos *
398 1.1 christos * RETURN: None
399 1.1 christos *
400 1.1 christos * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
401 1.1 christos * sequences.
402 1.1 christos *
403 1.1 christos ******************************************************************************/
404 1.1 christos
405 1.1 christos void
406 1.1 christos AcpiUtPrintString (
407 1.1 christos char *String,
408 1.1 christos UINT16 MaxLength)
409 1.1 christos {
410 1.1 christos UINT32 i;
411 1.1 christos
412 1.1 christos
413 1.1 christos if (!String)
414 1.1 christos {
415 1.1 christos AcpiOsPrintf ("<\"NULL STRING PTR\">");
416 1.1 christos return;
417 1.1 christos }
418 1.1 christos
419 1.1 christos AcpiOsPrintf ("\"");
420 1.1.1.2 christos for (i = 0; (i < MaxLength) && String[i]; i++)
421 1.1 christos {
422 1.1 christos /* Escape sequences */
423 1.1 christos
424 1.1 christos switch (String[i])
425 1.1 christos {
426 1.1 christos case 0x07:
427 1.1 christos
428 1.1 christos AcpiOsPrintf ("\\a"); /* BELL */
429 1.1 christos break;
430 1.1 christos
431 1.1 christos case 0x08:
432 1.1 christos
433 1.1 christos AcpiOsPrintf ("\\b"); /* BACKSPACE */
434 1.1 christos break;
435 1.1 christos
436 1.1 christos case 0x0C:
437 1.1 christos
438 1.1 christos AcpiOsPrintf ("\\f"); /* FORMFEED */
439 1.1 christos break;
440 1.1 christos
441 1.1 christos case 0x0A:
442 1.1 christos
443 1.1 christos AcpiOsPrintf ("\\n"); /* LINEFEED */
444 1.1 christos break;
445 1.1 christos
446 1.1 christos case 0x0D:
447 1.1 christos
448 1.1 christos AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
449 1.1 christos break;
450 1.1 christos
451 1.1 christos case 0x09:
452 1.1 christos
453 1.1 christos AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
454 1.1 christos break;
455 1.1 christos
456 1.1 christos case 0x0B:
457 1.1 christos
458 1.1 christos AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
459 1.1 christos break;
460 1.1 christos
461 1.1 christos case '\'': /* Single Quote */
462 1.1 christos case '\"': /* Double Quote */
463 1.1 christos case '\\': /* Backslash */
464 1.1 christos
465 1.1 christos AcpiOsPrintf ("\\%c", (int) String[i]);
466 1.1 christos break;
467 1.1 christos
468 1.1 christos default:
469 1.1 christos
470 1.1 christos /* Check for printable character or hex escape */
471 1.1 christos
472 1.1 christos if (ACPI_IS_PRINT (String[i]))
473 1.1 christos {
474 1.1 christos /* This is a normal character */
475 1.1 christos
476 1.1 christos AcpiOsPrintf ("%c", (int) String[i]);
477 1.1 christos }
478 1.1 christos else
479 1.1 christos {
480 1.1 christos /* All others will be Hex escapes */
481 1.1 christos
482 1.1 christos AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
483 1.1 christos }
484 1.1 christos break;
485 1.1 christos }
486 1.1 christos }
487 1.1 christos AcpiOsPrintf ("\"");
488 1.1 christos
489 1.1 christos if (i == MaxLength && String[i])
490 1.1 christos {
491 1.1 christos AcpiOsPrintf ("...");
492 1.1 christos }
493 1.1 christos }
494 1.1 christos
495 1.1 christos
496 1.1 christos /*******************************************************************************
497 1.1 christos *
498 1.1 christos * FUNCTION: AcpiUtValidAcpiChar
499 1.1 christos *
500 1.1 christos * PARAMETERS: Char - The character to be examined
501 1.1 christos * Position - Byte position (0-3)
502 1.1 christos *
503 1.1 christos * RETURN: TRUE if the character is valid, FALSE otherwise
504 1.1 christos *
505 1.1 christos * DESCRIPTION: Check for a valid ACPI character. Must be one of:
506 1.1 christos * 1) Upper case alpha
507 1.1 christos * 2) numeric
508 1.1 christos * 3) underscore
509 1.1 christos *
510 1.1 christos * We allow a '!' as the last character because of the ASF! table
511 1.1 christos *
512 1.1 christos ******************************************************************************/
513 1.1 christos
514 1.1 christos BOOLEAN
515 1.1 christos AcpiUtValidAcpiChar (
516 1.1 christos char Character,
517 1.1 christos UINT32 Position)
518 1.1 christos {
519 1.1 christos
520 1.1 christos if (!((Character >= 'A' && Character <= 'Z') ||
521 1.1 christos (Character >= '0' && Character <= '9') ||
522 1.1 christos (Character == '_')))
523 1.1 christos {
524 1.1 christos /* Allow a '!' in the last position */
525 1.1 christos
526 1.1 christos if (Character == '!' && Position == 3)
527 1.1 christos {
528 1.1 christos return (TRUE);
529 1.1 christos }
530 1.1 christos
531 1.1 christos return (FALSE);
532 1.1 christos }
533 1.1 christos
534 1.1 christos return (TRUE);
535 1.1 christos }
536 1.1 christos
537 1.1 christos
538 1.1 christos /*******************************************************************************
539 1.1 christos *
540 1.1 christos * FUNCTION: AcpiUtValidAcpiName
541 1.1 christos *
542 1.1 christos * PARAMETERS: Name - The name to be examined. Does not have to
543 1.1 christos * be NULL terminated string.
544 1.1 christos *
545 1.1 christos * RETURN: TRUE if the name is valid, FALSE otherwise
546 1.1 christos *
547 1.1 christos * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
548 1.1 christos * 1) Upper case alpha
549 1.1 christos * 2) numeric
550 1.1 christos * 3) underscore
551 1.1 christos *
552 1.1 christos ******************************************************************************/
553 1.1 christos
554 1.1 christos BOOLEAN
555 1.1 christos AcpiUtValidAcpiName (
556 1.1 christos char *Name)
557 1.1 christos {
558 1.1 christos UINT32 i;
559 1.1 christos
560 1.1 christos
561 1.1 christos ACPI_FUNCTION_ENTRY ();
562 1.1 christos
563 1.1 christos
564 1.1 christos for (i = 0; i < ACPI_NAME_SIZE; i++)
565 1.1 christos {
566 1.1 christos if (!AcpiUtValidAcpiChar (Name[i], i))
567 1.1 christos {
568 1.1 christos return (FALSE);
569 1.1 christos }
570 1.1 christos }
571 1.1 christos
572 1.1 christos return (TRUE);
573 1.1 christos }
574 1.1 christos
575 1.1 christos
576 1.1 christos /*******************************************************************************
577 1.1 christos *
578 1.1 christos * FUNCTION: AcpiUtRepairName
579 1.1 christos *
580 1.1 christos * PARAMETERS: Name - The ACPI name to be repaired
581 1.1 christos *
582 1.1 christos * RETURN: Repaired version of the name
583 1.1 christos *
584 1.1 christos * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
585 1.1 christos * return the new name. NOTE: the Name parameter must reside in
586 1.1 christos * read/write memory, cannot be a const.
587 1.1 christos *
588 1.1 christos * An ACPI Name must consist of valid ACPI characters. We will repair the name
589 1.1 christos * if necessary because we don't want to abort because of this, but we want
590 1.1 christos * all namespace names to be printable. A warning message is appropriate.
591 1.1 christos *
592 1.1 christos * This issue came up because there are in fact machines that exhibit
593 1.1 christos * this problem, and we want to be able to enable ACPI support for them,
594 1.1 christos * even though there are a few bad names.
595 1.1 christos *
596 1.1 christos ******************************************************************************/
597 1.1 christos
598 1.1 christos void
599 1.1 christos AcpiUtRepairName (
600 1.1 christos char *Name)
601 1.1 christos {
602 1.1 christos UINT32 i;
603 1.1 christos BOOLEAN FoundBadChar = FALSE;
604 1.1 christos UINT32 OriginalName;
605 1.1 christos
606 1.1 christos
607 1.1 christos ACPI_FUNCTION_NAME (UtRepairName);
608 1.1 christos
609 1.1 christos
610 1.1 christos ACPI_MOVE_NAME (&OriginalName, Name);
611 1.1 christos
612 1.1 christos /* Check each character in the name */
613 1.1 christos
614 1.1 christos for (i = 0; i < ACPI_NAME_SIZE; i++)
615 1.1 christos {
616 1.1 christos if (AcpiUtValidAcpiChar (Name[i], i))
617 1.1 christos {
618 1.1 christos continue;
619 1.1 christos }
620 1.1 christos
621 1.1 christos /*
622 1.1 christos * Replace a bad character with something printable, yet technically
623 1.1 christos * still invalid. This prevents any collisions with existing "good"
624 1.1 christos * names in the namespace.
625 1.1 christos */
626 1.1 christos Name[i] = '*';
627 1.1 christos FoundBadChar = TRUE;
628 1.1 christos }
629 1.1 christos
630 1.1 christos if (FoundBadChar)
631 1.1 christos {
632 1.1 christos /* Report warning only if in strict mode or debug mode */
633 1.1 christos
634 1.1 christos if (!AcpiGbl_EnableInterpreterSlack)
635 1.1 christos {
636 1.1 christos ACPI_WARNING ((AE_INFO,
637 1.1 christos "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
638 1.1 christos OriginalName, Name));
639 1.1 christos }
640 1.1 christos else
641 1.1 christos {
642 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
643 1.1 christos "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
644 1.1 christos OriginalName, Name));
645 1.1 christos }
646 1.1 christos }
647 1.1 christos }
648 1.1 christos
649 1.1 christos
650 1.1 christos #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
651 1.1 christos /*******************************************************************************
652 1.1 christos *
653 1.1 christos * FUNCTION: UtConvertBackslashes
654 1.1 christos *
655 1.1 christos * PARAMETERS: Pathname - File pathname string to be converted
656 1.1 christos *
657 1.1 christos * RETURN: Modifies the input Pathname
658 1.1 christos *
659 1.1 christos * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
660 1.1 christos * the entire input file pathname string.
661 1.1 christos *
662 1.1 christos ******************************************************************************/
663 1.1 christos
664 1.1 christos void
665 1.1 christos UtConvertBackslashes (
666 1.1 christos char *Pathname)
667 1.1 christos {
668 1.1 christos
669 1.1 christos if (!Pathname)
670 1.1 christos {
671 1.1 christos return;
672 1.1 christos }
673 1.1 christos
674 1.1 christos while (*Pathname)
675 1.1 christos {
676 1.1 christos if (*Pathname == '\\')
677 1.1 christos {
678 1.1 christos *Pathname = '/';
679 1.1 christos }
680 1.1 christos
681 1.1 christos Pathname++;
682 1.1 christos }
683 1.1 christos }
684 1.1 christos #endif
685 1.1 christos
686 1.1 christos #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
687 1.1 christos /*******************************************************************************
688 1.1 christos *
689 1.1 christos * FUNCTION: AcpiUtSafeStrcpy, AcpiUtSafeStrcat, AcpiUtSafeStrncat
690 1.1 christos *
691 1.1 christos * PARAMETERS: Adds a "DestSize" parameter to each of the standard string
692 1.1 christos * functions. This is the size of the Destination buffer.
693 1.1 christos *
694 1.1 christos * RETURN: TRUE if the operation would overflow the destination buffer.
695 1.1 christos *
696 1.1 christos * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that
697 1.1 christos * the result of the operation will not overflow the output string
698 1.1 christos * buffer.
699 1.1 christos *
700 1.1 christos * NOTE: These functions are typically only helpful for processing
701 1.1 christos * user input and command lines. For most ACPICA code, the
702 1.1 christos * required buffer length is precisely calculated before buffer
703 1.1 christos * allocation, so the use of these functions is unnecessary.
704 1.1 christos *
705 1.1 christos ******************************************************************************/
706 1.1 christos
707 1.1 christos BOOLEAN
708 1.1 christos AcpiUtSafeStrcpy (
709 1.1 christos char *Dest,
710 1.1 christos ACPI_SIZE DestSize,
711 1.1 christos char *Source)
712 1.1 christos {
713 1.1 christos
714 1.1 christos if (ACPI_STRLEN (Source) >= DestSize)
715 1.1 christos {
716 1.1 christos return (TRUE);
717 1.1 christos }
718 1.1 christos
719 1.1 christos ACPI_STRCPY (Dest, Source);
720 1.1 christos return (FALSE);
721 1.1 christos }
722 1.1 christos
723 1.1 christos BOOLEAN
724 1.1 christos AcpiUtSafeStrcat (
725 1.1 christos char *Dest,
726 1.1 christos ACPI_SIZE DestSize,
727 1.1 christos char *Source)
728 1.1 christos {
729 1.1 christos
730 1.1 christos if ((ACPI_STRLEN (Dest) + ACPI_STRLEN (Source)) >= DestSize)
731 1.1 christos {
732 1.1 christos return (TRUE);
733 1.1 christos }
734 1.1 christos
735 1.1 christos ACPI_STRCAT (Dest, Source);
736 1.1 christos return (FALSE);
737 1.1 christos }
738 1.1 christos
739 1.1 christos BOOLEAN
740 1.1 christos AcpiUtSafeStrncat (
741 1.1 christos char *Dest,
742 1.1 christos ACPI_SIZE DestSize,
743 1.1 christos char *Source,
744 1.1 christos ACPI_SIZE MaxTransferLength)
745 1.1 christos {
746 1.1 christos ACPI_SIZE ActualTransferLength;
747 1.1 christos
748 1.1 christos
749 1.1 christos ActualTransferLength = ACPI_MIN (MaxTransferLength, ACPI_STRLEN (Source));
750 1.1 christos
751 1.1 christos if ((ACPI_STRLEN (Dest) + ActualTransferLength) >= DestSize)
752 1.1 christos {
753 1.1 christos return (TRUE);
754 1.1 christos }
755 1.1 christos
756 1.1 christos ACPI_STRNCAT (Dest, Source, MaxTransferLength);
757 1.1 christos return (FALSE);
758 1.1 christos }
759 1.1 christos #endif
760