177a98b4jkim/******************************************************************************
277a98b4jkim *
377a98b4jkim * Name: acclib.h -- C library support. Prototypes for the (optional) local
477a98b4jkim *                   implementations of required C library functions.
577a98b4jkim *
677a98b4jkim *****************************************************************************/
777a98b4jkim
82417024jkim/******************************************************************************
92417024jkim *
102417024jkim * 1. Copyright Notice
112417024jkim *
125911ea1jkim * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
1377a98b4jkim * All rights reserved.
1477a98b4jkim *
152417024jkim * 2. License
162417024jkim *
172417024jkim * 2.1. This is your license from Intel Corp. under its intellectual property
182417024jkim * rights. You may have additional license terms from the party that provided
192417024jkim * you this software, covering your right to use that party's intellectual
202417024jkim * property rights.
212417024jkim *
222417024jkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
232417024jkim * copy of the source code appearing in this file ("Covered Code") an
242417024jkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
252417024jkim * base code distributed originally by Intel ("Original Intel Code") to copy,
262417024jkim * make derivatives, distribute, use and display any portion of the Covered
272417024jkim * Code in any form, with the right to sublicense such rights; and
282417024jkim *
292417024jkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
302417024jkim * license (with the right to sublicense), under only those claims of Intel
312417024jkim * patents that are infringed by the Original Intel Code, to make, use, sell,
322417024jkim * offer to sell, and import the Covered Code and derivative works thereof
332417024jkim * solely to the minimum extent necessary to exercise the above copyright
342417024jkim * license, and in no event shall the patent license extend to any additions
352417024jkim * to or modifications of the Original Intel Code. No other license or right
362417024jkim * is granted directly or by implication, estoppel or otherwise;
372417024jkim *
382417024jkim * The above copyright and patent license is granted only if the following
392417024jkim * conditions are met:
402417024jkim *
412417024jkim * 3. Conditions
422417024jkim *
432417024jkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
442417024jkim * Redistribution of source code of any substantial portion of the Covered
452417024jkim * Code or modification with rights to further distribute source must include
462417024jkim * the above Copyright Notice, the above License, this list of Conditions,
472417024jkim * and the following Disclaimer and Export Compliance provision. In addition,
482417024jkim * Licensee must cause all Covered Code to which Licensee contributes to
492417024jkim * contain a file documenting the changes Licensee made to create that Covered
502417024jkim * Code and the date of any change. Licensee must include in that file the
512417024jkim * documentation of any changes made by any predecessor Licensee. Licensee
522417024jkim * must include a prominent statement that the modification is derived,
532417024jkim * directly or indirectly, from Original Intel Code.
542417024jkim *
552417024jkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
562417024jkim * Redistribution of source code of any substantial portion of the Covered
572417024jkim * Code or modification without rights to further distribute source must
582417024jkim * include the following Disclaimer and Export Compliance provision in the
592417024jkim * documentation and/or other materials provided with distribution. In
602417024jkim * addition, Licensee may not authorize further sublicense of source of any
612417024jkim * portion of the Covered Code, and must include terms to the effect that the
622417024jkim * license from Licensee to its licensee is limited to the intellectual
632417024jkim * property embodied in the software Licensee provides to its licensee, and
642417024jkim * not to intellectual property embodied in modifications its licensee may
652417024jkim * make.
662417024jkim *
672417024jkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
682417024jkim * substantial portion of the Covered Code or modification must reproduce the
692417024jkim * above Copyright Notice, and the following Disclaimer and Export Compliance
702417024jkim * provision in the documentation and/or other materials provided with the
712417024jkim * distribution.
722417024jkim *
732417024jkim * 3.4. Intel retains all right, title, and interest in and to the Original
742417024jkim * Intel Code.
752417024jkim *
762417024jkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
772417024jkim * Intel shall be used in advertising or otherwise to promote the sale, use or
782417024jkim * other dealings in products derived from or relating to the Covered Code
792417024jkim * without prior written authorization from Intel.
802417024jkim *
812417024jkim * 4. Disclaimer and Export Compliance
822417024jkim *
832417024jkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
842417024jkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
852417024jkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
862417024jkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
872417024jkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
882417024jkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
892417024jkim * PARTICULAR PURPOSE.
902417024jkim *
912417024jkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
922417024jkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
932417024jkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
942417024jkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
952417024jkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
962417024jkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
972417024jkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
982417024jkim * LIMITED REMEDY.
992417024jkim *
1002417024jkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
1012417024jkim * software or system incorporating such software without first obtaining any
1022417024jkim * required license or other approval from the U. S. Department of Commerce or
1032417024jkim * any other agency or department of the United States Government. In the
1042417024jkim * event Licensee exports any such software from the United States or
1052417024jkim * re-exports any such software from a foreign destination, Licensee shall
1062417024jkim * ensure that the distribution and export/re-export of the software is in
1072417024jkim * compliance with all laws, regulations, orders, or other restrictions of the
1082417024jkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1092417024jkim * any of its subsidiaries will export/re-export any technical data, process,
1102417024jkim * software, or service, directly or indirectly, to any country for which the
1112417024jkim * United States government or any agency thereof requires an export license,
1122417024jkim * other governmental approval, or letter of assurance, without first obtaining
1132417024jkim * such license, approval or letter.
1142417024jkim *
1152417024jkim *****************************************************************************
1162417024jkim *
1172417024jkim * Alternatively, you may choose to be licensed under the terms of the
1182417024jkim * following license:
1192417024jkim *
12077a98b4jkim * Redistribution and use in source and binary forms, with or without
12177a98b4jkim * modification, are permitted provided that the following conditions
12277a98b4jkim * are met:
12377a98b4jkim * 1. Redistributions of source code must retain the above copyright
12477a98b4jkim *    notice, this list of conditions, and the following disclaimer,
12577a98b4jkim *    without modification.
12677a98b4jkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12777a98b4jkim *    substantially similar to the "NO WARRANTY" disclaimer below
12877a98b4jkim *    ("Disclaimer") and any redistribution must be conditioned upon
12977a98b4jkim *    including a substantially similar Disclaimer requirement for further
13077a98b4jkim *    binary redistribution.
13177a98b4jkim * 3. Neither the names of the above-listed copyright holders nor the names
13277a98b4jkim *    of any contributors may be used to endorse or promote products derived
13377a98b4jkim *    from this software without specific prior written permission.
13477a98b4jkim *
13577a98b4jkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13677a98b4jkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1372417024jkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13877a98b4jkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1392417024jkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1402417024jkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1412417024jkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1422417024jkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1432417024jkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1442417024jkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1452417024jkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1462417024jkim *
1472417024jkim * Alternatively, you may choose to be licensed under the terms of the
1482417024jkim * GNU General Public License ("GPL") version 2 as published by the Free
1492417024jkim * Software Foundation.
1502417024jkim *
1512417024jkim *****************************************************************************/
15277a98b4jkim
15377a98b4jkim#ifndef _ACCLIB_H
15477a98b4jkim#define _ACCLIB_H
15577a98b4jkim
15677a98b4jkim
15777a98b4jkim/*
15877a98b4jkim * Prototypes and macros for local implementations of C library functions
15977a98b4jkim */
16077a98b4jkim
16177a98b4jkim/* is* functions. The AcpiGbl_Ctypes array is defined in utclib.c */
16277a98b4jkim
16377a98b4jkimextern const UINT8 AcpiGbl_Ctypes[];
16477a98b4jkim
16577a98b4jkim#define _ACPI_XA     0x00    /* extra alphabetic - not supported */
16677a98b4jkim#define _ACPI_XS     0x40    /* extra space */
16777a98b4jkim#define _ACPI_BB     0x00    /* BEL, BS, etc. - not supported */
16877a98b4jkim#define _ACPI_CN     0x20    /* CR, FF, HT, NL, VT */
16977a98b4jkim#define _ACPI_DI     0x04    /* '0'-'9' */
17077a98b4jkim#define _ACPI_LO     0x02    /* 'a'-'z' */
17177a98b4jkim#define _ACPI_PU     0x10    /* punctuation */
17277a98b4jkim#define _ACPI_SP     0x08    /* space, tab, CR, LF, VT, FF */
17377a98b4jkim#define _ACPI_UP     0x01    /* 'A'-'Z' */
17477a98b4jkim#define _ACPI_XD     0x80    /* '0'-'9', 'A'-'F', 'a'-'f' */
17577a98b4jkim
17677a98b4jkim#define isdigit(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_DI))
17777a98b4jkim#define isspace(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_SP))
17877a98b4jkim#define isxdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_XD))
17977a98b4jkim#define isupper(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_UP))
18077a98b4jkim#define islower(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO))
18177a98b4jkim#define isprint(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU))
18277a98b4jkim#define isalpha(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
18377a98b4jkim
18479f6e62jkim/* Error code */
18579f6e62jkim
18679f6e62jkim#define EPERM            1 /* Operation not permitted */
18779f6e62jkim#define ENOENT           2 /* No such file or directory */
18879f6e62jkim#define EINTR            4 /* Interrupted system call */
18979f6e62jkim#define EIO              5 /* I/O error */
19079f6e62jkim#define EBADF            9 /* Bad file number */
19179f6e62jkim#define EAGAIN          11 /* Try again */
19279f6e62jkim#define ENOMEM          12 /* Out of memory */
19379f6e62jkim#define EACCES          13 /* Permission denied */
19479f6e62jkim#define EFAULT          14 /* Bad address */
19579f6e62jkim#define EBUSY           16 /* Device or resource busy */
19679f6e62jkim#define EEXIST          17 /* File exists */
19779f6e62jkim#define ENODEV          19 /* No such device */
19879f6e62jkim#define EINVAL          22 /* Invalid argument */
19979f6e62jkim#define EPIPE           32 /* Broken pipe */
20079f6e62jkim#define ERANGE          34 /* Math result not representable */
20177a98b4jkim
20277a98b4jkim/* Strings */
20377a98b4jkim
20477a98b4jkimchar *
20577a98b4jkimstrcat (
20677a98b4jkim    char                    *DstString,
20777a98b4jkim    const char              *SrcString);
20877a98b4jkim
20977a98b4jkimchar *
21077a98b4jkimstrchr (
21177a98b4jkim    const char              *String,
21277a98b4jkim    int                     ch);
21377a98b4jkim
21477a98b4jkimchar *
2157662af1jkimstrpbrk (
2167662af1jkim    const char              *String,
2177662af1jkim    const char              *Delimiters);
2187662af1jkim
2197662af1jkimchar *
2207662af1jkimstrtok (
2217662af1jkim    char                    *String,
2227662af1jkim    const char              *Delimiters);
2237662af1jkim
2247662af1jkimchar *
22577a98b4jkimstrcpy (
22677a98b4jkim    char                    *DstString,
22777a98b4jkim    const char              *SrcString);
22877a98b4jkim
22977a98b4jkimint
23077a98b4jkimstrcmp (
23177a98b4jkim    const char              *String1,
23277a98b4jkim    const char              *String2);
23377a98b4jkim
23477a98b4jkimACPI_SIZE
23577a98b4jkimstrlen (
23677a98b4jkim    const char              *String);
23777a98b4jkim
23877a98b4jkimchar *
23977a98b4jkimstrncat (
24077a98b4jkim    char                    *DstString,
24177a98b4jkim    const char              *SrcString,
24277a98b4jkim    ACPI_SIZE               Count);
24377a98b4jkim
24477a98b4jkimint
24577a98b4jkimstrncmp (
24677a98b4jkim    const char              *String1,
24777a98b4jkim    const char              *String2,
24877a98b4jkim    ACPI_SIZE               Count);
24977a98b4jkim
25077a98b4jkimchar *
25177a98b4jkimstrncpy (
25277a98b4jkim    char                    *DstString,
25377a98b4jkim    const char              *SrcString,
25477a98b4jkim    ACPI_SIZE               Count);
25577a98b4jkim
25677a98b4jkimchar *
25777a98b4jkimstrstr (
25877a98b4jkim    char                    *String1,
25977a98b4jkim    char                    *String2);
26077a98b4jkim
26177a98b4jkim
26277a98b4jkim/* Conversion */
26377a98b4jkim
26477a98b4jkimUINT32
26577a98b4jkimstrtoul (
26677a98b4jkim    const char              *String,
26777a98b4jkim    char                    **Terminator,
26877a98b4jkim    UINT32                  Base);
26977a98b4jkim
27077a98b4jkim
27177a98b4jkim/* Memory */
27277a98b4jkim
27377a98b4jkimint
27477a98b4jkimmemcmp (
27577a98b4jkim    void                    *Buffer1,
27677a98b4jkim    void                    *Buffer2,
27777a98b4jkim    ACPI_SIZE               Count);
27877a98b4jkim
27977a98b4jkimvoid *
28077a98b4jkimmemcpy (
28177a98b4jkim    void                    *Dest,
28277a98b4jkim    const void              *Src,
28377a98b4jkim    ACPI_SIZE               Count);
28477a98b4jkim
28577a98b4jkimvoid *
2867662af1jkimmemmove (
2877662af1jkim    void                    *Dest,
2887662af1jkim    const void              *Src,
2897662af1jkim    ACPI_SIZE               Count);
2907662af1jkim
2917662af1jkimvoid *
29277a98b4jkimmemset (
29377a98b4jkim    void                    *Dest,
29477a98b4jkim    int                     Value,
29577a98b4jkim    ACPI_SIZE               Count);
29677a98b4jkim
29777a98b4jkim
29877a98b4jkim/* upper/lower case */
29977a98b4jkim
30077a98b4jkimint
30177a98b4jkimtolower (
30277a98b4jkim    int                     c);
30377a98b4jkim
30477a98b4jkimint
30577a98b4jkimtoupper (
30677a98b4jkim    int                     c);
30777a98b4jkim
30879f6e62jkim/*
30979f6e62jkim * utprint - printf/vprintf output functions
31079f6e62jkim */
31179f6e62jkimconst char *
31279f6e62jkimAcpiUtScanNumber (
31379f6e62jkim    const char              *String,
31479f6e62jkim    UINT64                  *NumberPtr);
31579f6e62jkim
31679f6e62jkimconst char *
31779f6e62jkimAcpiUtPrintNumber (
31879f6e62jkim    char                    *String,
31979f6e62jkim    UINT64                  Number);
32079f6e62jkim
32179f6e62jkimint
32279f6e62jkimvsnprintf (
32379f6e62jkim    char                    *String,
32479f6e62jkim    ACPI_SIZE               Size,
32579f6e62jkim    const char              *Format,
32679f6e62jkim    va_list                 Args);
32779f6e62jkim
32879f6e62jkimint
32979f6e62jkimsnprintf (
33079f6e62jkim    char                    *String,
33179f6e62jkim    ACPI_SIZE               Size,
33279f6e62jkim    const char              *Format,
33379f6e62jkim    ...);
33479f6e62jkim
33579f6e62jkimint
33679f6e62jkimsprintf (
33779f6e62jkim    char                    *String,
33879f6e62jkim    const char              *Format,
33979f6e62jkim    ...);
34079f6e62jkim
34179f6e62jkim#ifdef ACPI_APPLICATION
34279f6e62jkim#define SEEK_SET            0
34379f6e62jkim#define SEEK_CUR            1
34479f6e62jkim#define SEEK_END            2
34579f6e62jkim
34679f6e62jkim/*
34779f6e62jkim * NOTE: Currently we only need to update errno for file IOs. Other
34867c6829jkim *       Clibrary invocations in ACPICA do not make decisions according to
34979f6e62jkim *       the errno.
35079f6e62jkim */
35179f6e62jkimextern int errno;
35279f6e62jkim
3537662af1jkim#ifndef EOF
3547662af1jkim#define EOF                 (-1)
3557662af1jkim#endif
3567662af1jkim
3577662af1jkim#define putchar(c)          fputc(stdout, c)
3587662af1jkim#define getchar(c)          fgetc(stdin)
3597662af1jkim
36079f6e62jkimint
36179f6e62jkimvprintf (
36279f6e62jkim    const char              *Format,
36379f6e62jkim    va_list                 Args);
36479f6e62jkim
36579f6e62jkimint
36679f6e62jkimprintf (
36779f6e62jkim    const char              *Format,
36879f6e62jkim    ...);
36979f6e62jkim
37079f6e62jkimint
37179f6e62jkimvfprintf (
37279f6e62jkim    FILE                    *File,
37379f6e62jkim    const char              *Format,
37479f6e62jkim    va_list                 Args);
37579f6e62jkim
37679f6e62jkimint
37779f6e62jkimfprintf (
37879f6e62jkim    FILE                    *File,
37979f6e62jkim    const char              *Format,
38079f6e62jkim    ...);
38179f6e62jkim
38279f6e62jkimFILE *
38379f6e62jkimfopen (
38479f6e62jkim    const char              *Path,
38579f6e62jkim    const char              *Modes);
38679f6e62jkim
38779f6e62jkimvoid
38879f6e62jkimfclose (
38979f6e62jkim    FILE                    *File);
39079f6e62jkim
39179f6e62jkimint
39279f6e62jkimfread (
39379f6e62jkim    void                    *Buffer,
39479f6e62jkim    ACPI_SIZE               Size,
39579f6e62jkim    ACPI_SIZE               Count,
39679f6e62jkim    FILE                    *File);
39779f6e62jkim
39879f6e62jkimint
39979f6e62jkimfwrite (
40079f6e62jkim    void                    *Buffer,
40179f6e62jkim    ACPI_SIZE               Size,
40279f6e62jkim    ACPI_SIZE               Count,
40379f6e62jkim    FILE                    *File);
40479f6e62jkim
40579f6e62jkimint
40679f6e62jkimfseek (
40779f6e62jkim    FILE                    *File,
40879f6e62jkim    long                    Offset,
40979f6e62jkim    int                     From);
41079f6e62jkim
41179f6e62jkimlong
41279f6e62jkimftell (
41379f6e62jkim    FILE                    *File);
4147662af1jkim
4157662af1jkimint
4167662af1jkimfgetc (
4177662af1jkim    FILE                    *File);
4187662af1jkim
4197662af1jkimint
4207662af1jkimfputc (
4217662af1jkim    FILE                    *File,
4227662af1jkim    char                    c);
4237662af1jkim
4247662af1jkimchar *
4257662af1jkimfgets (
4267662af1jkim    char                    *s,
4277662af1jkim    ACPI_SIZE               Size,
4287662af1jkim    FILE                    *File);
42979f6e62jkim#endif
43079f6e62jkim
43177a98b4jkim#endif /* _ACCLIB_H */
432