1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: utstring - Common functions for strings and characters
6 ******************************************************************************/
12 #define _COMPONENT ACPI_UTILITIES
13 ACPI_MODULE_NAME("utstring")
15 /*******************************************************************************
17 * FUNCTION: acpi_ut_print_string
19 * PARAMETERS: string - Null terminated ASCII string
20 * max_length - Maximum output length. Used to constrain the
21 * length of strings during debug output only.
25 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
28 ******************************************************************************/
29 void acpi_ut_print_string(char *string
, u16 max_length
)
34 acpi_os_printf("<\"NULL STRING PTR\">");
39 for (i
= 0; (i
< max_length
) && string
[i
]; i
++) {
41 /* Escape sequences */
46 acpi_os_printf("\\a"); /* BELL */
51 acpi_os_printf("\\b"); /* BACKSPACE */
56 acpi_os_printf("\\f"); /* FORMFEED */
61 acpi_os_printf("\\n"); /* LINEFEED */
66 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
71 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
76 acpi_os_printf("\\v"); /* VERTICAL TAB */
79 case '\'': /* Single Quote */
80 case '\"': /* Double Quote */
81 case '\\': /* Backslash */
83 acpi_os_printf("\\%c", (int)string
[i
]);
88 /* Check for printable character or hex escape */
90 if (isprint((int)string
[i
])) {
91 /* This is a normal character */
93 acpi_os_printf("%c", (int)string
[i
]);
95 /* All others will be Hex escapes */
97 acpi_os_printf("\\x%2.2X", (s32
)string
[i
]);
103 acpi_os_printf("\"");
105 if (i
== max_length
&& string
[i
]) {
106 acpi_os_printf("...");
110 /*******************************************************************************
112 * FUNCTION: acpi_ut_repair_name
114 * PARAMETERS: name - The ACPI name to be repaired
116 * RETURN: Repaired version of the name
118 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
119 * return the new name. NOTE: the Name parameter must reside in
120 * read/write memory, cannot be a const.
122 * An ACPI Name must consist of valid ACPI characters. We will repair the name
123 * if necessary because we don't want to abort because of this, but we want
124 * all namespace names to be printable. A warning message is appropriate.
126 * This issue came up because there are in fact machines that exhibit
127 * this problem, and we want to be able to enable ACPI support for them,
128 * even though there are a few bad names.
130 ******************************************************************************/
132 void acpi_ut_repair_name(char *name
)
135 u8 found_bad_char
= FALSE
;
138 ACPI_FUNCTION_NAME(ut_repair_name
);
141 * Special case for the root node. This can happen if we get an
142 * error during the execution of module-level code.
144 if (ACPI_COMPARE_NAMESEG(name
, ACPI_ROOT_PATHNAME
)) {
148 ACPI_COPY_NAMESEG(&original_name
, name
);
150 /* Check each character in the name */
152 for (i
= 0; i
< ACPI_NAMESEG_SIZE
; i
++) {
153 if (acpi_ut_valid_name_char(name
[i
], i
)) {
158 * Replace a bad character with something printable, yet technically
159 * still invalid. This prevents any collisions with existing "good"
160 * names in the namespace.
163 found_bad_char
= TRUE
;
166 if (found_bad_char
) {
168 /* Report warning only if in strict mode or debug mode */
170 if (!acpi_gbl_enable_interpreter_slack
) {
171 ACPI_WARNING((AE_INFO
,
172 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
173 original_name
, name
));
175 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
176 "Invalid character(s) in name (0x%.8X), repaired: [%4.4s]",
177 original_name
, name
));
182 #if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
183 /*******************************************************************************
185 * FUNCTION: ut_convert_backslashes
187 * PARAMETERS: pathname - File pathname string to be converted
189 * RETURN: Modifies the input Pathname
191 * DESCRIPTION: Convert all backslashes (0x5C) to forward slashes (0x2F) within
192 * the entire input file pathname string.
194 ******************************************************************************/
196 void ut_convert_backslashes(char *pathname
)
204 if (*pathname
== '\\') {