Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / acpi / acpica / utnonansi.c
blobff0802ace19b72add24d43a2eb14b98eed920337
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: utnonansi - Non-ansi C library functions
6 ******************************************************************************/
8 #include <acpi/acpi.h>
9 #include "accommon.h"
11 #define _COMPONENT ACPI_UTILITIES
12 ACPI_MODULE_NAME("utnonansi")
15 * Non-ANSI C library functions - strlwr, strupr, stricmp, and "safe"
16 * string functions.
18 /*******************************************************************************
20 * FUNCTION: acpi_ut_strlwr (strlwr)
22 * PARAMETERS: src_string - The source string to convert
24 * RETURN: None
26 * DESCRIPTION: Convert a string to lowercase
28 ******************************************************************************/
29 void acpi_ut_strlwr(char *src_string)
31 char *string;
33 ACPI_FUNCTION_ENTRY();
35 if (!src_string) {
36 return;
39 /* Walk entire string, lowercasing the letters */
41 for (string = src_string; *string; string++) {
42 *string = (char)tolower((int)*string);
46 /*******************************************************************************
48 * FUNCTION: acpi_ut_strupr (strupr)
50 * PARAMETERS: src_string - The source string to convert
52 * RETURN: None
54 * DESCRIPTION: Convert a string to uppercase
56 ******************************************************************************/
58 void acpi_ut_strupr(char *src_string)
60 char *string;
62 ACPI_FUNCTION_ENTRY();
64 if (!src_string) {
65 return;
68 /* Walk entire string, uppercasing the letters */
70 for (string = src_string; *string; string++) {
71 *string = (char)toupper((int)*string);
75 /******************************************************************************
77 * FUNCTION: acpi_ut_stricmp (stricmp)
79 * PARAMETERS: string1 - first string to compare
80 * string2 - second string to compare
82 * RETURN: int that signifies string relationship. Zero means strings
83 * are equal.
85 * DESCRIPTION: Case-insensitive string compare. Implementation of the
86 * non-ANSI stricmp function.
88 ******************************************************************************/
90 int acpi_ut_stricmp(char *string1, char *string2)
92 int c1;
93 int c2;
95 do {
96 c1 = tolower((int)*string1);
97 c2 = tolower((int)*string2);
99 string1++;
100 string2++;
102 while ((c1 == c2) && (c1));
104 return (c1 - c2);
107 #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) || defined (ACPI_DEBUG_OUTPUT)
108 /*******************************************************************************
110 * FUNCTION: acpi_ut_safe_strcpy, acpi_ut_safe_strcat, acpi_ut_safe_strncat
112 * PARAMETERS: Adds a "DestSize" parameter to each of the standard string
113 * functions. This is the size of the Destination buffer.
115 * RETURN: TRUE if the operation would overflow the destination buffer.
117 * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that
118 * the result of the operation will not overflow the output string
119 * buffer.
121 * NOTE: These functions are typically only helpful for processing
122 * user input and command lines. For most ACPICA code, the
123 * required buffer length is precisely calculated before buffer
124 * allocation, so the use of these functions is unnecessary.
126 ******************************************************************************/
128 u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source)
131 if (strlen(source) >= dest_size) {
132 return (TRUE);
135 strcpy(dest, source);
136 return (FALSE);
139 u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source)
142 if ((strlen(dest) + strlen(source)) >= dest_size) {
143 return (TRUE);
146 strcat(dest, source);
147 return (FALSE);
151 acpi_ut_safe_strncat(char *dest,
152 acpi_size dest_size,
153 char *source, acpi_size max_transfer_length)
155 acpi_size actual_transfer_length;
157 actual_transfer_length = ACPI_MIN(max_transfer_length, strlen(source));
159 if ((strlen(dest) + actual_transfer_length) >= dest_size) {
160 return (TRUE);
163 strncat(dest, source, max_transfer_length);
164 return (FALSE);
167 void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size)
169 /* Always terminate destination string */
171 strncpy(dest, source, dest_size);
172 dest[dest_size - 1] = 0;
175 #endif