Path: blob/main/sys/contrib/dev/acpica/include/acclib.h
48287 views
/******************************************************************************1*2* Name: acclib.h -- C library support. Prototypes for the (optional) local3* implementations of required C library functions.4*5*****************************************************************************/67/******************************************************************************8*9* 1. Copyright Notice10*11* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.12* All rights reserved.13*14* 2. License15*16* 2.1. This is your license from Intel Corp. under its intellectual property17* rights. You may have additional license terms from the party that provided18* you this software, covering your right to use that party's intellectual19* property rights.20*21* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a22* copy of the source code appearing in this file ("Covered Code") an23* irrevocable, perpetual, worldwide license under Intel's copyrights in the24* base code distributed originally by Intel ("Original Intel Code") to copy,25* make derivatives, distribute, use and display any portion of the Covered26* Code in any form, with the right to sublicense such rights; and27*28* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent29* license (with the right to sublicense), under only those claims of Intel30* patents that are infringed by the Original Intel Code, to make, use, sell,31* offer to sell, and import the Covered Code and derivative works thereof32* solely to the minimum extent necessary to exercise the above copyright33* license, and in no event shall the patent license extend to any additions34* to or modifications of the Original Intel Code. No other license or right35* is granted directly or by implication, estoppel or otherwise;36*37* The above copyright and patent license is granted only if the following38* conditions are met:39*40* 3. Conditions41*42* 3.1. Redistribution of Source with Rights to Further Distribute Source.43* Redistribution of source code of any substantial portion of the Covered44* Code or modification with rights to further distribute source must include45* the above Copyright Notice, the above License, this list of Conditions,46* and the following Disclaimer and Export Compliance provision. In addition,47* Licensee must cause all Covered Code to which Licensee contributes to48* contain a file documenting the changes Licensee made to create that Covered49* Code and the date of any change. Licensee must include in that file the50* documentation of any changes made by any predecessor Licensee. Licensee51* must include a prominent statement that the modification is derived,52* directly or indirectly, from Original Intel Code.53*54* 3.2. Redistribution of Source with no Rights to Further Distribute Source.55* Redistribution of source code of any substantial portion of the Covered56* Code or modification without rights to further distribute source must57* include the following Disclaimer and Export Compliance provision in the58* documentation and/or other materials provided with distribution. In59* addition, Licensee may not authorize further sublicense of source of any60* portion of the Covered Code, and must include terms to the effect that the61* license from Licensee to its licensee is limited to the intellectual62* property embodied in the software Licensee provides to its licensee, and63* not to intellectual property embodied in modifications its licensee may64* make.65*66* 3.3. Redistribution of Executable. Redistribution in executable form of any67* substantial portion of the Covered Code or modification must reproduce the68* above Copyright Notice, and the following Disclaimer and Export Compliance69* provision in the documentation and/or other materials provided with the70* distribution.71*72* 3.4. Intel retains all right, title, and interest in and to the Original73* Intel Code.74*75* 3.5. Neither the name Intel nor any other trademark owned or controlled by76* Intel shall be used in advertising or otherwise to promote the sale, use or77* other dealings in products derived from or relating to the Covered Code78* without prior written authorization from Intel.79*80* 4. Disclaimer and Export Compliance81*82* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED83* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE84* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,85* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY86* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY87* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A88* PARTICULAR PURPOSE.89*90* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES91* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR92* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,93* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY94* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL95* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS96* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY97* LIMITED REMEDY.98*99* 4.3. Licensee shall not export, either directly or indirectly, any of this100* software or system incorporating such software without first obtaining any101* required license or other approval from the U. S. Department of Commerce or102* any other agency or department of the United States Government. In the103* event Licensee exports any such software from the United States or104* re-exports any such software from a foreign destination, Licensee shall105* ensure that the distribution and export/re-export of the software is in106* compliance with all laws, regulations, orders, or other restrictions of the107* U.S. Export Administration Regulations. Licensee agrees that neither it nor108* any of its subsidiaries will export/re-export any technical data, process,109* software, or service, directly or indirectly, to any country for which the110* United States government or any agency thereof requires an export license,111* other governmental approval, or letter of assurance, without first obtaining112* such license, approval or letter.113*114*****************************************************************************115*116* Alternatively, you may choose to be licensed under the terms of the117* following license:118*119* Redistribution and use in source and binary forms, with or without120* modification, are permitted provided that the following conditions121* are met:122* 1. Redistributions of source code must retain the above copyright123* notice, this list of conditions, and the following disclaimer,124* without modification.125* 2. Redistributions in binary form must reproduce at minimum a disclaimer126* substantially similar to the "NO WARRANTY" disclaimer below127* ("Disclaimer") and any redistribution must be conditioned upon128* including a substantially similar Disclaimer requirement for further129* binary redistribution.130* 3. Neither the names of the above-listed copyright holders nor the names131* of any contributors may be used to endorse or promote products derived132* from this software without specific prior written permission.133*134* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS135* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT136* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR137* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT138* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,139* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT140* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,141* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY142* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT143* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE144* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.145*146* Alternatively, you may choose to be licensed under the terms of the147* GNU General Public License ("GPL") version 2 as published by the Free148* Software Foundation.149*150*****************************************************************************/151152#ifndef _ACCLIB_H153#define _ACCLIB_H154155156/*157* Prototypes and macros for local implementations of C library functions158*/159160/* is* functions. The AcpiGbl_Ctypes array is defined in utclib.c */161162extern const UINT8 AcpiGbl_Ctypes[];163164#define _ACPI_XA 0x00 /* extra alphabetic - not supported */165#define _ACPI_XS 0x40 /* extra space */166#define _ACPI_BB 0x00 /* BEL, BS, etc. - not supported */167#define _ACPI_CN 0x20 /* CR, FF, HT, NL, VT */168#define _ACPI_DI 0x04 /* '0'-'9' */169#define _ACPI_LO 0x02 /* 'a'-'z' */170#define _ACPI_PU 0x10 /* punctuation */171#define _ACPI_SP 0x08 /* space, tab, CR, LF, VT, FF */172#define _ACPI_UP 0x01 /* 'A'-'Z' */173#define _ACPI_XD 0x80 /* '0'-'9', 'A'-'F', 'a'-'f' */174175#define isdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_DI))176#define isspace(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_SP))177#define isxdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_XD))178#define isupper(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_UP))179#define islower(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO))180#define isprint(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU))181#define isalpha(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))182183/* Error code */184185#define EPERM 1 /* Operation not permitted */186#define ENOENT 2 /* No such file or directory */187#define EINTR 4 /* Interrupted system call */188#define EIO 5 /* I/O error */189#define EBADF 9 /* Bad file number */190#define EAGAIN 11 /* Try again */191#define ENOMEM 12 /* Out of memory */192#define EACCES 13 /* Permission denied */193#define EFAULT 14 /* Bad address */194#define EBUSY 16 /* Device or resource busy */195#define EEXIST 17 /* File exists */196#define ENODEV 19 /* No such device */197#define EINVAL 22 /* Invalid argument */198#define EPIPE 32 /* Broken pipe */199#define ERANGE 34 /* Math result not representable */200201/* Strings */202203char *204strcat (205char *DstString,206const char *SrcString);207208char *209strchr (210const char *String,211int ch);212213char *214strpbrk (215const char *String,216const char *Delimiters);217218char *219strtok (220char *String,221const char *Delimiters);222223char *224strcpy (225char *DstString,226const char *SrcString);227228int229strcmp (230const char *String1,231const char *String2);232233ACPI_SIZE234strlen (235const char *String);236237char *238strncat (239char *DstString,240const char *SrcString,241ACPI_SIZE Count);242243int244strncmp (245const char *String1,246const char *String2,247ACPI_SIZE Count);248249char *250strncpy (251char *DstString,252const char *SrcString,253ACPI_SIZE Count);254255char *256strstr (257char *String1,258char *String2);259260261/* Conversion */262263UINT32264strtoul (265const char *String,266char **Terminator,267UINT32 Base);268269270/* Memory */271272int273memcmp (274void *Buffer1,275void *Buffer2,276ACPI_SIZE Count);277278void *279memcpy (280void *Dest,281const void *Src,282ACPI_SIZE Count);283284void *285memmove (286void *Dest,287const void *Src,288ACPI_SIZE Count);289290void *291memset (292void *Dest,293int Value,294ACPI_SIZE Count);295296297/* upper/lower case */298299int300tolower (301int c);302303int304toupper (305int c);306307/*308* utprint - printf/vprintf output functions309*/310const char *311AcpiUtScanNumber (312const char *String,313UINT64 *NumberPtr);314315const char *316AcpiUtPrintNumber (317char *String,318UINT64 Number);319320int321vsnprintf (322char *String,323ACPI_SIZE Size,324const char *Format,325va_list Args);326327int328snprintf (329char *String,330ACPI_SIZE Size,331const char *Format,332...);333334int335sprintf (336char *String,337const char *Format,338...);339340#ifdef ACPI_APPLICATION341#define SEEK_SET 0342#define SEEK_CUR 1343#define SEEK_END 2344345/*346* NOTE: Currently we only need to update errno for file IOs. Other347* Clibrary invocations in ACPICA do not make decisions according to348* the errno.349*/350extern int errno;351352#ifndef EOF353#define EOF (-1)354#endif355356#define putchar(c) fputc(stdout, c)357#define getchar(c) fgetc(stdin)358359int360vprintf (361const char *Format,362va_list Args);363364int365printf (366const char *Format,367...);368369int370vfprintf (371FILE *File,372const char *Format,373va_list Args);374375int376fprintf (377FILE *File,378const char *Format,379...);380381FILE *382fopen (383const char *Path,384const char *Modes);385386void387fclose (388FILE *File);389390int391fread (392void *Buffer,393ACPI_SIZE Size,394ACPI_SIZE Count,395FILE *File);396397int398fwrite (399void *Buffer,400ACPI_SIZE Size,401ACPI_SIZE Count,402FILE *File);403404int405fseek (406FILE *File,407long Offset,408int From);409410long411ftell (412FILE *File);413414int415fgetc (416FILE *File);417418int419fputc (420FILE *File,421char c);422423char *424fgets (425char *s,426ACPI_SIZE Size,427FILE *File);428#endif429430#endif /* _ACCLIB_H */431432433