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