1599289f2SAugustin Cavalier/******************************************************************************
2599289f2SAugustin Cavalier *
3599289f2SAugustin Cavalier * Module Name: utclib - ACPICA implementations of C library functions
4599289f2SAugustin Cavalier *
5599289f2SAugustin Cavalier *****************************************************************************/
6599289f2SAugustin Cavalier
7599289f2SAugustin Cavalier/******************************************************************************
8599289f2SAugustin Cavalier *
9599289f2SAugustin Cavalier * 1. Copyright Notice
10599289f2SAugustin Cavalier *
11ff2e2f81SFredrik Holmqvist * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12599289f2SAugustin Cavalier * All rights reserved.
13599289f2SAugustin Cavalier *
14599289f2SAugustin Cavalier * 2. License
15599289f2SAugustin Cavalier *
16599289f2SAugustin Cavalier * 2.1. This is your license from Intel Corp. under its intellectual property
17599289f2SAugustin Cavalier * rights. You may have additional license terms from the party that provided
18599289f2SAugustin Cavalier * you this software, covering your right to use that party's intellectual
19599289f2SAugustin Cavalier * property rights.
20599289f2SAugustin Cavalier *
21599289f2SAugustin Cavalier * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22599289f2SAugustin Cavalier * copy of the source code appearing in this file ("Covered Code") an
23599289f2SAugustin Cavalier * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24599289f2SAugustin Cavalier * base code distributed originally by Intel ("Original Intel Code") to copy,
25599289f2SAugustin Cavalier * make derivatives, distribute, use and display any portion of the Covered
26599289f2SAugustin Cavalier * Code in any form, with the right to sublicense such rights; and
27599289f2SAugustin Cavalier *
28599289f2SAugustin Cavalier * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29599289f2SAugustin Cavalier * license (with the right to sublicense), under only those claims of Intel
30599289f2SAugustin Cavalier * patents that are infringed by the Original Intel Code, to make, use, sell,
31599289f2SAugustin Cavalier * offer to sell, and import the Covered Code and derivative works thereof
32599289f2SAugustin Cavalier * solely to the minimum extent necessary to exercise the above copyright
33599289f2SAugustin Cavalier * license, and in no event shall the patent license extend to any additions
34599289f2SAugustin Cavalier * to or modifications of the Original Intel Code. No other license or right
35599289f2SAugustin Cavalier * is granted directly or by implication, estoppel or otherwise;
36599289f2SAugustin Cavalier *
37599289f2SAugustin Cavalier * The above copyright and patent license is granted only if the following
38599289f2SAugustin Cavalier * conditions are met:
39599289f2SAugustin Cavalier *
40599289f2SAugustin Cavalier * 3. Conditions
41599289f2SAugustin Cavalier *
42599289f2SAugustin Cavalier * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43599289f2SAugustin Cavalier * Redistribution of source code of any substantial portion of the Covered
44599289f2SAugustin Cavalier * Code or modification with rights to further distribute source must include
45599289f2SAugustin Cavalier * the above Copyright Notice, the above License, this list of Conditions,
46599289f2SAugustin Cavalier * and the following Disclaimer and Export Compliance provision. In addition,
47599289f2SAugustin Cavalier * Licensee must cause all Covered Code to which Licensee contributes to
48599289f2SAugustin Cavalier * contain a file documenting the changes Licensee made to create that Covered
49599289f2SAugustin Cavalier * Code and the date of any change. Licensee must include in that file the
50599289f2SAugustin Cavalier * documentation of any changes made by any predecessor Licensee. Licensee
51599289f2SAugustin Cavalier * must include a prominent statement that the modification is derived,
52599289f2SAugustin Cavalier * directly or indirectly, from Original Intel Code.
53599289f2SAugustin Cavalier *
54599289f2SAugustin Cavalier * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55599289f2SAugustin Cavalier * Redistribution of source code of any substantial portion of the Covered
56599289f2SAugustin Cavalier * Code or modification without rights to further distribute source must
57599289f2SAugustin Cavalier * include the following Disclaimer and Export Compliance provision in the
58599289f2SAugustin Cavalier * documentation and/or other materials provided with distribution. In
59599289f2SAugustin Cavalier * addition, Licensee may not authorize further sublicense of source of any
60599289f2SAugustin Cavalier * portion of the Covered Code, and must include terms to the effect that the
61599289f2SAugustin Cavalier * license from Licensee to its licensee is limited to the intellectual
62599289f2SAugustin Cavalier * property embodied in the software Licensee provides to its licensee, and
63599289f2SAugustin Cavalier * not to intellectual property embodied in modifications its licensee may
64599289f2SAugustin Cavalier * make.
65599289f2SAugustin Cavalier *
66599289f2SAugustin Cavalier * 3.3. Redistribution of Executable. Redistribution in executable form of any
67599289f2SAugustin Cavalier * substantial portion of the Covered Code or modification must reproduce the
68599289f2SAugustin Cavalier * above Copyright Notice, and the following Disclaimer and Export Compliance
69599289f2SAugustin Cavalier * provision in the documentation and/or other materials provided with the
70599289f2SAugustin Cavalier * distribution.
71599289f2SAugustin Cavalier *
72599289f2SAugustin Cavalier * 3.4. Intel retains all right, title, and interest in and to the Original
73599289f2SAugustin Cavalier * Intel Code.
74599289f2SAugustin Cavalier *
75599289f2SAugustin Cavalier * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76599289f2SAugustin Cavalier * Intel shall be used in advertising or otherwise to promote the sale, use or
77599289f2SAugustin Cavalier * other dealings in products derived from or relating to the Covered Code
78599289f2SAugustin Cavalier * without prior written authorization from Intel.
79599289f2SAugustin Cavalier *
80599289f2SAugustin Cavalier * 4. Disclaimer and Export Compliance
81599289f2SAugustin Cavalier *
82599289f2SAugustin Cavalier * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83599289f2SAugustin Cavalier * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84599289f2SAugustin Cavalier * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85599289f2SAugustin Cavalier * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86599289f2SAugustin Cavalier * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87599289f2SAugustin Cavalier * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88599289f2SAugustin Cavalier * PARTICULAR PURPOSE.
89599289f2SAugustin Cavalier *
90599289f2SAugustin Cavalier * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91599289f2SAugustin Cavalier * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92599289f2SAugustin Cavalier * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93599289f2SAugustin Cavalier * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94599289f2SAugustin Cavalier * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95599289f2SAugustin Cavalier * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96599289f2SAugustin Cavalier * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97599289f2SAugustin Cavalier * LIMITED REMEDY.
98599289f2SAugustin Cavalier *
99599289f2SAugustin Cavalier * 4.3. Licensee shall not export, either directly or indirectly, any of this
100599289f2SAugustin Cavalier * software or system incorporating such software without first obtaining any
101599289f2SAugustin Cavalier * required license or other approval from the U. S. Department of Commerce or
102599289f2SAugustin Cavalier * any other agency or department of the United States Government. In the
103599289f2SAugustin Cavalier * event Licensee exports any such software from the United States or
104599289f2SAugustin Cavalier * re-exports any such software from a foreign destination, Licensee shall
105599289f2SAugustin Cavalier * ensure that the distribution and export/re-export of the software is in
106599289f2SAugustin Cavalier * compliance with all laws, regulations, orders, or other restrictions of the
107599289f2SAugustin Cavalier * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108599289f2SAugustin Cavalier * any of its subsidiaries will export/re-export any technical data, process,
109599289f2SAugustin Cavalier * software, or service, directly or indirectly, to any country for which the
110599289f2SAugustin Cavalier * United States government or any agency thereof requires an export license,
111599289f2SAugustin Cavalier * other governmental approval, or letter of assurance, without first obtaining
112599289f2SAugustin Cavalier * such license, approval or letter.
113599289f2SAugustin Cavalier *
114ff2e2f81SFredrik Holmqvist *****************************************************************************
115ff2e2f81SFredrik Holmqvist *
116ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist * following license:
118ff2e2f81SFredrik Holmqvist *
119ff2e2f81SFredrik Holmqvist * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist * are met:
122ff2e2f81SFredrik Holmqvist * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist *    notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist *    without modification.
125ff2e2f81SFredrik Holmqvist * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist *    substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist *    ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist *    including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist *    binary redistribution.
130ff2e2f81SFredrik Holmqvist * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist *    of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist *    from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist *
134ff2e2f81SFredrik Holmqvist * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist *
146ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist * Software Foundation.
149ff2e2f81SFredrik Holmqvist *
150599289f2SAugustin Cavalier *****************************************************************************/
151599289f2SAugustin Cavalier
152599289f2SAugustin Cavalier#define ACPI_CLIBRARY
153599289f2SAugustin Cavalier#include "acpi.h"
154599289f2SAugustin Cavalier#include "accommon.h"
155599289f2SAugustin Cavalier
156599289f2SAugustin Cavalier/*
157599289f2SAugustin Cavalier * This module contains implementations of the standard C library functions
158599289f2SAugustin Cavalier * that are required by the ACPICA code at both application level and kernel
159599289f2SAugustin Cavalier * level.
160599289f2SAugustin Cavalier *
161599289f2SAugustin Cavalier * The module is an optional feature that can be used if a local/system
162599289f2SAugustin Cavalier * C library is not available. Some operating system kernels may not have
163599289f2SAugustin Cavalier * an internal C library.
164599289f2SAugustin Cavalier *
165599289f2SAugustin Cavalier * In general, these functions are less efficient than an inline or assembly
166599289f2SAugustin Cavalier * code implementation.
167599289f2SAugustin Cavalier *
168599289f2SAugustin Cavalier * These C functions and the associated prototypes are enabled by default
169599289f2SAugustin Cavalier * unless the ACPI_USE_SYSTEM_CLIBRARY symbol is defined. This is usually
170599289f2SAugustin Cavalier * automatically defined for the ACPICA applications such as iASL and
171599289f2SAugustin Cavalier * AcpiExec, so that these user-level applications use the local C library
172599289f2SAugustin Cavalier * instead of the functions in this module.
173599289f2SAugustin Cavalier */
174599289f2SAugustin Cavalier
175599289f2SAugustin Cavalier/*******************************************************************************
176599289f2SAugustin Cavalier *
177599289f2SAugustin Cavalier * Functions implemented in this module:
178599289f2SAugustin Cavalier *
179599289f2SAugustin Cavalier * FUNCTION:    memcmp
180599289f2SAugustin Cavalier * FUNCTION:    memcpy
181599289f2SAugustin Cavalier * FUNCTION:    memset
182599289f2SAugustin Cavalier * FUNCTION:    strlen
183599289f2SAugustin Cavalier * FUNCTION:    strcpy
184599289f2SAugustin Cavalier * FUNCTION:    strncpy
185599289f2SAugustin Cavalier * FUNCTION:    strcmp
186599289f2SAugustin Cavalier * FUNCTION:    strchr
187599289f2SAugustin Cavalier * FUNCTION:    strncmp
188599289f2SAugustin Cavalier * FUNCTION:    strcat
189599289f2SAugustin Cavalier * FUNCTION:    strncat
190599289f2SAugustin Cavalier * FUNCTION:    strstr
191599289f2SAugustin Cavalier * FUNCTION:    strtoul
192599289f2SAugustin Cavalier * FUNCTION:    toupper
193599289f2SAugustin Cavalier * FUNCTION:    tolower
194599289f2SAugustin Cavalier * FUNCTION:    is* functions
195599289f2SAugustin Cavalier *
196599289f2SAugustin Cavalier ******************************************************************************/
197599289f2SAugustin Cavalier
198599289f2SAugustin Cavalier#define _COMPONENT          ACPI_UTILITIES
199599289f2SAugustin Cavalier        ACPI_MODULE_NAME    ("utclib")
200599289f2SAugustin Cavalier
201599289f2SAugustin Cavalier
202599289f2SAugustin Cavalier#ifndef ACPI_USE_SYSTEM_CLIBRARY    /* Entire module */
203599289f2SAugustin Cavalier
204599289f2SAugustin Cavalier
205599289f2SAugustin Cavalier/*******************************************************************************
206599289f2SAugustin Cavalier *
207599289f2SAugustin Cavalier * FUNCTION:    memcmp
208599289f2SAugustin Cavalier *
209599289f2SAugustin Cavalier * PARAMETERS:  Buffer1         - First Buffer
210599289f2SAugustin Cavalier *              Buffer2         - Second Buffer
211599289f2SAugustin Cavalier *              Count           - Maximum # of bytes to compare
212599289f2SAugustin Cavalier *
213599289f2SAugustin Cavalier * RETURN:      Index where Buffers mismatched, or 0 if Buffers matched
214599289f2SAugustin Cavalier *
215599289f2SAugustin Cavalier * DESCRIPTION: Compare two Buffers, with a maximum length
216599289f2SAugustin Cavalier *
217599289f2SAugustin Cavalier ******************************************************************************/
218599289f2SAugustin Cavalier
219599289f2SAugustin Cavalierint
220599289f2SAugustin Cavaliermemcmp (
221599289f2SAugustin Cavalier    void                    *VBuffer1,
222599289f2SAugustin Cavalier    void                    *VBuffer2,
223599289f2SAugustin Cavalier    ACPI_SIZE               Count)
224599289f2SAugustin Cavalier{
225599289f2SAugustin Cavalier    char                    *Buffer1 = (char *) VBuffer1;
226599289f2SAugustin Cavalier    char                    *Buffer2 = (char *) VBuffer2;
227599289f2SAugustin Cavalier
228599289f2SAugustin Cavalier
229599289f2SAugustin Cavalier    for ( ; Count-- && (*Buffer1 == *Buffer2); Buffer1++, Buffer2++)
230599289f2SAugustin Cavalier    {
231599289f2SAugustin Cavalier    }
232599289f2SAugustin Cavalier
233599289f2SAugustin Cavalier    return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *Buffer1 -
234599289f2SAugustin Cavalier        (unsigned char) *Buffer2));
235599289f2SAugustin Cavalier}
236599289f2SAugustin Cavalier
237599289f2SAugustin Cavalier
238ff2e2f81SFredrik Holmqvist/*******************************************************************************
239ff2e2f81SFredrik Holmqvist *
240ff2e2f81SFredrik Holmqvist * FUNCTION:    memmove
241ff2e2f81SFredrik Holmqvist *
242ff2e2f81SFredrik Holmqvist * PARAMETERS:  Dest        - Target of the copy
243ff2e2f81SFredrik Holmqvist *              Src         - Source buffer to copy
244ff2e2f81SFredrik Holmqvist *              Count       - Number of bytes to copy
245ff2e2f81SFredrik Holmqvist *
246ff2e2f81SFredrik Holmqvist * RETURN:      Dest
247ff2e2f81SFredrik Holmqvist *
248ff2e2f81SFredrik Holmqvist * DESCRIPTION: Copy arbitrary bytes of memory with respect to the overlapping
249ff2e2f81SFredrik Holmqvist *
250ff2e2f81SFredrik Holmqvist ******************************************************************************/
251ff2e2f81SFredrik Holmqvist
252ff2e2f81SFredrik Holmqvistvoid *
253ff2e2f81SFredrik Holmqvistmemmove (
254ff2e2f81SFredrik Holmqvist    void                    *Dest,
255ff2e2f81SFredrik Holmqvist    const void              *Src,
256ff2e2f81SFredrik Holmqvist    ACPI_SIZE               Count)
257ff2e2f81SFredrik Holmqvist{
258ff2e2f81SFredrik Holmqvist    char                    *New = (char *) Dest;
259ff2e2f81SFredrik Holmqvist    char                    *Old = (char *) Src;
260ff2e2f81SFredrik Holmqvist
261ff2e2f81SFredrik Holmqvist
262ff2e2f81SFredrik Holmqvist    if (Old > New)
263ff2e2f81SFredrik Holmqvist    {
264ff2e2f81SFredrik Holmqvist        /* Copy from the beginning */
265ff2e2f81SFredrik Holmqvist
266ff2e2f81SFredrik Holmqvist        while (Count)
267ff2e2f81SFredrik Holmqvist        {
268ff2e2f81SFredrik Holmqvist            *New = *Old;
269ff2e2f81SFredrik Holmqvist            New++;
270ff2e2f81SFredrik Holmqvist            Old++;
271ff2e2f81SFredrik Holmqvist            Count--;
272ff2e2f81SFredrik Holmqvist        }
273ff2e2f81SFredrik Holmqvist    }
274ff2e2f81SFredrik Holmqvist    else if (Old < New)
275ff2e2f81SFredrik Holmqvist    {
276ff2e2f81SFredrik Holmqvist        /* Copy from the end */
277ff2e2f81SFredrik Holmqvist
278ff2e2f81SFredrik Holmqvist        New = New + Count - 1;
279ff2e2f81SFredrik Holmqvist        Old = Old + Count - 1;
280ff2e2f81SFredrik Holmqvist        while (Count)
281ff2e2f81SFredrik Holmqvist        {
282ff2e2f81SFredrik Holmqvist            *New = *Old;
283ff2e2f81SFredrik Holmqvist            New--;
284ff2e2f81SFredrik Holmqvist            Old--;
285ff2e2f81SFredrik Holmqvist            Count--;
286ff2e2f81SFredrik Holmqvist        }
287ff2e2f81SFredrik Holmqvist    }
288ff2e2f81SFredrik Holmqvist
289ff2e2f81SFredrik Holmqvist    return (Dest);
290ff2e2f81SFredrik Holmqvist}
291ff2e2f81SFredrik Holmqvist
292ff2e2f81SFredrik Holmqvist
293599289f2SAugustin Cavalier/*******************************************************************************
294599289f2SAugustin Cavalier *
295599289f2SAugustin Cavalier * FUNCTION:    memcpy
296599289f2SAugustin Cavalier *
297599289f2SAugustin Cavalier * PARAMETERS:  Dest        - Target of the copy
298599289f2SAugustin Cavalier *              Src         - Source buffer to copy
299599289f2SAugustin Cavalier *              Count       - Number of bytes to copy
300599289f2SAugustin Cavalier *
301599289f2SAugustin Cavalier * RETURN:      Dest
302599289f2SAugustin Cavalier *
303599289f2SAugustin Cavalier * DESCRIPTION: Copy arbitrary bytes of memory
304599289f2SAugustin Cavalier *
305599289f2SAugustin Cavalier ******************************************************************************/
306599289f2SAugustin Cavalier
307599289f2SAugustin Cavaliervoid *
308599289f2SAugustin Cavaliermemcpy (
309599289f2SAugustin Cavalier    void                    *Dest,
310599289f2SAugustin Cavalier    const void              *Src,
311599289f2SAugustin Cavalier    ACPI_SIZE               Count)
312599289f2SAugustin Cavalier{
313599289f2SAugustin Cavalier    char                    *New = (char *) Dest;
314599289f2SAugustin Cavalier    char                    *Old = (char *) Src;
315599289f2SAugustin Cavalier
316599289f2SAugustin Cavalier
317599289f2SAugustin Cavalier    while (Count)
318599289f2SAugustin Cavalier    {
319599289f2SAugustin Cavalier        *New = *Old;
320599289f2SAugustin Cavalier        New++;
321599289f2SAugustin Cavalier        Old++;
322599289f2SAugustin Cavalier        Count--;
323599289f2SAugustin Cavalier    }
324599289f2SAugustin Cavalier
325599289f2SAugustin Cavalier    return (Dest);
326599289f2SAugustin Cavalier}
327599289f2SAugustin Cavalier
328599289f2SAugustin Cavalier
329599289f2SAugustin Cavalier/*******************************************************************************
330599289f2SAugustin Cavalier *
331599289f2SAugustin Cavalier * FUNCTION:    memset
332599289f2SAugustin Cavalier *
333599289f2SAugustin Cavalier * PARAMETERS:  Dest        - Buffer to set
334599289f2SAugustin Cavalier *              Value       - Value to set each byte of memory
335599289f2SAugustin Cavalier *              Count       - Number of bytes to set
336599289f2SAugustin Cavalier *
337599289f2SAugustin Cavalier * RETURN:      Dest
338599289f2SAugustin Cavalier *
339599289f2SAugustin Cavalier * DESCRIPTION: Initialize a buffer to a known value.
340599289f2SAugustin Cavalier *
341599289f2SAugustin Cavalier ******************************************************************************/
342599289f2SAugustin Cavalier
343599289f2SAugustin Cavaliervoid *
344599289f2SAugustin Cavaliermemset (
345599289f2SAugustin Cavalier    void                    *Dest,
346599289f2SAugustin Cavalier    int                     Value,
347599289f2SAugustin Cavalier    ACPI_SIZE               Count)
348599289f2SAugustin Cavalier{
349599289f2SAugustin Cavalier    char                    *New = (char *) Dest;
350599289f2SAugustin Cavalier
351599289f2SAugustin Cavalier
352599289f2SAugustin Cavalier    while (Count)
353599289f2SAugustin Cavalier    {
354599289f2SAugustin Cavalier        *New = (char) Value;
355599289f2SAugustin Cavalier        New++;
356599289f2SAugustin Cavalier        Count--;
357599289f2SAugustin Cavalier    }
358599289f2SAugustin Cavalier
359599289f2SAugustin Cavalier    return (Dest);
360599289f2SAugustin Cavalier}
361599289f2SAugustin Cavalier
362599289f2SAugustin Cavalier
363599289f2SAugustin Cavalier/*******************************************************************************
364599289f2SAugustin Cavalier *
365599289f2SAugustin Cavalier * FUNCTION:    strlen
366599289f2SAugustin Cavalier *
367599289f2SAugustin Cavalier * PARAMETERS:  String              - Null terminated string
368599289f2SAugustin Cavalier *
369599289f2SAugustin Cavalier * RETURN:      Length
370599289f2SAugustin Cavalier *
371599289f2SAugustin Cavalier * DESCRIPTION: Returns the length of the input string
372599289f2SAugustin Cavalier *
373599289f2SAugustin Cavalier ******************************************************************************/
374599289f2SAugustin Cavalier
375599289f2SAugustin Cavalier
376599289f2SAugustin CavalierACPI_SIZE
377599289f2SAugustin Cavalierstrlen (
378599289f2SAugustin Cavalier    const char              *String)
379599289f2SAugustin Cavalier{
380599289f2SAugustin Cavalier    UINT32                  Length = 0;
381599289f2SAugustin Cavalier
382599289f2SAugustin Cavalier
383599289f2SAugustin Cavalier    /* Count the string until a null is encountered */
384599289f2SAugustin Cavalier
385599289f2SAugustin Cavalier    while (*String)
386599289f2SAugustin Cavalier    {
387599289f2SAugustin Cavalier        Length++;
388599289f2SAugustin Cavalier        String++;
389599289f2SAugustin Cavalier    }
390599289f2SAugustin Cavalier
391599289f2SAugustin Cavalier    return (Length);
392599289f2SAugustin Cavalier}
393599289f2SAugustin Cavalier
394599289f2SAugustin Cavalier
395ff2e2f81SFredrik Holmqvist/*******************************************************************************
396ff2e2f81SFredrik Holmqvist *
397ff2e2f81SFredrik Holmqvist * FUNCTION:    strpbrk
398ff2e2f81SFredrik Holmqvist *
399ff2e2f81SFredrik Holmqvist * PARAMETERS:  String              - Null terminated string
400ff2e2f81SFredrik Holmqvist *              Delimiters          - Delimiters to match
401ff2e2f81SFredrik Holmqvist *
402ff2e2f81SFredrik Holmqvist * RETURN:      The first occurance in the string of any of the bytes in the
403ff2e2f81SFredrik Holmqvist *              delimiters
404ff2e2f81SFredrik Holmqvist *
405ff2e2f81SFredrik Holmqvist * DESCRIPTION: Search a string for any of a set of the delimiters
406ff2e2f81SFredrik Holmqvist *
407ff2e2f81SFredrik Holmqvist ******************************************************************************/
408ff2e2f81SFredrik Holmqvist
409ff2e2f81SFredrik Holmqvistchar *
410ff2e2f81SFredrik Holmqviststrpbrk (
411ff2e2f81SFredrik Holmqvist    const char              *String,
412ff2e2f81SFredrik Holmqvist    const char              *Delimiters)
413ff2e2f81SFredrik Holmqvist{
414ff2e2f81SFredrik Holmqvist    const char              *Delimiter;
415ff2e2f81SFredrik Holmqvist
416ff2e2f81SFredrik Holmqvist
417ff2e2f81SFredrik Holmqvist    for ( ; *String != '\0'; ++String)
418ff2e2f81SFredrik Holmqvist    {
419ff2e2f81SFredrik Holmqvist        for (Delimiter = Delimiters; *Delimiter != '\0'; Delimiter++)
420ff2e2f81SFredrik Holmqvist        {
421ff2e2f81SFredrik Holmqvist            if (*String == *Delimiter)
422ff2e2f81SFredrik Holmqvist            {
423ff2e2f81SFredrik Holmqvist                return (ACPI_CAST_PTR (char, String));
424ff2e2f81SFredrik Holmqvist            }
425ff2e2f81SFredrik Holmqvist        }
426ff2e2f81SFredrik Holmqvist    }
427ff2e2f81SFredrik Holmqvist
428ff2e2f81SFredrik Holmqvist    return (NULL);
429ff2e2f81SFredrik Holmqvist}
430ff2e2f81SFredrik Holmqvist
431ff2e2f81SFredrik Holmqvist
432ff2e2f81SFredrik Holmqvist/*******************************************************************************
433ff2e2f81SFredrik Holmqvist *
434ff2e2f81SFredrik Holmqvist * FUNCTION:    strtok
435ff2e2f81SFredrik Holmqvist *
436ff2e2f81SFredrik Holmqvist * PARAMETERS:  String              - Null terminated string
437ff2e2f81SFredrik Holmqvist *              Delimiters          - Delimiters to match
438ff2e2f81SFredrik Holmqvist *
439ff2e2f81SFredrik Holmqvist * RETURN:      Pointer to the next token
440ff2e2f81SFredrik Holmqvist *
441ff2e2f81SFredrik Holmqvist * DESCRIPTION: Split string into tokens
442ff2e2f81SFredrik Holmqvist *
443ff2e2f81SFredrik Holmqvist ******************************************************************************/
444ff2e2f81SFredrik Holmqvist
445ff2e2f81SFredrik Holmqvistchar*
446ff2e2f81SFredrik Holmqviststrtok (
447ff2e2f81SFredrik Holmqvist    char                    *String,
448ff2e2f81SFredrik Holmqvist    const char              *Delimiters)
449ff2e2f81SFredrik Holmqvist{
450ff2e2f81SFredrik Holmqvist    char                    *Begin = String;
451ff2e2f81SFredrik Holmqvist    static char             *SavedPtr;
452ff2e2f81SFredrik Holmqvist
453ff2e2f81SFredrik Holmqvist
454ff2e2f81SFredrik Holmqvist    if (Begin == NULL)
455ff2e2f81SFredrik Holmqvist    {
456ff2e2f81SFredrik Holmqvist        if (SavedPtr == NULL)
457ff2e2f81SFredrik Holmqvist        {
458ff2e2f81SFredrik Holmqvist            return (NULL);
459ff2e2f81SFredrik Holmqvist        }
460ff2e2f81SFredrik Holmqvist        Begin = SavedPtr;
461ff2e2f81SFredrik Holmqvist    }
462ff2e2f81SFredrik Holmqvist
463ff2e2f81SFredrik Holmqvist    SavedPtr = strpbrk (Begin, Delimiters);
464ff2e2f81SFredrik Holmqvist    while (SavedPtr == Begin)
465ff2e2f81SFredrik Holmqvist    {
466ff2e2f81SFredrik Holmqvist        *Begin++ = '\0';
467ff2e2f81SFredrik Holmqvist        SavedPtr = strpbrk (Begin, Delimiters);
468ff2e2f81SFredrik Holmqvist    }
469ff2e2f81SFredrik Holmqvist
470ff2e2f81SFredrik Holmqvist    if (SavedPtr)
471ff2e2f81SFredrik Holmqvist    {
472ff2e2f81SFredrik Holmqvist        *SavedPtr++ = '\0';
473ff2e2f81SFredrik Holmqvist        return (Begin);
474ff2e2f81SFredrik Holmqvist    }
475ff2e2f81SFredrik Holmqvist    else
476ff2e2f81SFredrik Holmqvist    {
477ff2e2f81SFredrik Holmqvist        return (NULL);
478ff2e2f81SFredrik Holmqvist    }
479ff2e2f81SFredrik Holmqvist}
480ff2e2f81SFredrik Holmqvist
481ff2e2f81SFredrik Holmqvist
482599289f2SAugustin Cavalier/*******************************************************************************
483599289f2SAugustin Cavalier *
484599289f2SAugustin Cavalier * FUNCTION:    strcpy
485599289f2SAugustin Cavalier *
486599289f2SAugustin Cavalier * PARAMETERS:  DstString       - Target of the copy
487599289f2SAugustin Cavalier *              SrcString       - The source string to copy
488599289f2SAugustin Cavalier *
489599289f2SAugustin Cavalier * RETURN:      DstString
490599289f2SAugustin Cavalier *
491599289f2SAugustin Cavalier * DESCRIPTION: Copy a null terminated string
492599289f2SAugustin Cavalier *
493599289f2SAugustin Cavalier ******************************************************************************/
494599289f2SAugustin Cavalier
495599289f2SAugustin Cavalierchar *
496599289f2SAugustin Cavalierstrcpy (
497599289f2SAugustin Cavalier    char                    *DstString,
498599289f2SAugustin Cavalier    const char              *SrcString)
499599289f2SAugustin Cavalier{
500599289f2SAugustin Cavalier    char                    *String = DstString;
501599289f2SAugustin Cavalier
502599289f2SAugustin Cavalier
503599289f2SAugustin Cavalier    /* Move bytes brute force */
504599289f2SAugustin Cavalier
505599289f2SAugustin Cavalier    while (*SrcString)
506599289f2SAugustin Cavalier    {
507599289f2SAugustin Cavalier        *String = *SrcString;
508599289f2SAugustin Cavalier
509599289f2SAugustin Cavalier        String++;
510599289f2SAugustin Cavalier        SrcString++;
511599289f2SAugustin Cavalier    }
512599289f2SAugustin Cavalier
513599289f2SAugustin Cavalier    /* Null terminate */
514599289f2SAugustin Cavalier
515599289f2SAugustin Cavalier    *String = 0;
516599289f2SAugustin Cavalier    return (DstString);
517599289f2SAugustin Cavalier}
518599289f2SAugustin Cavalier
519599289f2SAugustin Cavalier
520599289f2SAugustin Cavalier/*******************************************************************************
521599289f2SAugustin Cavalier *
522599289f2SAugustin Cavalier * FUNCTION:    strncpy
523599289f2SAugustin Cavalier *
524599289f2SAugustin Cavalier * PARAMETERS:  DstString       - Target of the copy
525599289f2SAugustin Cavalier *              SrcString       - The source string to copy
526599289f2SAugustin Cavalier *              Count           - Maximum # of bytes to copy
527599289f2SAugustin Cavalier *
528599289f2SAugustin Cavalier * RETURN:      DstString
529599289f2SAugustin Cavalier *
530599289f2SAugustin Cavalier * DESCRIPTION: Copy a null terminated string, with a maximum length
531599289f2SAugustin Cavalier *
532599289f2SAugustin Cavalier ******************************************************************************/
533599289f2SAugustin Cavalier
534599289f2SAugustin Cavalierchar *
535599289f2SAugustin Cavalierstrncpy (
536599289f2SAugustin Cavalier    char                    *DstString,
537599289f2SAugustin Cavalier    const char              *SrcString,
538599289f2SAugustin Cavalier    ACPI_SIZE               Count)
539599289f2SAugustin Cavalier{
540599289f2SAugustin Cavalier    char                    *String = DstString;
541599289f2SAugustin Cavalier
542599289f2SAugustin Cavalier
543599289f2SAugustin Cavalier    /* Copy the string */
544599289f2SAugustin Cavalier
545599289f2SAugustin Cavalier    for (String = DstString;
546599289f2SAugustin Cavalier        Count && (Count--, (*String++ = *SrcString++)); )
547599289f2SAugustin Cavalier    {;}
548599289f2SAugustin Cavalier
549599289f2SAugustin Cavalier    /* Pad with nulls if necessary */
550599289f2SAugustin Cavalier
551599289f2SAugustin Cavalier    while (Count--)
552599289f2SAugustin Cavalier    {
553599289f2SAugustin Cavalier        *String = 0;
554599289f2SAugustin Cavalier        String++;
555599289f2SAugustin Cavalier    }
556599289f2SAugustin Cavalier
557599289f2SAugustin Cavalier    /* Return original pointer */
558599289f2SAugustin Cavalier
559599289f2SAugustin Cavalier    return (DstString);
560599289f2SAugustin Cavalier}
561599289f2SAugustin Cavalier
562599289f2SAugustin Cavalier
563599289f2SAugustin Cavalier/*******************************************************************************
564599289f2SAugustin Cavalier *
565599289f2SAugustin Cavalier * FUNCTION:    strcmp
566599289f2SAugustin Cavalier *
567599289f2SAugustin Cavalier * PARAMETERS:  String1         - First string
568599289f2SAugustin Cavalier *              String2         - Second string
569599289f2SAugustin Cavalier *
570599289f2SAugustin Cavalier * RETURN:      Index where strings mismatched, or 0 if strings matched
571599289f2SAugustin Cavalier *
572599289f2SAugustin Cavalier * DESCRIPTION: Compare two null terminated strings
573599289f2SAugustin Cavalier *
574599289f2SAugustin Cavalier ******************************************************************************/
575599289f2SAugustin Cavalier
576599289f2SAugustin Cavalierint
577599289f2SAugustin Cavalierstrcmp (
578599289f2SAugustin Cavalier    const char              *String1,
579599289f2SAugustin Cavalier    const char              *String2)
580599289f2SAugustin Cavalier{
581599289f2SAugustin Cavalier
582599289f2SAugustin Cavalier
583599289f2SAugustin Cavalier    for ( ; (*String1 == *String2); String2++)
584599289f2SAugustin Cavalier    {
585599289f2SAugustin Cavalier        if (!*String1++)
586599289f2SAugustin Cavalier        {
587599289f2SAugustin Cavalier            return (0);
588599289f2SAugustin Cavalier        }
589599289f2SAugustin Cavalier    }
590599289f2SAugustin Cavalier
591599289f2SAugustin Cavalier    return ((unsigned char) *String1 - (unsigned char) *String2);
592599289f2SAugustin Cavalier}
593599289f2SAugustin Cavalier
594599289f2SAugustin Cavalier
595599289f2SAugustin Cavalier/*******************************************************************************
596599289f2SAugustin Cavalier *
597599289f2SAugustin Cavalier * FUNCTION:    strchr
598599289f2SAugustin Cavalier *
599599289f2SAugustin Cavalier * PARAMETERS:  String          - Search string
600599289f2SAugustin Cavalier *              ch              - character to search for
601599289f2SAugustin Cavalier *
602599289f2SAugustin Cavalier * RETURN:      Ptr to char or NULL if not found
603599289f2SAugustin Cavalier *
604599289f2SAugustin Cavalier * DESCRIPTION: Search a string for a character
605599289f2SAugustin Cavalier *
606599289f2SAugustin Cavalier ******************************************************************************/
607599289f2SAugustin Cavalier
608599289f2SAugustin Cavalierchar *
609599289f2SAugustin Cavalierstrchr (
610599289f2SAugustin Cavalier    const char              *String,
611599289f2SAugustin Cavalier    int                     ch)
612599289f2SAugustin Cavalier{
613599289f2SAugustin Cavalier
614599289f2SAugustin Cavalier
615599289f2SAugustin Cavalier    for ( ; (*String); String++)
616599289f2SAugustin Cavalier    {
617599289f2SAugustin Cavalier        if ((*String) == (char) ch)
618599289f2SAugustin Cavalier        {
619599289f2SAugustin Cavalier            return ((char *) String);
620599289f2SAugustin Cavalier        }
621599289f2SAugustin Cavalier    }
622599289f2SAugustin Cavalier
623599289f2SAugustin Cavalier    return (NULL);
624599289f2SAugustin Cavalier}
625599289f2SAugustin Cavalier
626599289f2SAugustin Cavalier
627599289f2SAugustin Cavalier/*******************************************************************************
628599289f2SAugustin Cavalier *
629599289f2SAugustin Cavalier * FUNCTION:    strncmp
630599289f2SAugustin Cavalier *
631599289f2SAugustin Cavalier * PARAMETERS:  String1         - First string
632599289f2SAugustin Cavalier *              String2         - Second string
633599289f2SAugustin Cavalier *              Count           - Maximum # of bytes to compare
634599289f2SAugustin Cavalier *
635599289f2SAugustin Cavalier * RETURN:      Index where strings mismatched, or 0 if strings matched
636599289f2SAugustin Cavalier *
637599289f2SAugustin Cavalier * DESCRIPTION: Compare two null terminated strings, with a maximum length
638599289f2SAugustin Cavalier *
639599289f2SAugustin Cavalier ******************************************************************************/
640599289f2SAugustin Cavalier
641599289f2SAugustin Cavalierint
642599289f2SAugustin Cavalierstrncmp (
643599289f2SAugustin Cavalier    const char              *String1,
644599289f2SAugustin Cavalier    const char              *String2,
645599289f2SAugustin Cavalier    ACPI_SIZE               Count)
646599289f2SAugustin Cavalier{
647599289f2SAugustin Cavalier
648599289f2SAugustin Cavalier
649599289f2SAugustin Cavalier    for ( ; Count-- && (*String1 == *String2); String2++)
650599289f2SAugustin Cavalier    {
651599289f2SAugustin Cavalier        if (!*String1++)
652599289f2SAugustin Cavalier        {
653599289f2SAugustin Cavalier            return (0);
654599289f2SAugustin Cavalier        }
655599289f2SAugustin Cavalier    }
656599289f2SAugustin Cavalier
657599289f2SAugustin Cavalier    return ((Count == ACPI_SIZE_MAX) ? 0 : ((unsigned char) *String1 -
658599289f2SAugustin Cavalier        (unsigned char) *String2));
659599289f2SAugustin Cavalier}
660599289f2SAugustin Cavalier
661599289f2SAugustin Cavalier
662599289f2SAugustin Cavalier/*******************************************************************************
663599289f2SAugustin Cavalier *
664599289f2SAugustin Cavalier * FUNCTION:    strcat
665599289f2SAugustin Cavalier *
666599289f2SAugustin Cavalier * PARAMETERS:  DstString       - Target of the copy
667599289f2SAugustin Cavalier *              SrcString       - The source string to copy
668599289f2SAugustin Cavalier *
669599289f2SAugustin Cavalier * RETURN:      DstString
670599289f2SAugustin Cavalier *
671599289f2SAugustin Cavalier * DESCRIPTION: Append a null terminated string to a null terminated string
672599289f2SAugustin Cavalier *
673599289f2SAugustin Cavalier ******************************************************************************/
674599289f2SAugustin Cavalier
675599289f2SAugustin Cavalierchar *
676599289f2SAugustin Cavalierstrcat (
677599289f2SAugustin Cavalier    char                    *DstString,
678599289f2SAugustin Cavalier    const char              *SrcString)
679599289f2SAugustin Cavalier{
680599289f2SAugustin Cavalier    char                    *String;
681599289f2SAugustin Cavalier
682599289f2SAugustin Cavalier
683599289f2SAugustin Cavalier    /* Find end of the destination string */
684599289f2SAugustin Cavalier
685599289f2SAugustin Cavalier    for (String = DstString; *String++; )
686599289f2SAugustin Cavalier    { ; }
687599289f2SAugustin Cavalier
688599289f2SAugustin Cavalier    /* Concatenate the string */
689599289f2SAugustin Cavalier
690599289f2SAugustin Cavalier    for (--String; (*String++ = *SrcString++); )
691599289f2SAugustin Cavalier    { ; }
692599289f2SAugustin Cavalier
693599289f2SAugustin Cavalier    return (DstString);
694599289f2SAugustin Cavalier}
695599289f2SAugustin Cavalier
696599289f2SAugustin Cavalier
697599289f2SAugustin Cavalier/*******************************************************************************
698599289f2SAugustin Cavalier *
699599289f2SAugustin Cavalier * FUNCTION:    strncat
700599289f2SAugustin Cavalier *
701599289f2SAugustin Cavalier * PARAMETERS:  DstString       - Target of the copy
702599289f2SAugustin Cavalier *              SrcString       - The source string to copy
703599289f2SAugustin Cavalier *              Count           - Maximum # of bytes to copy
704599289f2SAugustin Cavalier *
705599289f2SAugustin Cavalier * RETURN:      DstString
706599289f2SAugustin Cavalier *
707599289f2SAugustin Cavalier * DESCRIPTION: Append a null terminated string to a null terminated string,
708599289f2SAugustin Cavalier *              with a maximum count.
709599289f2SAugustin Cavalier *
710599289f2SAugustin Cavalier ******************************************************************************/
711599289f2SAugustin Cavalier
712599289f2SAugustin Cavalierchar *
713599289f2SAugustin Cavalierstrncat (
714599289f2SAugustin Cavalier    char                    *DstString,
715599289f2SAugustin Cavalier    const char              *SrcString,
716599289f2SAugustin Cavalier    ACPI_SIZE               Count)
717599289f2SAugustin Cavalier{
718599289f2SAugustin Cavalier    char                    *String;
719599289f2SAugustin Cavalier
720599289f2SAugustin Cavalier
721599289f2SAugustin Cavalier    if (Count)
722599289f2SAugustin Cavalier    {
723599289f2SAugustin Cavalier        /* Find end of the destination string */
724599289f2SAugustin Cavalier
725599289f2SAugustin Cavalier        for (String = DstString; *String++; )
726599289f2SAugustin Cavalier        { ; }
727599289f2SAugustin Cavalier
728599289f2SAugustin Cavalier        /* Concatenate the string */
729599289f2SAugustin Cavalier
730