acclib.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /******************************************************************************
  2. *
  3. * Name: acclib.h -- C library support. Prototypes for the (optional) local
  4. * implementations of required C library functions.
  5. *
  6. *****************************************************************************/
  7. /******************************************************************************
  8. *
  9. * 1. Copyright Notice
  10. *
  11. * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
  12. * All rights reserved.
  13. *
  14. * 2. License
  15. *
  16. * 2.1. This is your license from Intel Corp. under its intellectual property
  17. * rights. You may have additional license terms from the party that provided
  18. * you this software, covering your right to use that party's intellectual
  19. * property rights.
  20. *
  21. * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
  22. * copy of the source code appearing in this file ("Covered Code") an
  23. * irrevocable, perpetual, worldwide license under Intel's copyrights in the
  24. * base code distributed originally by Intel ("Original Intel Code") to copy,
  25. * make derivatives, distribute, use and display any portion of the Covered
  26. * Code in any form, with the right to sublicense such rights; and
  27. *
  28. * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
  29. * license (with the right to sublicense), under only those claims of Intel
  30. * 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 thereof
  32. * solely to the minimum extent necessary to exercise the above copyright
  33. * license, and in no event shall the patent license extend to any additions
  34. * to or modifications of the Original Intel Code. No other license or right
  35. * is granted directly or by implication, estoppel or otherwise;
  36. *
  37. * The above copyright and patent license is granted only if the following
  38. * conditions are met:
  39. *
  40. * 3. Conditions
  41. *
  42. * 3.1. Redistribution of Source with Rights to Further Distribute Source.
  43. * Redistribution of source code of any substantial portion of the Covered
  44. * Code or modification with rights to further distribute source must include
  45. * 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 to
  48. * contain a file documenting the changes Licensee made to create that Covered
  49. * Code and the date of any change. Licensee must include in that file the
  50. * documentation of any changes made by any predecessor Licensee. Licensee
  51. * 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 Covered
  56. * Code or modification without rights to further distribute source must
  57. * include the following Disclaimer and Export Compliance provision in the
  58. * documentation and/or other materials provided with distribution. In
  59. * addition, Licensee may not authorize further sublicense of source of any
  60. * portion of the Covered Code, and must include terms to the effect that the
  61. * license from Licensee to its licensee is limited to the intellectual
  62. * property embodied in the software Licensee provides to its licensee, and
  63. * not to intellectual property embodied in modifications its licensee may
  64. * make.
  65. *
  66. * 3.3. Redistribution of Executable. Redistribution in executable form of any
  67. * substantial portion of the Covered Code or modification must reproduce the
  68. * above Copyright Notice, and the following Disclaimer and Export Compliance
  69. * provision in the documentation and/or other materials provided with the
  70. * distribution.
  71. *
  72. * 3.4. Intel retains all right, title, and interest in and to the Original
  73. * Intel Code.
  74. *
  75. * 3.5. Neither the name Intel nor any other trademark owned or controlled by
  76. * Intel shall be used in advertising or otherwise to promote the sale, use or
  77. * other dealings in products derived from or relating to the Covered Code
  78. * without prior written authorization from Intel.
  79. *
  80. * 4. Disclaimer and Export Compliance
  81. *
  82. * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
  83. * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
  84. * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
  85. * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
  86. * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
  87. * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
  88. * PARTICULAR PURPOSE.
  89. *
  90. * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
  91. * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
  92. * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
  93. * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
  94. * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
  95. * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
  96. * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
  97. * LIMITED REMEDY.
  98. *
  99. * 4.3. Licensee shall not export, either directly or indirectly, any of this
  100. * software or system incorporating such software without first obtaining any
  101. * required license or other approval from the U. S. Department of Commerce or
  102. * any other agency or department of the United States Government. In the
  103. * event Licensee exports any such software from the United States or
  104. * re-exports any such software from a foreign destination, Licensee shall
  105. * ensure that the distribution and export/re-export of the software is in
  106. * compliance with all laws, regulations, orders, or other restrictions of the
  107. * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  108. * any of its subsidiaries will export/re-export any technical data, process,
  109. * software, or service, directly or indirectly, to any country for which the
  110. * United States government or any agency thereof requires an export license,
  111. * other governmental approval, or letter of assurance, without first obtaining
  112. * such license, approval or letter.
  113. *
  114. *****************************************************************************
  115. *
  116. * Alternatively, you may choose to be licensed under the terms of the
  117. * following license:
  118. *
  119. * Redistribution and use in source and binary forms, with or without
  120. * modification, are permitted provided that the following conditions
  121. * are met:
  122. * 1. Redistributions of source code must retain the above copyright
  123. * notice, this list of conditions, and the following disclaimer,
  124. * without modification.
  125. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  126. * substantially similar to the "NO WARRANTY" disclaimer below
  127. * ("Disclaimer") and any redistribution must be conditioned upon
  128. * including a substantially similar Disclaimer requirement for further
  129. * binary redistribution.
  130. * 3. Neither the names of the above-listed copyright holders nor the names
  131. * of any contributors may be used to endorse or promote products derived
  132. * from this software without specific prior written permission.
  133. *
  134. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  135. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  136. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  137. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  138. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  139. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  140. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  141. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  142. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  143. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  144. * 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 the
  147. * GNU General Public License ("GPL") version 2 as published by the Free
  148. * Software Foundation.
  149. *
  150. *****************************************************************************/
  151. #ifndef _ACCLIB_H
  152. #define _ACCLIB_H
  153. /*
  154. * Prototypes and macros for local implementations of C library functions
  155. */
  156. /* is* functions. The AcpiGbl_Ctypes array is defined in utclib.c */
  157. extern const UINT8 AcpiGbl_Ctypes[];
  158. #define _ACPI_XA 0x00 /* extra alphabetic - not supported */
  159. #define _ACPI_XS 0x40 /* extra space */
  160. #define _ACPI_BB 0x00 /* BEL, BS, etc. - not supported */
  161. #define _ACPI_CN 0x20 /* CR, FF, HT, NL, VT */
  162. #define _ACPI_DI 0x04 /* '0'-'9' */
  163. #define _ACPI_LO 0x02 /* 'a'-'z' */
  164. #define _ACPI_PU 0x10 /* punctuation */
  165. #define _ACPI_SP 0x08 /* space, tab, CR, LF, VT, FF */
  166. #define _ACPI_UP 0x01 /* 'A'-'Z' */
  167. #define _ACPI_XD 0x80 /* '0'-'9', 'A'-'F', 'a'-'f' */
  168. #define isdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_DI))
  169. #define isspace(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_SP))
  170. #define isxdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_XD))
  171. #define isupper(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_UP))
  172. #define islower(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO))
  173. #define isprint(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU))
  174. #define isalpha(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
  175. /* Error code */
  176. #define EPERM 1 /* Operation not permitted */
  177. #define ENOENT 2 /* No such file or directory */
  178. #define EINTR 4 /* Interrupted system call */
  179. #define EIO 5 /* I/O error */
  180. #define EBADF 9 /* Bad file number */
  181. #define EAGAIN 11 /* Try again */
  182. #define ENOMEM 12 /* Out of memory */
  183. #define EACCES 13 /* Permission denied */
  184. #define EFAULT 14 /* Bad address */
  185. #define EBUSY 16 /* Device or resource busy */
  186. #define EEXIST 17 /* File exists */
  187. #define ENODEV 19 /* No such device */
  188. #define EINVAL 22 /* Invalid argument */
  189. #define EPIPE 32 /* Broken pipe */
  190. #define ERANGE 34 /* Math result not representable */
  191. /* Strings */
  192. char *
  193. strcat (
  194. char *DstString,
  195. const char *SrcString);
  196. char *
  197. strchr (
  198. const char *String,
  199. int ch);
  200. char *
  201. strpbrk (
  202. const char *String,
  203. const char *Delimiters);
  204. char *
  205. strtok (
  206. char *String,
  207. const char *Delimiters);
  208. char *
  209. strcpy (
  210. char *DstString,
  211. const char *SrcString);
  212. int
  213. strcmp (
  214. const char *String1,
  215. const char *String2);
  216. ACPI_SIZE
  217. strlen (
  218. const char *String);
  219. char *
  220. strncat (
  221. char *DstString,
  222. const char *SrcString,
  223. ACPI_SIZE Count);
  224. int
  225. strncmp (
  226. const char *String1,
  227. const char *String2,
  228. ACPI_SIZE Count);
  229. char *
  230. strncpy (
  231. char *DstString,
  232. const char *SrcString,
  233. ACPI_SIZE Count);
  234. char *
  235. strstr (
  236. char *String1,
  237. char *String2);
  238. /* Conversion */
  239. UINT32
  240. strtoul (
  241. const char *String,
  242. char **Terminator,
  243. UINT32 Base);
  244. /* Memory */
  245. int
  246. memcmp (
  247. void *Buffer1,
  248. void *Buffer2,
  249. ACPI_SIZE Count);
  250. void *
  251. memcpy (
  252. void *Dest,
  253. const void *Src,
  254. ACPI_SIZE Count);
  255. void *
  256. memmove (
  257. void *Dest,
  258. const void *Src,
  259. ACPI_SIZE Count);
  260. void *
  261. memset (
  262. void *Dest,
  263. int Value,
  264. ACPI_SIZE Count);
  265. /* upper/lower case */
  266. int
  267. tolower (
  268. int c);
  269. int
  270. toupper (
  271. int c);
  272. /*
  273. * utprint - printf/vprintf output functions
  274. */
  275. const char *
  276. AcpiUtScanNumber (
  277. const char *String,
  278. UINT64 *NumberPtr);
  279. const char *
  280. AcpiUtPrintNumber (
  281. char *String,
  282. UINT64 Number);
  283. int
  284. vsnprintf (
  285. char *String,
  286. ACPI_SIZE Size,
  287. const char *Format,
  288. va_list Args);
  289. int
  290. snprintf (
  291. char *String,
  292. ACPI_SIZE Size,
  293. const char *Format,
  294. ...);
  295. int
  296. sprintf (
  297. char *String,
  298. const char *Format,
  299. ...);
  300. #ifdef ACPI_APPLICATION
  301. #define SEEK_SET 0
  302. #define SEEK_CUR 1
  303. #define SEEK_END 2
  304. /*
  305. * NOTE: Currently we only need to update errno for file IOs. Other
  306. * Clibrary invocations in ACPICA do not make descisions according to
  307. * the errno.
  308. */
  309. extern int errno;
  310. #ifndef EOF
  311. #define EOF (-1)
  312. #endif
  313. #define putchar(c) fputc(stdout, c)
  314. #define getchar(c) fgetc(stdin)
  315. int
  316. vprintf (
  317. const char *Format,
  318. va_list Args);
  319. int
  320. printf (
  321. const char *Format,
  322. ...);
  323. int
  324. vfprintf (
  325. FILE *File,
  326. const char *Format,
  327. va_list Args);
  328. int
  329. fprintf (
  330. FILE *File,
  331. const char *Format,
  332. ...);
  333. FILE *
  334. fopen (
  335. const char *Path,
  336. const char *Modes);
  337. void
  338. fclose (
  339. FILE *File);
  340. int
  341. fread (
  342. void *Buffer,
  343. ACPI_SIZE Size,
  344. ACPI_SIZE Count,
  345. FILE *File);
  346. int
  347. fwrite (
  348. void *Buffer,
  349. ACPI_SIZE Size,
  350. ACPI_SIZE Count,
  351. FILE *File);
  352. int
  353. fseek (
  354. FILE *File,
  355. long Offset,
  356. int From);
  357. long
  358. ftell (
  359. FILE *File);
  360. int
  361. fgetc (
  362. FILE *File);
  363. int
  364. fputc (
  365. FILE *File,
  366. char c);
  367. char *
  368. fgets (
  369. char *s,
  370. ACPI_SIZE Size,
  371. FILE *File);
  372. #endif
  373. #endif /* _ACCLIB_H */