utstring.c revision 281075
1219974Smav/*******************************************************************************
2219974Smav *
3219974Smav * Module Name: utstring - Common functions for strings and characters
4219974Smav *
5219974Smav ******************************************************************************/
6219974Smav
7219974Smav/*
8219974Smav * Copyright (C) 2000 - 2015, Intel Corp.
9219974Smav * All rights reserved.
10219974Smav *
11219974Smav * Redistribution and use in source and binary forms, with or without
12219974Smav * modification, are permitted provided that the following conditions
13219974Smav * are met:
14219974Smav * 1. Redistributions of source code must retain the above copyright
15219974Smav *    notice, this list of conditions, and the following disclaimer,
16219974Smav *    without modification.
17219974Smav * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18219974Smav *    substantially similar to the "NO WARRANTY" disclaimer below
19219974Smav *    ("Disclaimer") and any redistribution must be conditioned upon
20219974Smav *    including a substantially similar Disclaimer requirement for further
21219974Smav *    binary redistribution.
22219974Smav * 3. Neither the names of the above-listed copyright holders nor the names
23219974Smav *    of any contributors may be used to endorse or promote products derived
24219974Smav *    from this software without specific prior written permission.
25219974Smav *
26219974Smav * Alternatively, this software may be distributed under the terms of the
27219974Smav * GNU General Public License ("GPL") version 2 as published by the Free
28219974Smav * Software Foundation.
29219974Smav *
30219974Smav * NO WARRANTY
31219974Smav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32219974Smav * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33219974Smav * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34219974Smav * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35219974Smav * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36219974Smav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37219974Smav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38219974Smav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39219974Smav * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40219974Smav * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41219974Smav * POSSIBILITY OF SUCH DAMAGES.
42219974Smav */
43219974Smav
44219974Smav#include <contrib/dev/acpica/include/acpi.h>
45219974Smav#include <contrib/dev/acpica/include/accommon.h>
46219974Smav#include <contrib/dev/acpica/include/acnamesp.h>
47219974Smav
48219974Smav
49219974Smav#define _COMPONENT          ACPI_UTILITIES
50219974Smav        ACPI_MODULE_NAME    ("utstring")
51219974Smav
52219974Smav
53219974Smav/*
54219974Smav * Non-ANSI C library functions - strlwr, strupr, stricmp, and a 64-bit
55219974Smav * version of strtoul.
56219974Smav */
57219974Smav
58219974Smav#ifdef ACPI_ASL_COMPILER
59219974Smav/*******************************************************************************
60219974Smav *
61219974Smav * FUNCTION:    AcpiUtStrlwr (strlwr)
62219974Smav *
63219974Smav * PARAMETERS:  SrcString       - The source string to convert
64219974Smav *
65219974Smav * RETURN:      None
66219974Smav *
67219974Smav * DESCRIPTION: Convert string to lowercase
68219974Smav *
69219974Smav * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
70219974Smav *
71219974Smav ******************************************************************************/
72219974Smav
73219974Smavvoid
74219974SmavAcpiUtStrlwr (
75219974Smav    char                    *SrcString)
76219974Smav{
77219974Smav    char                    *String;
78219974Smav
79219974Smav
80219974Smav    ACPI_FUNCTION_ENTRY ();
81219974Smav
82219974Smav
83219974Smav    if (!SrcString)
84219974Smav    {
85219974Smav        return;
86219974Smav    }
87219974Smav
88219974Smav    /* Walk entire string, lowercasing the letters */
89219974Smav
90219974Smav    for (String = SrcString; *String; String++)
91219974Smav    {
92219974Smav        *String = (char) ACPI_TOLOWER (*String);
93219974Smav    }
94219974Smav
95219974Smav    return;
96219974Smav}
97219974Smav
98219974Smav
99219974Smav/******************************************************************************
100219974Smav *
101219974Smav * FUNCTION:    AcpiUtStricmp (stricmp)
102219974Smav *
103219974Smav * PARAMETERS:  String1             - first string to compare
104219974Smav *              String2             - second string to compare
105219974Smav *
106219974Smav * RETURN:      int that signifies string relationship. Zero means strings
107219974Smav *              are equal.
108219974Smav *
109219974Smav * DESCRIPTION: Implementation of the non-ANSI stricmp function (compare
110219974Smav *              strings with no case sensitivity)
111219974Smav *
112219974Smav ******************************************************************************/
113219974Smav
114219974Smavint
115219974SmavAcpiUtStricmp (
116219974Smav    char                    *String1,
117219974Smav    char                    *String2)
118219974Smav{
119219974Smav    int                     c1;
120219974Smav    int                     c2;
121219974Smav
122219974Smav
123219974Smav    do
124219974Smav    {
125219974Smav        c1 = tolower ((int) *String1);
126219974Smav        c2 = tolower ((int) *String2);
127219974Smav
128219974Smav        String1++;
129219974Smav        String2++;
130219974Smav    }
131219974Smav    while ((c1 == c2) && (c1));
132219974Smav
133219974Smav    return (c1 - c2);
134219974Smav}
135219974Smav#endif
136219974Smav
137219974Smav
138219974Smav/*******************************************************************************
139219974Smav *
140219974Smav * FUNCTION:    AcpiUtStrupr (strupr)
141219974Smav *
142219974Smav * PARAMETERS:  SrcString       - The source string to convert
143219974Smav *
144219974Smav * RETURN:      None
145219974Smav *
146219974Smav * DESCRIPTION: Convert string to uppercase
147219974Smav *
148219974Smav * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
149219974Smav *
150219974Smav ******************************************************************************/
151219974Smav
152219974Smavvoid
153219974SmavAcpiUtStrupr (
154219974Smav    char                    *SrcString)
155219974Smav{
156219974Smav    char                    *String;
157219974Smav
158219974Smav
159219974Smav    ACPI_FUNCTION_ENTRY ();
160219974Smav
161219974Smav
162219974Smav    if (!SrcString)
163219974Smav    {
164219974Smav        return;
165219974Smav    }
166219974Smav
167219974Smav    /* Walk entire string, uppercasing the letters */
168219974Smav
169219974Smav    for (String = SrcString; *String; String++)
170219974Smav    {
171219974Smav        *String = (char) ACPI_TOUPPER (*String);
172219974Smav    }
173219974Smav
174219974Smav    return;
175219974Smav}
176219974Smav
177219974Smav
178219974Smav/*******************************************************************************
179219974Smav *
180219974Smav * FUNCTION:    AcpiUtStrtoul64
181219974Smav *
182219974Smav * PARAMETERS:  String          - Null terminated string
183219974Smav *              Base            - Radix of the string: 16 or ACPI_ANY_BASE;
184219974Smav *                                ACPI_ANY_BASE means 'in behalf of ToInteger'
185219974Smav *              RetInteger      - Where the converted integer is returned
186219974Smav *
187219974Smav * RETURN:      Status and Converted value
188219974Smav *
189219974Smav * DESCRIPTION: Convert a string into an unsigned value. Performs either a
190219974Smav *              32-bit or 64-bit conversion, depending on the current mode
191219974Smav *              of the interpreter.
192219974Smav *              NOTE: Does not support Octal strings, not needed.
193219974Smav *
194219974Smav ******************************************************************************/
195219974Smav
196219974SmavACPI_STATUS
197219974SmavAcpiUtStrtoul64 (
198219974Smav    char                    *String,
199219974Smav    UINT32                  Base,
200219974Smav    UINT64                  *RetInteger)
201219974Smav{
202219974Smav    UINT32                  ThisDigit = 0;
203219974Smav    UINT64                  ReturnValue = 0;
204219974Smav    UINT64                  Quotient;
205219974Smav    UINT64                  Dividend;
206219974Smav    UINT32                  ToIntegerOp = (Base == ACPI_ANY_BASE);
207219974Smav    UINT32                  Mode32 = (AcpiGbl_IntegerByteWidth == 4);
208219974Smav    UINT8                   ValidDigits = 0;
209219974Smav    UINT8                   SignOf0x = 0;
210219974Smav    UINT8                   Term = 0;
211219974Smav
212219974Smav
213219974Smav    ACPI_FUNCTION_TRACE_STR (UtStroul64, String);
214219974Smav
215219974Smav
216219974Smav    switch (Base)
217219974Smav    {
218219974Smav    case ACPI_ANY_BASE:
219219974Smav    case 16:
220219974Smav
221219974Smav        break;
222219974Smav
223219974Smav    default:
224219974Smav
225219974Smav        /* Invalid Base */
226219974Smav
227219974Smav        return_ACPI_STATUS (AE_BAD_PARAMETER);
228219974Smav    }
229219974Smav
230219974Smav    if (!String)
231219974Smav    {
232219974Smav        goto ErrorExit;
233219974Smav    }
234219974Smav
235219974Smav    /* Skip over any white space in the buffer */
236219974Smav
237219974Smav    while ((*String) && (ACPI_IS_SPACE (*String) || *String == '\t'))
238219974Smav    {
239219974Smav        String++;
240219974Smav    }
241219974Smav
242219974Smav    if (ToIntegerOp)
243219974Smav    {
244219974Smav        /*
245219974Smav         * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
246219974Smav         * We need to determine if it is decimal or hexadecimal.
247219974Smav         */
248219974Smav        if ((*String == '0') && (ACPI_TOLOWER (*(String + 1)) == 'x'))
249219974Smav        {
250219974Smav            SignOf0x = 1;
251219974Smav            Base = 16;
252219974Smav
253219974Smav            /* Skip over the leading '0x' */
254219974Smav            String += 2;
255219974Smav        }
256219974Smav        else
257219974Smav        {
258219974Smav            Base = 10;
259219974Smav        }
260219974Smav    }
261219974Smav
262219974Smav    /* Any string left? Check that '0x' is not followed by white space. */
263219974Smav
264219974Smav    if (!(*String) || ACPI_IS_SPACE (*String) || *String == '\t')
265219974Smav    {
266219974Smav        if (ToIntegerOp)
267219974Smav        {
268219974Smav            goto ErrorExit;
269219974Smav        }
270219974Smav        else
271219974Smav        {
272219974Smav            goto AllDone;
273219974Smav        }
274219974Smav    }
275219974Smav
276219974Smav    /*
277219974Smav     * Perform a 32-bit or 64-bit conversion, depending upon the current
278219974Smav     * execution mode of the interpreter
279219974Smav     */
280219974Smav    Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
281219974Smav
282219974Smav    /* Main loop: convert the string to a 32- or 64-bit integer */
283219974Smav
284219974Smav    while (*String)
285219974Smav    {
286219974Smav        if (ACPI_IS_DIGIT (*String))
287219974Smav        {
288219974Smav            /* Convert ASCII 0-9 to Decimal value */
289219974Smav
290219974Smav            ThisDigit = ((UINT8) *String) - '0';
291219974Smav        }
292219974Smav        else if (Base == 10)
293219974Smav        {
294219974Smav            /* Digit is out of range; possible in ToInteger case only */
295219974Smav
296219974Smav            Term = 1;
297219974Smav        }
298219974Smav        else
299219974Smav        {
300219974Smav            ThisDigit = (UINT8) ACPI_TOUPPER (*String);
301219974Smav            if (ACPI_IS_XDIGIT ((char) ThisDigit))
302219974Smav            {
303219974Smav                /* Convert ASCII Hex char to value */
304219974Smav
305219974Smav                ThisDigit = ThisDigit - 'A' + 10;
306219974Smav            }
307219974Smav            else
308219974Smav            {
309219974Smav                Term = 1;
310219974Smav            }
311219974Smav        }
312219974Smav
313219974Smav        if (Term)
314219974Smav        {
315219974Smav            if (ToIntegerOp)
316219974Smav            {
317219974Smav                goto ErrorExit;
318219974Smav            }
319219974Smav            else
320219974Smav            {
321219974Smav                break;
322219974Smav            }
323219974Smav        }
324219974Smav        else if ((ValidDigits == 0) && (ThisDigit == 0) && !SignOf0x)
325219974Smav        {
326219974Smav            /* Skip zeros */
327219974Smav            String++;
328219974Smav            continue;
329219974Smav        }
330219974Smav
331219974Smav        ValidDigits++;
332219974Smav
333219974Smav        if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32)))
334219974Smav        {
335219974Smav            /*
336219974Smav             * This is ToInteger operation case.
337219974Smav             * No any restrictions for string-to-integer conversion,
338219974Smav             * see ACPI spec.
339219974Smav             */
340219974Smav            goto ErrorExit;
341219974Smav        }
342219974Smav
343219974Smav        /* Divide the digit into the correct position */
344219974Smav
345219974Smav        (void) AcpiUtShortDivide ((Dividend - (UINT64) ThisDigit),
346219974Smav                    Base, &Quotient, NULL);
347219974Smav
348219974Smav        if (ReturnValue > Quotient)
349219974Smav        {
350219974Smav            if (ToIntegerOp)
351219974Smav            {
352219974Smav                goto ErrorExit;
353219974Smav            }
354219974Smav            else
355219974Smav            {
356219974Smav                break;
357219974Smav            }
358219974Smav        }
359219974Smav
360219974Smav        ReturnValue *= Base;
361219974Smav        ReturnValue += ThisDigit;
362219974Smav        String++;
363219974Smav    }
364219974Smav
365219974Smav    /* All done, normal exit */
366219974Smav
367219974SmavAllDone:
368219974Smav
369219974Smav    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
370219974Smav        ACPI_FORMAT_UINT64 (ReturnValue)));
371219974Smav
372219974Smav    *RetInteger = ReturnValue;
373219974Smav    return_ACPI_STATUS (AE_OK);
374219974Smav
375219974Smav
376219974SmavErrorExit:
377219974Smav    /* Base was set/validated above */
378219974Smav
379219974Smav    if (Base == 10)
380219974Smav    {
381219974Smav        return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
382219974Smav    }
383219974Smav    else
384219974Smav    {
385219974Smav        return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
386219974Smav    }
387219974Smav}
388219974Smav
389219974Smav
390219974Smav/*******************************************************************************
391219974Smav *
392219974Smav * FUNCTION:    AcpiUtPrintString
393219974Smav *
394219974Smav * PARAMETERS:  String          - Null terminated ASCII string
395219974Smav *              MaxLength       - Maximum output length. Used to constrain the
396219974Smav *                                length of strings during debug output only.
397219974Smav *
398219974Smav * RETURN:      None
399219974Smav *
400219974Smav * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
401219974Smav *              sequences.
402219974Smav *
403219974Smav ******************************************************************************/
404219974Smav
405219974Smavvoid
406219974SmavAcpiUtPrintString (
407219974Smav    char                    *String,
408219974Smav    UINT16                  MaxLength)
409219974Smav{
410219974Smav    UINT32                  i;
411219974Smav
412219974Smav
413219974Smav    if (!String)
414219974Smav    {
415219974Smav        AcpiOsPrintf ("<\"NULL STRING PTR\">");
416219974Smav        return;
417219974Smav    }
418219974Smav
419219974Smav    AcpiOsPrintf ("\"");
420219974Smav    for (i = 0; (i < MaxLength) && String[i]; i++)
421219974Smav    {
422219974Smav        /* Escape sequences */
423219974Smav
424219974Smav        switch (String[i])
425219974Smav        {
426219974Smav        case 0x07:
427219974Smav
428219974Smav            AcpiOsPrintf ("\\a");       /* BELL */
429219974Smav            break;
430219974Smav
431219974Smav        case 0x08:
432219974Smav
433219974Smav            AcpiOsPrintf ("\\b");       /* BACKSPACE */
434219974Smav            break;
435219974Smav
436219974Smav        case 0x0C:
437219974Smav
438219974Smav            AcpiOsPrintf ("\\f");       /* FORMFEED */
439219974Smav            break;
440219974Smav
441219974Smav        case 0x0A:
442219974Smav
443219974Smav            AcpiOsPrintf ("\\n");       /* LINEFEED */
444219974Smav            break;
445219974Smav
446219974Smav        case 0x0D:
447219974Smav
448219974Smav            AcpiOsPrintf ("\\r");       /* CARRIAGE RETURN*/
449219974Smav            break;
450219974Smav
451219974Smav        case 0x09:
452219974Smav
453219974Smav            AcpiOsPrintf ("\\t");       /* HORIZONTAL TAB */
454219974Smav            break;
455219974Smav
456219974Smav        case 0x0B:
457219974Smav
458219974Smav            AcpiOsPrintf ("\\v");       /* VERTICAL TAB */
459219974Smav            break;
460219974Smav
461219974Smav        case '\'':                      /* Single Quote */
462219974Smav        case '\"':                      /* Double Quote */
463219974Smav        case '\\':                      /* Backslash */
464219974Smav
465219974Smav            AcpiOsPrintf ("\\%c", (int) String[i]);
466219974Smav            break;
467219974Smav
468219974Smav        default:
469219974Smav
470219974Smav            /* Check for printable character or hex escape */
471219974Smav
472219974Smav            if (ACPI_IS_PRINT (String[i]))
473219974Smav            {
474219974Smav                /* This is a normal character */
475219974Smav
476219974Smav                AcpiOsPrintf ("%c", (int) String[i]);
477219974Smav            }
478219974Smav            else
479219974Smav            {
480219974Smav                /* All others will be Hex escapes */
481219974Smav
482219974Smav                AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
483219974Smav            }
484219974Smav            break;
485219974Smav        }
486219974Smav    }
487219974Smav    AcpiOsPrintf ("\"");
488219974Smav
489219974Smav    if (i == MaxLength && String[i])
490219974Smav    {
491219974Smav        AcpiOsPrintf ("...");
492219974Smav    }
493219974Smav}
494219974Smav
495219974Smav
496219974Smav/*******************************************************************************
497219974Smav *
498219974Smav * FUNCTION:    AcpiUtValidAcpiChar
499219974Smav *
500219974Smav * PARAMETERS:  Char            - The character to be examined
501219974Smav *              Position        - Byte position (0-3)
502219974Smav *
503219974Smav * RETURN:      TRUE if the character is valid, FALSE otherwise
504219974Smav *
505219974Smav * DESCRIPTION: Check for a valid ACPI character. Must be one of:
506219974Smav *              1) Upper case alpha
507219974Smav *              2) numeric
508219974Smav *              3) underscore
509219974Smav *
510219974Smav *              We allow a '!' as the last character because of the ASF! table
511219974Smav *
512219974Smav ******************************************************************************/
513219974Smav
514219974SmavBOOLEAN
515219974SmavAcpiUtValidAcpiChar (
516219974Smav    char                    Character,
517219974Smav    UINT32                  Position)
518219974Smav{
519219974Smav
520219974Smav    if (!((Character >= 'A' && Character <= 'Z') ||
521219974Smav          (Character >= '0' && Character <= '9') ||
522219974Smav          (Character == '_')))
523219974Smav    {
524219974Smav        /* Allow a '!' in the last position */
525219974Smav
526219974Smav        if (Character == '!' && Position == 3)
527219974Smav        {
528219974Smav            return (TRUE);
529219974Smav        }
530219974Smav
531219974Smav        return (FALSE);
532219974Smav    }
533219974Smav
534219974Smav    return (TRUE);
535219974Smav}
536219974Smav
537219974Smav
538219974Smav/*******************************************************************************
539219974Smav *
540219974Smav * FUNCTION:    AcpiUtValidAcpiName
541219974Smav *
542219974Smav * PARAMETERS:  Name            - The name to be examined. Does not have to
543219974Smav *                                be NULL terminated string.
544220209Smav *
545219974Smav * RETURN:      TRUE if the name is valid, FALSE otherwise
546220209Smav *
547219974Smav * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
548219974Smav *              1) Upper case alpha
549219974Smav *              2) numeric
550219974Smav *              3) underscore
551219974Smav *
552219974Smav ******************************************************************************/
553219974Smav
554219974SmavBOOLEAN
555219974SmavAcpiUtValidAcpiName (
556219974Smav    char                    *Name)
557219974Smav{
558219974Smav    UINT32                  i;
559219974Smav
560219974Smav
561219974Smav    ACPI_FUNCTION_ENTRY ();
562219974Smav
563219974Smav
564219974Smav    for (i = 0; i < ACPI_NAME_SIZE; i++)
565219974Smav    {
566219974Smav        if (!AcpiUtValidAcpiChar (Name[i], i))
567219974Smav        {
568219974Smav            return (FALSE);
569219974Smav        }
570219974Smav    }
571219974Smav
572219974Smav    return (TRUE);
573219974Smav}
574219974Smav
575219974Smav
576219974Smav/*******************************************************************************
577219974Smav *
578219974Smav * FUNCTION:    AcpiUtRepairName
579219974Smav *
580219974Smav * PARAMETERS:  Name            - The ACPI name to be repaired
581219974Smav *
582219974Smav * RETURN:      Repaired version of the name
583219974Smav *
584219974Smav * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
585219974Smav *              return the new name. NOTE: the Name parameter must reside in
586219974Smav *              read/write memory, cannot be a const.
587219974Smav *
588219974Smav * An ACPI Name must consist of valid ACPI characters. We will repair the name
589219974Smav * if necessary because we don't want to abort because of this, but we want
590219974Smav * all namespace names to be printable. A warning message is appropriate.
591219974Smav *
592219974Smav * This issue came up because there are in fact machines that exhibit
593219974Smav * this problem, and we want to be able to enable ACPI support for them,
594219974Smav * even though there are a few bad names.
595219974Smav *
596219974Smav ******************************************************************************/
597219974Smav
598219974Smavvoid
599219974SmavAcpiUtRepairName (
600219974Smav    char                    *Name)
601219974Smav{
602219974Smav    UINT32                  i;
603219974Smav    BOOLEAN                 FoundBadChar = FALSE;
604219974Smav    UINT32                  OriginalName;
605219974Smav
606219974Smav
607219974Smav    ACPI_FUNCTION_NAME (UtRepairName);
608219974Smav
609219974Smav
610219974Smav    ACPI_MOVE_NAME (&OriginalName, Name);
611219974Smav
612219974Smav    /* Check each character in the name */
613219974Smav
614219974Smav    for (i = 0; i < ACPI_NAME_SIZE; i++)
615219974Smav    {
616219974Smav        if (AcpiUtValidAcpiChar (Name[i], i))
617219974Smav        {
618219974Smav            continue;
619219974Smav        }
620219974Smav
621219974Smav        /*
622219974Smav         * Replace a bad character with something printable, yet technically
623219974Smav         * still invalid. This prevents any collisions with existing "good"
624219974Smav         * names in the namespace.
625219974Smav         */
626219974Smav        Name[i] = '*';
627219974Smav        FoundBadChar = TRUE;
628219974Smav    }
629219974Smav
630219974Smav    if (FoundBadChar)
631219974Smav    {
632219974Smav        /* Report warning only if in strict mode or debug mode */
633219974Smav
634219974Smav        if (!AcpiGbl_EnableInterpreterSlack)
635219974Smav        {
636219974Smav            ACPI_WARNING ((AE_INFO,
637219974Smav                "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
638219974Smav                OriginalName, Name));
639219974Smav        }
640219974Smav        else
641219974Smav        {
642219974Smav            ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
643219974Smav                "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
644219974Smav                OriginalName, Name));
645219974Smav        }
646219974Smav    }
647219974Smav}
648219974Smav
649219974Smav
650219974Smav#if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
651219974Smav/*******************************************************************************
652219974Smav *
653219974Smav * FUNCTION:    UtConvertBackslashes
654219974Smav *
655219974Smav * PARAMETERS:  Pathname        - File pathname string to be converted
656219974Smav *
657219974Smav * RETURN:      Modifies the input Pathname
658219974Smav *
659219974Smav * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
660219974Smav *              the entire input file pathname string.
661219974Smav *
662219974Smav ******************************************************************************/
663219974Smav
664219974Smavvoid
665219974SmavUtConvertBackslashes (
666219974Smav    char                    *Pathname)
667219974Smav{
668219974Smav
669219974Smav    if (!Pathname)
670219974Smav    {
671219974Smav        return;
672219974Smav    }
673219974Smav
674219974Smav    while (*Pathname)
675219974Smav    {
676219974Smav        if (*Pathname == '\\')
677219974Smav        {
678219974Smav            *Pathname = '/';
679219974Smav        }
680219974Smav
681219974Smav        Pathname++;
682219974Smav    }
683219974Smav}
684219974Smav#endif
685219974Smav
686219974Smav#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
687219974Smav/*******************************************************************************
688219974Smav *
689219974Smav * FUNCTION:    AcpiUtSafeStrcpy, AcpiUtSafeStrcat, AcpiUtSafeStrncat
690219974Smav *
691219974Smav * PARAMETERS:  Adds a "DestSize" parameter to each of the standard string
692219974Smav *              functions. This is the size of the Destination buffer.
693219974Smav *
694219974Smav * RETURN:      TRUE if the operation would overflow the destination buffer.
695219974Smav *
696219974Smav * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that
697219974Smav *              the result of the operation will not overflow the output string
698219974Smav *              buffer.
699219974Smav *
700219974Smav * NOTE:        These functions are typically only helpful for processing
701219974Smav *              user input and command lines. For most ACPICA code, the
702219974Smav *              required buffer length is precisely calculated before buffer
703219974Smav *              allocation, so the use of these functions is unnecessary.
704219974Smav *
705219974Smav ******************************************************************************/
706219974Smav
707219974SmavBOOLEAN
708219974SmavAcpiUtSafeStrcpy (
709219974Smav    char                    *Dest,
710219974Smav    ACPI_SIZE               DestSize,
711219974Smav    char                    *Source)
712219974Smav{
713219974Smav
714219974Smav    if (ACPI_STRLEN (Source) >= DestSize)
715219974Smav    {
716219974Smav        return (TRUE);
717219974Smav    }
718219974Smav
719219974Smav    ACPI_STRCPY (Dest, Source);
720219974Smav    return (FALSE);
721219974Smav}
722219974Smav
723219974SmavBOOLEAN
724219974SmavAcpiUtSafeStrcat (
725219974Smav    char                    *Dest,
726219974Smav    ACPI_SIZE               DestSize,
727219974Smav    char                    *Source)
728219974Smav{
729219974Smav
730219974Smav    if ((ACPI_STRLEN (Dest) + ACPI_STRLEN (Source)) >= DestSize)
731219974Smav    {
732219974Smav        return (TRUE);
733219974Smav    }
734219974Smav
735219974Smav    ACPI_STRCAT (Dest, Source);
736219974Smav    return (FALSE);
737219974Smav}
738219974Smav
739219974Smav#ifndef _KERNEL
740219974SmavBOOLEAN
741219974SmavAcpiUtSafeStrncat (
742219974Smav    char                    *Dest,
743219974Smav    ACPI_SIZE               DestSize,
744219974Smav    char                    *Source,
745219974Smav    ACPI_SIZE               MaxTransferLength)
746219974Smav{
747219974Smav    ACPI_SIZE               ActualTransferLength;
748219974Smav
749219974Smav
750219974Smav    ActualTransferLength = ACPI_MIN (MaxTransferLength, ACPI_STRLEN (Source));
751219974Smav
752219974Smav    if ((ACPI_STRLEN (Dest) + ActualTransferLength) >= DestSize)
753219974Smav    {
754219974Smav        return (TRUE);
755219974Smav    }
756219974Smav
757219974Smav    ACPI_STRNCAT (Dest, Source, MaxTransferLength);
758219974Smav    return (FALSE);
759219974Smav}
760219974Smav#endif
761219974Smav
762219974Smav#endif
763219974Smav