1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef COMMON_FORBIDDEN_H 24 #define COMMON_FORBIDDEN_H 25 26 /** 27 * @file 28 * This header file is meant to help ensure that engines and 29 * infrastructure code do not make use of certain "forbidden" APIs, such 30 * as fopen(), setjmp(), etc. 31 * This is achieved by re-#defining various symbols to a "garbage" 32 * string which then triggers a compiler error. 33 * 34 * Backend files may #define FORBIDDEN_SYMBOL_ALLOW_ALL if they 35 * have to access functions like fopen, fread etc. 36 * Regular code, esp. code in engines/, should never do that. 37 * To ease transition, though, we allow re-enabling selected symbols 38 * in frontend code. However, this should only be used as a temporary 39 * measure. Especially new code should avoid this at all costs. 40 */ 41 42 #ifndef FORBIDDEN_SYMBOL_ALLOW_ALL 43 44 // Make sure scummsys.h is always included first 45 #include "common/scummsys.h" 46 47 48 /** 49 * The garbage string to use as replacement for forbidden symbols. 50 * 51 * The reason for this particular string is the following: 52 * By including a space and some non-alphanumeric symbols we trigger 53 * a compiler error. By including the words "forbidden symbol" (which 54 * the compiler will hopefully print along with its own error message), 55 * we try to make clear what is causing the error. 56 */ 57 #define FORBIDDEN_SYMBOL_REPLACEMENT FORBIDDEN_look_at_common_forbidden_h_for_more_info SYMBOL !%* 58 59 60 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_printf 61 #undef printf 62 #define printf FORBIDDEN_SYMBOL_REPLACEMENT 63 #endif 64 65 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fprintf 66 #undef fprintf 67 #define fprintf FORBIDDEN_SYMBOL_REPLACEMENT 68 #endif 69 70 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_vprintf 71 #undef vprintf 72 #define vprintf FORBIDDEN_SYMBOL_REPLACEMENT 73 #endif 74 75 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_vfprintf 76 #undef vfprintf 77 #define vfprintf FORBIDDEN_SYMBOL_REPLACEMENT 78 #endif 79 80 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_FILE 81 #undef FILE 82 #define FILE FORBIDDEN_SYMBOL_REPLACEMENT 83 #endif 84 85 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_stdin 86 #undef stdin 87 #define stdin FORBIDDEN_SYMBOL_REPLACEMENT 88 #endif 89 90 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_stdout 91 #undef stdout 92 #define stdout FORBIDDEN_SYMBOL_REPLACEMENT 93 #endif 94 95 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_stderr 96 #undef stderr 97 #define stderr FORBIDDEN_SYMBOL_REPLACEMENT 98 #endif 99 100 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fopen 101 #undef fopen 102 #define fopen(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 103 #endif 104 105 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fclose 106 #undef fclose 107 #define fclose(a) FORBIDDEN_SYMBOL_REPLACEMENT 108 #endif 109 110 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fread 111 #undef fread 112 #define fread(a,b,c,d) FORBIDDEN_SYMBOL_REPLACEMENT 113 #endif 114 115 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fwrite 116 #undef fwrite 117 #define fwrite(a,b,c,d) FORBIDDEN_SYMBOL_REPLACEMENT 118 #endif 119 120 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fseek 121 #undef fseek 122 #define fseek(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT 123 #endif 124 125 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_ftell 126 #undef ftell 127 #define ftell(a) FORBIDDEN_SYMBOL_REPLACEMENT 128 #endif 129 130 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_feof 131 #undef feof 132 #define feof(a) FORBIDDEN_SYMBOL_REPLACEMENT 133 #endif 134 135 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fgetc 136 #undef fgetc 137 #define fgetc(a) FORBIDDEN_SYMBOL_REPLACEMENT 138 #endif 139 140 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fputc 141 #undef fputc 142 #define fputc(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 143 #endif 144 145 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fgets 146 #undef fgets 147 #define fgets(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT 148 #endif 149 150 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_fputs 151 #undef fputs 152 #define fputs(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 153 #endif 154 155 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getc 156 #undef getc 157 #define getc(a) FORBIDDEN_SYMBOL_REPLACEMENT 158 #endif 159 160 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_putc 161 #undef putc 162 #define putc(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 163 #endif 164 165 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_gets 166 #undef gets 167 #define gets(a) FORBIDDEN_SYMBOL_REPLACEMENT 168 #endif 169 170 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_puts 171 #undef puts 172 #define puts(a) FORBIDDEN_SYMBOL_REPLACEMENT 173 #endif 174 175 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getchar 176 #undef getchar 177 #define getchar() FORBIDDEN_SYMBOL_REPLACEMENT 178 #endif 179 180 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_putchar 181 #undef putchar 182 #define putchar(a) FORBIDDEN_SYMBOL_REPLACEMENT 183 #endif 184 185 // mingw-w64 uses [set|long]jmp in system headers 186 #if !defined __MINGW64__ && ! defined __MINGW32__ 187 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp 188 #undef setjmp 189 #define setjmp(a) FORBIDDEN_SYMBOL_REPLACEMENT 190 #endif 191 192 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp 193 #undef longjmp 194 #define longjmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 195 #endif 196 #endif // __MINGW64__ __MINGW32__ 197 198 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_system 199 #undef system 200 #define system(a) FORBIDDEN_SYMBOL_REPLACEMENT 201 #endif 202 203 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_exit 204 #undef exit 205 #define exit(a) FORBIDDEN_SYMBOL_REPLACEMENT 206 #endif 207 208 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_abort 209 #undef abort 210 #define abort() FORBIDDEN_SYMBOL_REPLACEMENT 211 #endif 212 213 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getenv 214 #undef getenv 215 #define getenv(a) FORBIDDEN_SYMBOL_REPLACEMENT 216 #endif 217 218 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_putenv 219 #undef putenv 220 #define putenv(a) FORBIDDEN_SYMBOL_REPLACEMENT 221 #endif 222 223 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_setenv 224 #undef setenv 225 #define setenv(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT 226 #endif 227 228 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_unsetenv 229 #undef unsetenv 230 #define unsetenv(a) FORBIDDEN_SYMBOL_REPLACEMENT 231 #endif 232 233 234 // 235 // Disable various symbols from time.h 236 // 237 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_h 238 239 /* 240 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_time_t 241 #undef time_t 242 #define time_t FORBIDDEN_SYMBOL_REPLACEMENT 243 #endif 244 */ 245 246 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_asctime 247 #undef asctime 248 #define asctime(a) FORBIDDEN_SYMBOL_REPLACEMENT 249 #endif 250 251 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_clock 252 #undef clock 253 #define clock() FORBIDDEN_SYMBOL_REPLACEMENT 254 #endif 255 256 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_ctime 257 #undef ctime 258 #define ctime(a) FORBIDDEN_SYMBOL_REPLACEMENT 259 #endif 260 261 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_difftime 262 #undef difftime 263 #define difftime(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 264 #endif 265 266 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getdate 267 #undef getdate 268 #define getdate(a) FORBIDDEN_SYMBOL_REPLACEMENT 269 #endif 270 271 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_gmtime 272 #undef gmtime 273 #define gmtime(a) FORBIDDEN_SYMBOL_REPLACEMENT 274 #endif 275 276 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_localtime 277 #undef localtime 278 #define localtime(a) FORBIDDEN_SYMBOL_REPLACEMENT 279 #endif 280 281 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_mktime 282 #undef mktime 283 #define mktime(a) FORBIDDEN_SYMBOL_REPLACEMENT 284 #endif 285 286 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_time 287 #undef time 288 #define time(a) FORBIDDEN_SYMBOL_REPLACEMENT 289 #endif 290 291 #endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h 292 293 // 294 // Disable various symbols from unistd.h 295 // 296 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_unistd_h 297 298 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_chdir 299 #undef chdir 300 #define chdir(a) FORBIDDEN_SYMBOL_REPLACEMENT 301 #endif 302 303 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getcwd 304 #undef getcwd 305 #define getcwd(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 306 #endif 307 308 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_getwd 309 #undef getwd 310 #define getwd(a) FORBIDDEN_SYMBOL_REPLACEMENT 311 #endif 312 313 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_unlink 314 #undef unlink 315 #define unlink(a) FORBIDDEN_SYMBOL_REPLACEMENT 316 #endif 317 318 #endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h 319 320 321 // 322 // Disable various symbols from ctype.h 323 // 324 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_ctype_h 325 326 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isalnum 327 #undef isalnum 328 #define isalnum(a) FORBIDDEN_SYMBOL_REPLACEMENT 329 #endif 330 331 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isalpha 332 #undef isalpha 333 #define isalpha(a) FORBIDDEN_SYMBOL_REPLACEMENT 334 #endif 335 336 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_iscntrl 337 #undef iscntrl 338 #define iscntrl(a) FORBIDDEN_SYMBOL_REPLACEMENT 339 #endif 340 341 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isdigit 342 #undef isdigit 343 #define isdigit(a) FORBIDDEN_SYMBOL_REPLACEMENT 344 #endif 345 346 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isgraph 347 #undef isgraph 348 #define isgraph(a) FORBIDDEN_SYMBOL_REPLACEMENT 349 #endif 350 351 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isnumber 352 #undef isnumber 353 #define isnumber(a) FORBIDDEN_SYMBOL_REPLACEMENT 354 #endif 355 356 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_islower 357 #undef islower 358 #define islower(a) FORBIDDEN_SYMBOL_REPLACEMENT 359 #endif 360 361 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isprint 362 #undef isprint 363 #define isprint(a) FORBIDDEN_SYMBOL_REPLACEMENT 364 #endif 365 366 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_ispunct 367 #undef ispunct 368 #define ispunct(a) FORBIDDEN_SYMBOL_REPLACEMENT 369 #endif 370 371 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isspace 372 #undef isspace 373 #define isspace(a) FORBIDDEN_SYMBOL_REPLACEMENT 374 #endif 375 376 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isupper 377 #undef isupper 378 #define isupper(a) FORBIDDEN_SYMBOL_REPLACEMENT 379 #endif 380 381 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isxdigit 382 #undef isxdigit 383 #define isxdigit(a) FORBIDDEN_SYMBOL_REPLACEMENT 384 #endif 385 386 #endif // FORBIDDEN_SYMBOL_EXCEPTION_ctype_h 387 388 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_mkdir 389 #undef mkdir 390 #define mkdir(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 391 #endif 392 393 /* 394 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_setlocale 395 #undef setlocale 396 #define setlocale(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 397 #endif 398 */ 399 400 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_setvbuf 401 #undef setvbuf 402 #define setvbuf(a,b,c,d) FORBIDDEN_SYMBOL_REPLACEMENT 403 #endif 404 405 406 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_tmpfile 407 #undef tmpfile 408 #define tmpfile() FORBIDDEN_SYMBOL_REPLACEMENT 409 #endif 410 411 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_tmpnam 412 #undef tmpnam 413 #define tmpnam(a) FORBIDDEN_SYMBOL_REPLACEMENT 414 #endif 415 416 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_tempnam 417 #undef tempnam 418 #define tempnam(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 419 #endif 420 421 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_rand 422 #undef rand 423 #define rand() FORBIDDEN_SYMBOL_REPLACEMENT 424 #endif 425 426 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_srand 427 #undef srand 428 #define srand(a) FORBIDDEN_SYMBOL_REPLACEMENT 429 #endif 430 431 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_random 432 #undef random 433 #define random() FORBIDDEN_SYMBOL_REPLACEMENT 434 #endif 435 436 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_srandom 437 #undef srandom 438 #define srandom(a) FORBIDDEN_SYMBOL_REPLACEMENT 439 #endif 440 441 442 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_stricmp 443 #undef stricmp 444 #define stricmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 445 #endif 446 447 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_strnicmp 448 #undef strnicmp 449 #define strnicmp(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT 450 #endif 451 452 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_strcasecmp 453 #undef strcasecmp 454 #define strcasecmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 455 #endif 456 457 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_strncasecmp 458 #undef strncasecmp 459 #define strncasecmp(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT 460 #endif 461 462 463 /* 464 * We also would like to disable the following symbols; 465 * however, these are also frequently used in regular code, 466 * e.g. for method names, so we don't override them. 467 * - read 468 * - remove 469 * - write 470 * - ... 471 */ 472 473 474 #endif 475 476 477 #endif 478