1284563Sjkim/******************************************************************************
2284563Sjkim *
3284563Sjkim * Name: acclib.h -- C library support. Prototypes for the (optional) local
4284563Sjkim *                   implementations of required C library functions.
5284563Sjkim *
6284563Sjkim *****************************************************************************/
7284563Sjkim
8316303Sjkim/******************************************************************************
9316303Sjkim *
10316303Sjkim * 1. Copyright Notice
11316303Sjkim *
12316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
13284563Sjkim * All rights reserved.
14284563Sjkim *
15316303Sjkim * 2. License
16316303Sjkim *
17316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
18316303Sjkim * rights. You may have additional license terms from the party that provided
19316303Sjkim * you this software, covering your right to use that party's intellectual
20316303Sjkim * property rights.
21316303Sjkim *
22316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
24316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
26316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
27316303Sjkim * Code in any form, with the right to sublicense such rights; and
28316303Sjkim *
29316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30316303Sjkim * license (with the right to sublicense), under only those claims of Intel
31316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
32316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
33316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
34316303Sjkim * license, and in no event shall the patent license extend to any additions
35316303Sjkim * to or modifications of the Original Intel Code. No other license or right
36316303Sjkim * is granted directly or by implication, estoppel or otherwise;
37316303Sjkim *
38316303Sjkim * The above copyright and patent license is granted only if the following
39316303Sjkim * conditions are met:
40316303Sjkim *
41316303Sjkim * 3. Conditions
42316303Sjkim *
43316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44316303Sjkim * Redistribution of source code of any substantial portion of the Covered
45316303Sjkim * Code or modification with rights to further distribute source must include
46316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
47316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
48316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
49316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
50316303Sjkim * Code and the date of any change. Licensee must include in that file the
51316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
52316303Sjkim * must include a prominent statement that the modification is derived,
53316303Sjkim * directly or indirectly, from Original Intel Code.
54316303Sjkim *
55316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56316303Sjkim * Redistribution of source code of any substantial portion of the Covered
57316303Sjkim * Code or modification without rights to further distribute source must
58316303Sjkim * include the following Disclaimer and Export Compliance provision in the
59316303Sjkim * documentation and/or other materials provided with distribution. In
60316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
61316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
62316303Sjkim * license from Licensee to its licensee is limited to the intellectual
63316303Sjkim * property embodied in the software Licensee provides to its licensee, and
64316303Sjkim * not to intellectual property embodied in modifications its licensee may
65316303Sjkim * make.
66316303Sjkim *
67316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
68316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
69316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
70316303Sjkim * provision in the documentation and/or other materials provided with the
71316303Sjkim * distribution.
72316303Sjkim *
73316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
74316303Sjkim * Intel Code.
75316303Sjkim *
76316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
78316303Sjkim * other dealings in products derived from or relating to the Covered Code
79316303Sjkim * without prior written authorization from Intel.
80316303Sjkim *
81316303Sjkim * 4. Disclaimer and Export Compliance
82316303Sjkim *
83316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89316303Sjkim * PARTICULAR PURPOSE.
90316303Sjkim *
91316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98316303Sjkim * LIMITED REMEDY.
99316303Sjkim *
100316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
101316303Sjkim * software or system incorporating such software without first obtaining any
102316303Sjkim * required license or other approval from the U. S. Department of Commerce or
103316303Sjkim * any other agency or department of the United States Government. In the
104316303Sjkim * event Licensee exports any such software from the United States or
105316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
106316303Sjkim * ensure that the distribution and export/re-export of the software is in
107316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
108316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
110316303Sjkim * software, or service, directly or indirectly, to any country for which the
111316303Sjkim * United States government or any agency thereof requires an export license,
112316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
113316303Sjkim * such license, approval or letter.
114316303Sjkim *
115316303Sjkim *****************************************************************************
116316303Sjkim *
117316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
118316303Sjkim * following license:
119316303Sjkim *
120284563Sjkim * Redistribution and use in source and binary forms, with or without
121284563Sjkim * modification, are permitted provided that the following conditions
122284563Sjkim * are met:
123284563Sjkim * 1. Redistributions of source code must retain the above copyright
124284563Sjkim *    notice, this list of conditions, and the following disclaimer,
125284563Sjkim *    without modification.
126284563Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127284563Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
128284563Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
129284563Sjkim *    including a substantially similar Disclaimer requirement for further
130284563Sjkim *    binary redistribution.
131284563Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
132284563Sjkim *    of any contributors may be used to endorse or promote products derived
133284563Sjkim *    from this software without specific prior written permission.
134284563Sjkim *
135316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146316303Sjkim *
147316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
148284563Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
149284563Sjkim * Software Foundation.
150284563Sjkim *
151316303Sjkim *****************************************************************************/
152284563Sjkim
153284563Sjkim#ifndef _ACCLIB_H
154284563Sjkim#define _ACCLIB_H
155284563Sjkim
156284563Sjkim
157284563Sjkim/*
158284563Sjkim * Prototypes and macros for local implementations of C library functions
159284563Sjkim */
160284563Sjkim
161284563Sjkim/* is* functions. The AcpiGbl_Ctypes array is defined in utclib.c */
162284563Sjkim
163284563Sjkimextern const UINT8 AcpiGbl_Ctypes[];
164284563Sjkim
165284563Sjkim#define _ACPI_XA     0x00    /* extra alphabetic - not supported */
166284563Sjkim#define _ACPI_XS     0x40    /* extra space */
167284563Sjkim#define _ACPI_BB     0x00    /* BEL, BS, etc. - not supported */
168284563Sjkim#define _ACPI_CN     0x20    /* CR, FF, HT, NL, VT */
169284563Sjkim#define _ACPI_DI     0x04    /* '0'-'9' */
170284563Sjkim#define _ACPI_LO     0x02    /* 'a'-'z' */
171284563Sjkim#define _ACPI_PU     0x10    /* punctuation */
172284563Sjkim#define _ACPI_SP     0x08    /* space, tab, CR, LF, VT, FF */
173284563Sjkim#define _ACPI_UP     0x01    /* 'A'-'Z' */
174284563Sjkim#define _ACPI_XD     0x80    /* '0'-'9', 'A'-'F', 'a'-'f' */
175284563Sjkim
176284563Sjkim#define isdigit(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_DI))
177284563Sjkim#define isspace(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_SP))
178284563Sjkim#define isxdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_XD))
179284563Sjkim#define isupper(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_UP))
180284563Sjkim#define islower(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO))
181284563Sjkim#define isprint(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU))
182284563Sjkim#define isalpha(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
183284563Sjkim
184316303Sjkim/* Error code */
185284563Sjkim
186316303Sjkim#define EPERM            1 /* Operation not permitted */
187316303Sjkim#define ENOENT           2 /* No such file or directory */
188316303Sjkim#define EINTR            4 /* Interrupted system call */
189316303Sjkim#define EIO              5 /* I/O error */
190316303Sjkim#define EBADF            9 /* Bad file number */
191316303Sjkim#define EAGAIN          11 /* Try again */
192316303Sjkim#define ENOMEM          12 /* Out of memory */
193316303Sjkim#define EACCES          13 /* Permission denied */
194316303Sjkim#define EFAULT          14 /* Bad address */
195316303Sjkim#define EBUSY           16 /* Device or resource busy */
196316303Sjkim#define EEXIST          17 /* File exists */
197316303Sjkim#define ENODEV          19 /* No such device */
198316303Sjkim#define EINVAL          22 /* Invalid argument */
199316303Sjkim#define EPIPE           32 /* Broken pipe */
200316303Sjkim#define ERANGE          34 /* Math result not representable */
201316303Sjkim
202284563Sjkim/* Strings */
203284563Sjkim
204284563Sjkimchar *
205284563Sjkimstrcat (
206284563Sjkim    char                    *DstString,
207284563Sjkim    const char              *SrcString);
208284563Sjkim
209284563Sjkimchar *
210284563Sjkimstrchr (
211284563Sjkim    const char              *String,
212284563Sjkim    int                     ch);
213284563Sjkim
214284563Sjkimchar *
215316303Sjkimstrpbrk (
216316303Sjkim    const char              *String,
217316303Sjkim    const char              *Delimiters);
218316303Sjkim
219316303Sjkimchar *
220316303Sjkimstrtok (
221316303Sjkim    char                    *String,
222316303Sjkim    const char              *Delimiters);
223316303Sjkim
224316303Sjkimchar *
225284563Sjkimstrcpy (
226284563Sjkim    char                    *DstString,
227284563Sjkim    const char              *SrcString);
228284563Sjkim
229284563Sjkimint
230284563Sjkimstrcmp (
231284563Sjkim    const char              *String1,
232284563Sjkim    const char              *String2);
233284563Sjkim
234284563SjkimACPI_SIZE
235284563Sjkimstrlen (
236284563Sjkim    const char              *String);
237284563Sjkim
238284563Sjkimchar *
239284563Sjkimstrncat (
240284563Sjkim    char                    *DstString,
241284563Sjkim    const char              *SrcString,
242284563Sjkim    ACPI_SIZE               Count);
243284563Sjkim
244284563Sjkimint
245284563Sjkimstrncmp (
246284563Sjkim    const char              *String1,
247284563Sjkim    const char              *String2,
248284563Sjkim    ACPI_SIZE               Count);
249284563Sjkim
250284563Sjkimchar *
251284563Sjkimstrncpy (
252284563Sjkim    char                    *DstString,
253284563Sjkim    const char              *SrcString,
254284563Sjkim    ACPI_SIZE               Count);
255284563Sjkim
256284563Sjkimchar *
257284563Sjkimstrstr (
258284563Sjkim    char                    *String1,
259284563Sjkim    char                    *String2);
260284563Sjkim
261284563Sjkim
262284563Sjkim/* Conversion */
263284563Sjkim
264284563SjkimUINT32
265284563Sjkimstrtoul (
266284563Sjkim    const char              *String,
267284563Sjkim    char                    **Terminator,
268284563Sjkim    UINT32                  Base);
269284563Sjkim
270284563Sjkim
271284563Sjkim/* Memory */
272284563Sjkim
273284563Sjkimint
274284563Sjkimmemcmp (
275284563Sjkim    void                    *Buffer1,
276284563Sjkim    void                    *Buffer2,
277284563Sjkim    ACPI_SIZE               Count);
278284563Sjkim
279284563Sjkimvoid *
280284563Sjkimmemcpy (
281284563Sjkim    void                    *Dest,
282284563Sjkim    const void              *Src,
283284563Sjkim    ACPI_SIZE               Count);
284284563Sjkim
285284563Sjkimvoid *
286316303Sjkimmemmove (
287316303Sjkim    void                    *Dest,
288316303Sjkim    const void              *Src,
289316303Sjkim    ACPI_SIZE               Count);
290316303Sjkim
291316303Sjkimvoid *
292284563Sjkimmemset (
293284563Sjkim    void                    *Dest,
294284563Sjkim    int                     Value,
295284563Sjkim    ACPI_SIZE               Count);
296284563Sjkim
297284563Sjkim
298284563Sjkim/* upper/lower case */
299284563Sjkim
300284563Sjkimint
301284563Sjkimtolower (
302284563Sjkim    int                     c);
303284563Sjkim
304284563Sjkimint
305284563Sjkimtoupper (
306284563Sjkim    int                     c);
307284563Sjkim
308316303Sjkim/*
309316303Sjkim * utprint - printf/vprintf output functions
310316303Sjkim */
311316303Sjkimconst char *
312316303SjkimAcpiUtScanNumber (
313316303Sjkim    const char              *String,
314316303Sjkim    UINT64                  *NumberPtr);
315316303Sjkim
316316303Sjkimconst char *
317316303SjkimAcpiUtPrintNumber (
318316303Sjkim    char                    *String,
319316303Sjkim    UINT64                  Number);
320316303Sjkim
321316303Sjkimint
322316303Sjkimvsnprintf (
323316303Sjkim    char                    *String,
324316303Sjkim    ACPI_SIZE               Size,
325316303Sjkim    const char              *Format,
326316303Sjkim    va_list                 Args);
327316303Sjkim
328316303Sjkimint
329316303Sjkimsnprintf (
330316303Sjkim    char                    *String,
331316303Sjkim    ACPI_SIZE               Size,
332316303Sjkim    const char              *Format,
333316303Sjkim    ...);
334316303Sjkim
335316303Sjkimint
336316303Sjkimsprintf (
337316303Sjkim    char                    *String,
338316303Sjkim    const char              *Format,
339316303Sjkim    ...);
340316303Sjkim
341316303Sjkim#ifdef ACPI_APPLICATION
342316303Sjkim#define SEEK_SET            0
343316303Sjkim#define SEEK_CUR            1
344316303Sjkim#define SEEK_END            2
345316303Sjkim
346316303Sjkim/*
347316303Sjkim * NOTE: Currently we only need to update errno for file IOs. Other
348316303Sjkim *       Clibrary invocations in ACPICA do not make descisions according to
349316303Sjkim *       the errno.
350316303Sjkim */
351316303Sjkimextern int errno;
352316303Sjkim
353316303Sjkim#ifndef EOF
354316303Sjkim#define EOF                 (-1)
355316303Sjkim#endif
356316303Sjkim
357316303Sjkim#define putchar(c)          fputc(stdout, c)
358316303Sjkim#define getchar(c)          fgetc(stdin)
359316303Sjkim
360316303Sjkimint
361316303Sjkimvprintf (
362316303Sjkim    const char              *Format,
363316303Sjkim    va_list                 Args);
364316303Sjkim
365316303Sjkimint
366316303Sjkimprintf (
367316303Sjkim    const char              *Format,
368316303Sjkim    ...);
369316303Sjkim
370316303Sjkimint
371316303Sjkimvfprintf (
372316303Sjkim    FILE                    *File,
373316303Sjkim    const char              *Format,
374316303Sjkim    va_list                 Args);
375316303Sjkim
376316303Sjkimint
377316303Sjkimfprintf (
378316303Sjkim    FILE                    *File,
379316303Sjkim    const char              *Format,
380316303Sjkim    ...);
381316303Sjkim
382316303SjkimFILE *
383316303Sjkimfopen (
384316303Sjkim    const char              *Path,
385316303Sjkim    const char              *Modes);
386316303Sjkim
387316303Sjkimvoid
388316303Sjkimfclose (
389316303Sjkim    FILE                    *File);
390316303Sjkim
391316303Sjkimint
392316303Sjkimfread (
393316303Sjkim    void                    *Buffer,
394316303Sjkim    ACPI_SIZE               Size,
395316303Sjkim    ACPI_SIZE               Count,
396316303Sjkim    FILE                    *File);
397316303Sjkim
398316303Sjkimint
399316303Sjkimfwrite (
400316303Sjkim    void                    *Buffer,
401316303Sjkim    ACPI_SIZE               Size,
402316303Sjkim    ACPI_SIZE               Count,
403316303Sjkim    FILE                    *File);
404316303Sjkim
405316303Sjkimint
406316303Sjkimfseek (
407316303Sjkim    FILE                    *File,
408316303Sjkim    long                    Offset,
409316303Sjkim    int                     From);
410316303Sjkim
411316303Sjkimlong
412316303Sjkimftell (
413316303Sjkim    FILE                    *File);
414316303Sjkim
415316303Sjkimint
416316303Sjkimfgetc (
417316303Sjkim    FILE                    *File);
418316303Sjkim
419316303Sjkimint
420316303Sjkimfputc (
421316303Sjkim    FILE                    *File,
422316303Sjkim    char                    c);
423316303Sjkim
424316303Sjkimchar *
425316303Sjkimfgets (
426316303Sjkim    char                    *s,
427316303Sjkim    ACPI_SIZE               Size,
428316303Sjkim    FILE                    *File);
429316303Sjkim#endif
430316303Sjkim
431284563Sjkim#endif /* _ACCLIB_H */
432