1 /*******************************************************************************
3 * Module Name: utnonansi - Non-ansi C library functions
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME ("utnonansi")
52 * Non-ANSI C library functions - strlwr, strupr, stricmp, and "safe"
56 /*******************************************************************************
58 * FUNCTION: AcpiUtStrlwr (strlwr)
60 * PARAMETERS: SrcString - The source string to convert
64 * DESCRIPTION: Convert a string to lowercase
66 ******************************************************************************/
75 ACPI_FUNCTION_ENTRY ();
83 /* Walk entire string, lowercasing the letters */
85 for (String
= SrcString
; *String
; String
++)
87 *String
= (char) tolower ((int) *String
);
92 /*******************************************************************************
94 * FUNCTION: AcpiUtStrupr (strupr)
96 * PARAMETERS: SrcString - The source string to convert
100 * DESCRIPTION: Convert a string to uppercase
102 ******************************************************************************/
111 ACPI_FUNCTION_ENTRY ();
119 /* Walk entire string, uppercasing the letters */
121 for (String
= SrcString
; *String
; String
++)
123 *String
= (char) toupper ((int) *String
);
128 /******************************************************************************
130 * FUNCTION: AcpiUtStricmp (stricmp)
132 * PARAMETERS: String1 - first string to compare
133 * String2 - second string to compare
135 * RETURN: int that signifies string relationship. Zero means strings
138 * DESCRIPTION: Case-insensitive string compare. Implementation of the
139 * non-ANSI stricmp function.
141 ******************************************************************************/
154 c1
= tolower ((int) *String1
);
155 c2
= tolower ((int) *String2
);
160 while ((c1
== c2
) && (c1
));
166 #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
167 /*******************************************************************************
169 * FUNCTION: AcpiUtSafeStrcpy, AcpiUtSafeStrcat, AcpiUtSafeStrncat
171 * PARAMETERS: Adds a "DestSize" parameter to each of the standard string
172 * functions. This is the size of the Destination buffer.
174 * RETURN: TRUE if the operation would overflow the destination buffer.
176 * DESCRIPTION: Safe versions of standard Clib string functions. Ensure that
177 * the result of the operation will not overflow the output string
180 * NOTE: These functions are typically only helpful for processing
181 * user input and command lines. For most ACPICA code, the
182 * required buffer length is precisely calculated before buffer
183 * allocation, so the use of these functions is unnecessary.
185 ******************************************************************************/
194 if (strlen (Source
) >= DestSize
)
199 strcpy (Dest
, Source
);
210 if ((strlen (Dest
) + strlen (Source
)) >= DestSize
)
215 strcat (Dest
, Source
);
224 ACPI_SIZE MaxTransferLength
)
226 ACPI_SIZE ActualTransferLength
;
229 ActualTransferLength
= ACPI_MIN (MaxTransferLength
, strlen (Source
));
231 if ((strlen (Dest
) + ActualTransferLength
) >= DestSize
)
236 strncat (Dest
, Source
, MaxTransferLength
);