acclib.h revision 1.1.1.3 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Name: acclib.h -- C library support. Prototypes for the (optional) local
4 1.1 christos * implementations of required C library functions.
5 1.1 christos *
6 1.1 christos *****************************************************************************/
7 1.1 christos
8 1.1 christos /*
9 1.1.1.2 christos * Copyright (C) 2000 - 2016, Intel Corp.
10 1.1 christos * All rights reserved.
11 1.1 christos *
12 1.1 christos * Redistribution and use in source and binary forms, with or without
13 1.1 christos * modification, are permitted provided that the following conditions
14 1.1 christos * are met:
15 1.1 christos * 1. Redistributions of source code must retain the above copyright
16 1.1 christos * notice, this list of conditions, and the following disclaimer,
17 1.1 christos * without modification.
18 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1 christos * including a substantially similar Disclaimer requirement for further
22 1.1 christos * binary redistribution.
23 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1 christos * of any contributors may be used to endorse or promote products derived
25 1.1 christos * from this software without specific prior written permission.
26 1.1 christos *
27 1.1 christos * Alternatively, this software may be distributed under the terms of the
28 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1 christos * Software Foundation.
30 1.1 christos *
31 1.1 christos * NO WARRANTY
32 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
43 1.1 christos */
44 1.1 christos
45 1.1 christos #ifndef _ACCLIB_H
46 1.1 christos #define _ACCLIB_H
47 1.1 christos
48 1.1 christos
49 1.1 christos /*
50 1.1 christos * Prototypes and macros for local implementations of C library functions
51 1.1 christos */
52 1.1 christos
53 1.1 christos /* is* functions. The AcpiGbl_Ctypes array is defined in utclib.c */
54 1.1 christos
55 1.1 christos extern const UINT8 AcpiGbl_Ctypes[];
56 1.1 christos
57 1.1 christos #define _ACPI_XA 0x00 /* extra alphabetic - not supported */
58 1.1 christos #define _ACPI_XS 0x40 /* extra space */
59 1.1 christos #define _ACPI_BB 0x00 /* BEL, BS, etc. - not supported */
60 1.1 christos #define _ACPI_CN 0x20 /* CR, FF, HT, NL, VT */
61 1.1 christos #define _ACPI_DI 0x04 /* '0'-'9' */
62 1.1 christos #define _ACPI_LO 0x02 /* 'a'-'z' */
63 1.1 christos #define _ACPI_PU 0x10 /* punctuation */
64 1.1 christos #define _ACPI_SP 0x08 /* space, tab, CR, LF, VT, FF */
65 1.1 christos #define _ACPI_UP 0x01 /* 'A'-'Z' */
66 1.1 christos #define _ACPI_XD 0x80 /* '0'-'9', 'A'-'F', 'a'-'f' */
67 1.1 christos
68 1.1 christos #define isdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_DI))
69 1.1 christos #define isspace(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_SP))
70 1.1 christos #define isxdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_XD))
71 1.1 christos #define isupper(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_UP))
72 1.1 christos #define islower(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO))
73 1.1 christos #define isprint(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU))
74 1.1 christos #define isalpha(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
75 1.1 christos
76 1.1.1.3 christos /* Error code */
77 1.1.1.3 christos
78 1.1.1.3 christos #define EPERM 1 /* Operation not permitted */
79 1.1.1.3 christos #define ENOENT 2 /* No such file or directory */
80 1.1.1.3 christos #define EINTR 4 /* Interrupted system call */
81 1.1.1.3 christos #define EIO 5 /* I/O error */
82 1.1.1.3 christos #define EBADF 9 /* Bad file number */
83 1.1.1.3 christos #define EAGAIN 11 /* Try again */
84 1.1.1.3 christos #define ENOMEM 12 /* Out of memory */
85 1.1.1.3 christos #define EACCES 13 /* Permission denied */
86 1.1.1.3 christos #define EFAULT 14 /* Bad address */
87 1.1.1.3 christos #define EBUSY 16 /* Device or resource busy */
88 1.1.1.3 christos #define EEXIST 17 /* File exists */
89 1.1.1.3 christos #define ENODEV 19 /* No such device */
90 1.1.1.3 christos #define EINVAL 22 /* Invalid argument */
91 1.1.1.3 christos #define EPIPE 32 /* Broken pipe */
92 1.1.1.3 christos #define ERANGE 34 /* Math result not representable */
93 1.1 christos
94 1.1 christos /* Strings */
95 1.1 christos
96 1.1 christos char *
97 1.1 christos strcat (
98 1.1 christos char *DstString,
99 1.1 christos const char *SrcString);
100 1.1 christos
101 1.1 christos char *
102 1.1 christos strchr (
103 1.1 christos const char *String,
104 1.1 christos int ch);
105 1.1 christos
106 1.1 christos char *
107 1.1 christos strcpy (
108 1.1 christos char *DstString,
109 1.1 christos const char *SrcString);
110 1.1 christos
111 1.1 christos int
112 1.1 christos strcmp (
113 1.1 christos const char *String1,
114 1.1 christos const char *String2);
115 1.1 christos
116 1.1 christos ACPI_SIZE
117 1.1 christos strlen (
118 1.1 christos const char *String);
119 1.1 christos
120 1.1 christos char *
121 1.1 christos strncat (
122 1.1 christos char *DstString,
123 1.1 christos const char *SrcString,
124 1.1 christos ACPI_SIZE Count);
125 1.1 christos
126 1.1 christos int
127 1.1 christos strncmp (
128 1.1 christos const char *String1,
129 1.1 christos const char *String2,
130 1.1 christos ACPI_SIZE Count);
131 1.1 christos
132 1.1 christos char *
133 1.1 christos strncpy (
134 1.1 christos char *DstString,
135 1.1 christos const char *SrcString,
136 1.1 christos ACPI_SIZE Count);
137 1.1 christos
138 1.1 christos char *
139 1.1 christos strstr (
140 1.1 christos char *String1,
141 1.1 christos char *String2);
142 1.1 christos
143 1.1 christos
144 1.1 christos /* Conversion */
145 1.1 christos
146 1.1 christos UINT32
147 1.1 christos strtoul (
148 1.1 christos const char *String,
149 1.1 christos char **Terminator,
150 1.1 christos UINT32 Base);
151 1.1 christos
152 1.1 christos
153 1.1 christos /* Memory */
154 1.1 christos
155 1.1 christos int
156 1.1 christos memcmp (
157 1.1 christos void *Buffer1,
158 1.1 christos void *Buffer2,
159 1.1 christos ACPI_SIZE Count);
160 1.1 christos
161 1.1 christos void *
162 1.1 christos memcpy (
163 1.1 christos void *Dest,
164 1.1 christos const void *Src,
165 1.1 christos ACPI_SIZE Count);
166 1.1 christos
167 1.1 christos void *
168 1.1 christos memset (
169 1.1 christos void *Dest,
170 1.1 christos int Value,
171 1.1 christos ACPI_SIZE Count);
172 1.1 christos
173 1.1 christos
174 1.1 christos /* upper/lower case */
175 1.1 christos
176 1.1 christos int
177 1.1 christos tolower (
178 1.1 christos int c);
179 1.1 christos
180 1.1 christos int
181 1.1 christos toupper (
182 1.1 christos int c);
183 1.1 christos
184 1.1.1.3 christos /*
185 1.1.1.3 christos * utprint - printf/vprintf output functions
186 1.1.1.3 christos */
187 1.1.1.3 christos const char *
188 1.1.1.3 christos AcpiUtScanNumber (
189 1.1.1.3 christos const char *String,
190 1.1.1.3 christos UINT64 *NumberPtr);
191 1.1.1.3 christos
192 1.1.1.3 christos const char *
193 1.1.1.3 christos AcpiUtPrintNumber (
194 1.1.1.3 christos char *String,
195 1.1.1.3 christos UINT64 Number);
196 1.1.1.3 christos
197 1.1.1.3 christos int
198 1.1.1.3 christos vsnprintf (
199 1.1.1.3 christos char *String,
200 1.1.1.3 christos ACPI_SIZE Size,
201 1.1.1.3 christos const char *Format,
202 1.1.1.3 christos va_list Args);
203 1.1.1.3 christos
204 1.1.1.3 christos int
205 1.1.1.3 christos snprintf (
206 1.1.1.3 christos char *String,
207 1.1.1.3 christos ACPI_SIZE Size,
208 1.1.1.3 christos const char *Format,
209 1.1.1.3 christos ...);
210 1.1.1.3 christos
211 1.1.1.3 christos int
212 1.1.1.3 christos sprintf (
213 1.1.1.3 christos char *String,
214 1.1.1.3 christos const char *Format,
215 1.1.1.3 christos ...);
216 1.1.1.3 christos
217 1.1.1.3 christos #ifdef ACPI_APPLICATION
218 1.1.1.3 christos #define SEEK_SET 0
219 1.1.1.3 christos #define SEEK_CUR 1
220 1.1.1.3 christos #define SEEK_END 2
221 1.1.1.3 christos
222 1.1.1.3 christos /*
223 1.1.1.3 christos * NOTE: Currently we only need to update errno for file IOs. Other
224 1.1.1.3 christos * Clibrary invocations in ACPICA do not make descisions according to
225 1.1.1.3 christos * the errno.
226 1.1.1.3 christos */
227 1.1.1.3 christos extern int errno;
228 1.1.1.3 christos
229 1.1.1.3 christos int
230 1.1.1.3 christos vprintf (
231 1.1.1.3 christos const char *Format,
232 1.1.1.3 christos va_list Args);
233 1.1.1.3 christos
234 1.1.1.3 christos int
235 1.1.1.3 christos printf (
236 1.1.1.3 christos const char *Format,
237 1.1.1.3 christos ...);
238 1.1.1.3 christos
239 1.1.1.3 christos int
240 1.1.1.3 christos vfprintf (
241 1.1.1.3 christos FILE *File,
242 1.1.1.3 christos const char *Format,
243 1.1.1.3 christos va_list Args);
244 1.1.1.3 christos
245 1.1.1.3 christos int
246 1.1.1.3 christos fprintf (
247 1.1.1.3 christos FILE *File,
248 1.1.1.3 christos const char *Format,
249 1.1.1.3 christos ...);
250 1.1.1.3 christos
251 1.1.1.3 christos FILE *
252 1.1.1.3 christos fopen (
253 1.1.1.3 christos const char *Path,
254 1.1.1.3 christos const char *Modes);
255 1.1.1.3 christos
256 1.1.1.3 christos void
257 1.1.1.3 christos fclose (
258 1.1.1.3 christos FILE *File);
259 1.1.1.3 christos
260 1.1.1.3 christos int
261 1.1.1.3 christos fread (
262 1.1.1.3 christos void *Buffer,
263 1.1.1.3 christos ACPI_SIZE Size,
264 1.1.1.3 christos ACPI_SIZE Count,
265 1.1.1.3 christos FILE *File);
266 1.1.1.3 christos
267 1.1.1.3 christos int
268 1.1.1.3 christos fwrite (
269 1.1.1.3 christos void *Buffer,
270 1.1.1.3 christos ACPI_SIZE Size,
271 1.1.1.3 christos ACPI_SIZE Count,
272 1.1.1.3 christos FILE *File);
273 1.1.1.3 christos
274 1.1.1.3 christos int
275 1.1.1.3 christos fseek (
276 1.1.1.3 christos FILE *File,
277 1.1.1.3 christos long Offset,
278 1.1.1.3 christos int From);
279 1.1.1.3 christos
280 1.1.1.3 christos long
281 1.1.1.3 christos ftell (
282 1.1.1.3 christos FILE *File);
283 1.1.1.3 christos #endif
284 1.1.1.3 christos
285 1.1 christos #endif /* _ACCLIB_H */
286