Sync ACPICA with Intel's version 20160831.
[dragonfly.git] / sys / contrib / dev / acpica / source / components / utilities / utnonansi.c
blob4cddcf190b50c97f9e0b66af447ab299ba570631
1 /*******************************************************************************
3 * Module Name: utnonansi - Non-ansi C library functions
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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.
44 #include "acpi.h"
45 #include "accommon.h"
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME ("utnonansi")
52 * Non-ANSI C library functions - strlwr, strupr, stricmp, and "safe"
53 * string functions.
56 /*******************************************************************************
58 * FUNCTION: AcpiUtStrlwr (strlwr)
60 * PARAMETERS: SrcString - The source string to convert
62 * RETURN: None
64 * DESCRIPTION: Convert a string to lowercase
66 ******************************************************************************/
68 void
69 AcpiUtStrlwr (
70 char *SrcString)
72 char *String;
75 ACPI_FUNCTION_ENTRY ();
78 if (!SrcString)
80 return;
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
98 * RETURN: None
100 * DESCRIPTION: Convert a string to uppercase
102 ******************************************************************************/
104 void
105 AcpiUtStrupr (
106 char *SrcString)
108 char *String;
111 ACPI_FUNCTION_ENTRY ();
114 if (!SrcString)
116 return;
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
136 * are equal.
138 * DESCRIPTION: Case-insensitive string compare. Implementation of the
139 * non-ANSI stricmp function.
141 ******************************************************************************/
144 AcpiUtStricmp (
145 char *String1,
146 char *String2)
148 int c1;
149 int c2;
154 c1 = tolower ((int) *String1);
155 c2 = tolower ((int) *String2);
157 String1++;
158 String2++;
160 while ((c1 == c2) && (c1));
162 return (c1 - c2);
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
178 * buffer.
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 ******************************************************************************/
187 BOOLEAN
188 AcpiUtSafeStrcpy (
189 char *Dest,
190 ACPI_SIZE DestSize,
191 char *Source)
194 if (strlen (Source) >= DestSize)
196 return (TRUE);
199 strcpy (Dest, Source);
200 return (FALSE);
203 BOOLEAN
204 AcpiUtSafeStrcat (
205 char *Dest,
206 ACPI_SIZE DestSize,
207 char *Source)
210 if ((strlen (Dest) + strlen (Source)) >= DestSize)
212 return (TRUE);
215 strcat (Dest, Source);
216 return (FALSE);
219 BOOLEAN
220 AcpiUtSafeStrncat (
221 char *Dest,
222 ACPI_SIZE DestSize,
223 char *Source,
224 ACPI_SIZE MaxTransferLength)
226 ACPI_SIZE ActualTransferLength;
229 ActualTransferLength = ACPI_MIN (MaxTransferLength, strlen (Source));
231 if ((strlen (Dest) + ActualTransferLength) >= DestSize)
233 return (TRUE);
236 strncat (Dest, Source, MaxTransferLength);
237 return (FALSE);
239 #endif