cint_porting.h (7154B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: cint_porting.h 8 * Purpose: CINT porting interfaces 9 */ 10 11 #ifndef __CINT_PORTING_H__ 12 #define __CINT_PORTING_H__ 13 14 #include "cint_config.h" 15 16 /* 17 * The following portability macros must be defined 18 * before your can build the interpreter. 19 */ 20 21 #if CINT_CONFIG_INCLUDE_STDLIB == 1 22 23 /* 24 * Standard C Library compatibility 25 */ 26 27 #include <stdlib.h> 28 #include <stdio.h> 29 #include <string.h> 30 #include <stdarg.h> 31 32 #ifndef CINT_PRINTF 33 #define CINT_PRINTF printf 34 #endif 35 36 #ifndef CINT_FPRINTF 37 #define CINT_FPRINTF fprintf 38 #endif 39 40 #ifndef CINT_VPRINTF 41 #define CINT_VPRINTF vprintf 42 #endif 43 44 #ifndef CINT_MALLOC 45 #define CINT_MALLOC(sz) malloc(sz) 46 #endif 47 48 #ifndef CINT_REALLOC 49 #define CINT_REALLOC realloc 50 #endif 51 52 #ifndef CINT_FREE 53 #define CINT_FREE free 54 #endif 55 56 #ifndef CINT_STRNCPY 57 #define CINT_STRNCPY strncpy 58 #endif 59 60 #ifndef CINT_STRRCHR 61 #define CINT_STRRCHR strrchr 62 #endif 63 64 #ifndef CINT_STRCMP 65 #define CINT_STRCMP strcmp 66 #endif 67 68 #ifndef CINT_STRNCMP 69 #define CINT_STRNCMP strncmp 70 #endif 71 72 #ifndef CINT_STRNCASECMP 73 #define CINT_STRNCASECMP strncasecmp 74 #endif 75 76 #ifndef CINT_STRSTR 77 #define CINT_STRSTR strstr 78 #endif 79 80 #ifndef CINT_MEMCPY 81 #define CINT_MEMCPY memcpy 82 #endif 83 84 #ifndef CINT_MEMSET 85 #define CINT_MEMSET memset 86 #endif 87 88 #ifndef CINT_SPRINTF 89 #define CINT_SPRINTF sprintf 90 #endif 91 92 #ifndef CINT_SNPRINTF 93 #define CINT_SNPRINTF snprintf 94 #endif 95 96 #ifndef CINT_VSNPRINTF 97 #define CINT_VSNPRINTF vsnprintf 98 #endif 99 100 #ifndef CINT_VFPRINTF 101 #define CINT_VFPRINTF vfprintf 102 #endif 103 104 #ifndef CINT_FFLUSH 105 #define CINT_FFLUSH fflush 106 #endif 107 108 #ifndef CINT_STRCAT 109 #define CINT_STRCAT strcat 110 #endif 111 112 #ifndef CINT_STRNCAT 113 #define CINT_STRNCAT strncat 114 #endif 115 116 #ifndef CINT_STRDUP 117 #define CINT_STRDUP strdup 118 #endif 119 120 #ifndef CINT_STRLEN 121 #define CINT_STRLEN strlen 122 #endif 123 124 #if CINT_CONFIG_INCLUDE_PARSER_READLINE == 1 125 #ifndef CINT_READLINE 126 #include <readline/readline.h> 127 #define CINT_READLINE readline 128 #endif 129 #endif 130 131 #if CINT_CONFIG_INCLUDE_PARSER_ADD_HISTORY == 1 132 #ifndef CINT_ADD_HISTORY 133 #include <readline/history.h> 134 #define CINT_ADD_HISTORY add_history 135 #endif 136 #endif 137 138 #ifndef CINT_GETC 139 #define CINT_GETC getc 140 #endif 141 142 #ifndef CINT_FERROR 143 #define CINT_FERROR ferror 144 #endif 145 146 #if CINT_CONFIG_FILE_IO == 1 147 148 #ifndef CINT_FOPEN 149 #define CINT_FOPEN fopen 150 #endif 151 152 #ifndef CINT_FCLOSE 153 #define CINT_FCLOSE fclose 154 #endif 155 156 #ifndef CINT_FREAD 157 #define CINT_FREAD fread 158 #endif 159 160 #endif /* CINT_CONFIG_FILE_IO */ 161 162 #define CINT_FATAL_ERROR(msg) do { fputs(msg, stderr); exit(2); } while(0) 163 164 #endif /* CINT_CONFIG_INCLUDE_STDLIB == 1 */ 165 166 167 168 #if CINT_CONFIG_INCLUDE_SDK_SAL == 1 169 170 /* 171 * Use the SDK SAL interface 172 */ 173 174 #include <sal/core/libc.h> 175 #include <sal/core/alloc.h> 176 #include <shared/bsl.h> 177 #include <sal/appl/io.h> 178 179 #ifndef CINT_PRINTF 180 extern int cint_printk(const char* fmt, ...) 181 COMPILER_ATTRIBUTE((format (printf, 1, 2))); 182 #define CINT_PRINTF cint_printk 183 #endif 184 185 #ifndef CINT_FPRINTF 186 #define CINT_FPRINTF sal_fprintf 187 #endif 188 189 #ifndef CINT_VPRINTF 190 #define CINT_VPRINTF bsl_vprintf 191 #endif 192 193 #ifndef CINT_MALLOC 194 #define CINT_MALLOC(sz) sal_alloc(sz, "cint") 195 #endif 196 197 /* SAL doesn't not support realloc */ 198 199 #ifndef CINT_FREE 200 #define CINT_FREE sal_free 201 #endif 202 203 #ifndef CINT_STRNCPY 204 #define CINT_STRNCPY sal_strncpy 205 #endif 206 207 #ifndef CINT_STRRCHR 208 #define CINT_STRRCHR strrchr 209 #endif 210 211 #ifndef CINT_STRCMP 212 #define CINT_STRCMP sal_strcmp 213 #endif 214 215 #ifndef CINT_STRNCMP 216 #define CINT_STRNCMP sal_strncmp 217 #endif 218 219 #ifndef CINT_STRNCASECMP 220 #define CINT_STRNCASECMP sal_strncasecmp 221 #endif 222 223 #ifndef CINT_STRSTR 224 #define CINT_STRSTR strstr 225 #endif 226 227 #ifndef CINT_MEMCPY 228 #define CINT_MEMCPY sal_memcpy 229 #endif 230 231 #ifndef CINT_MEMSET 232 #define CINT_MEMSET sal_memset 233 #endif 234 235 #ifndef CINT_SPRINTF 236 #define CINT_SPRINTF sal_sprintf 237 #endif 238 239 #ifndef CINT_SNPRINTF 240 #define CINT_SNPRINTF sal_snprintf 241 #endif 242 243 #ifndef CINT_VSNPRINTF 244 #define CINT_VSNPRINTF sal_vsnprintf 245 #endif 246 247 #ifndef CINT_VFPRINTF 248 #define CINT_VFPRINTF sal_vfprintf 249 #endif 250 251 #ifndef CINT_FFLUSH 252 #define CINT_FFLUSH sal_fflush 253 #endif 254 255 #ifndef CINT_STRCAT 256 #define CINT_STRCAT strcat 257 #endif 258 259 #ifndef CINT_STRNCAT 260 #define CINT_STRNCAT strncat 261 #endif 262 263 #ifndef CINT_STRDUP 264 #define CINT_STRDUP sal_strdup 265 #endif 266 267 #ifndef CINT_STRLEN 268 #define CINT_STRLEN sal_strlen 269 #endif 270 271 #if CINT_CONFIG_INCLUDE_PARSER_READLINE == 1 272 #ifndef CINT_READLINE 273 #ifndef INCLUDE_EDITLINE 274 extern char* readline(const char* p); 275 #endif 276 #define CINT_READLINE readline 277 #endif 278 #endif 279 280 #if CINT_CONFIG_INCLUDE_PARSER_ADD_HISTORY == 1 281 #ifndef INCLUDE_EDITLINE 282 extern void add_history(char* p); 283 #endif 284 #ifndef CINT_ADD_HISTORY 285 #define CINT_ADD_HISTORY add_history 286 #endif 287 #endif 288 289 #ifndef CINT_GETC 290 #define CINT_GETC getc 291 #endif 292 293 #ifndef CINT_FERROR 294 #define CINT_FERROR ferror 295 #endif 296 297 #if CINT_CONFIG_FILE_IO == 1 298 299 #ifndef CINT_FOPEN 300 #define CINT_FOPEN sal_fopen 301 #endif 302 303 #ifndef CINT_FCLOSE 304 #define CINT_FCLOSE sal_fclose 305 #endif 306 307 #ifndef CINT_FREAD 308 #define CINT_FREAD sal_fread 309 #endif 310 311 #endif /* CINT_CONFIG_FILE_IO */ 312 313 #if CINT_CONFIG_INCLUDE_POSIX_TIMER == 1 314 315 #include <sal/core/time.h> 316 317 #define CINT_TIMER_GET sal_time_usecs() 318 319 #endif /* CINT_CONFIG_INCLUDE_POSIX_TIMER */ 320 321 #include <appl/diag/cmd_cint.h> 322 #define CINT_FATAL_ERROR(msg) cmd_cint_fatal_error(msg) 323 324 #endif /* CINT_CONFIG_INCLUDE_SDK_SAL == 1 */ 325 326 /* 327 * Test interfaces for CINT portability 328 */ 329 #if CINT_CONFIG_INCLUDE_STUBS == 1 330 #include "cint_stubs.h" 331 #endif /* CINT_CONFIG_INCLUDE_STUBS == 1 */ 332 333 /* 334 * These macros must be defined to something at this point, 335 * either as a result of CINT_CONFIG_INCLUDE_STDLIB = 1 336 * or by defining them externally in your cint_customer_config.h 337 */ 338 339 #ifndef CINT_PRINTF 340 #error CINT_PRINTF macro is not defined 341 #endif 342 343 #ifndef CINT_VPRINTF 344 #error CINT_VPRINTF macro is not defined 345 #endif 346 347 #ifndef CINT_MALLOC 348 #error CINT_MALLOC macro is not defined 349 #endif 350 351 #ifndef CINT_FREE 352 #error CINT_FREE macro is not defined 353 #endif 354 355 #ifndef CINT_STRRCHR 356 #error CINT_STRRCHR macro is not defined 357 #endif 358 359 #ifndef CINT_STRCMP 360 #error CINT_STRCMP macro is not defined 361 #endif 362 363 #ifndef CINT_STRSTR 364 #error CINT_STRSTR macro is not defined 365 #endif 366 367 #ifndef CINT_MEMCPY 368 #error CINT_MEMCPY macro is not defined 369 #endif 370 371 #ifndef CINT_MEMSET 372 #error CINT_MEMSET macro is not defined 373 #endif 374 375 #ifndef CINT_SPRINTF 376 #error CINT_SPRINTF macro is not defined 377 #endif 378 379 #ifndef CINT_SNPRINTF 380 #error CINT_SNPRINTF macro is not defined 381 #endif 382 383 #ifndef CINT_VSNPRINTF 384 #error CINT_VSNPRINTF macro is not defined 385 #endif 386 387 #ifndef CINT_STRCAT 388 #error CINT_STRCAT macro is not defined 389 #endif 390 391 #ifndef CINT_STRDUP 392 #error CINT_STRDUP macro is not defined 393 #endif 394 395 #ifndef CINT_STRLEN 396 #error CINT_STRLEN macro is not defined 397 #endif 398 399 #if CINT_CONFIG_INCLUDE_FILE_IO == 1 400 401 #ifndef CINT_FOPEN 402 #error CINT_FOPEN macro is not defined 403 #endif 404 405 #ifndef CINT_FCLOSE 406 #error CINT_FCLOSE macro is not defined 407 #endif 408 409 #ifndef CINT_FREAD 410 #error CINT_FREAD macro is not defined 411 #endif 412 413 #endif /* CINT_CONFIG_INCLUDE_FILE_IO */ 414 415 #ifndef COMPILER_ATTRIBUTE 416 #define COMPILER_ATTRIBUTE(_a) __attribute__ (_a) 417 #endif 418 419 #endif /* __CINT_PORTING_H__ */ 420 421 422 423