OpenTTD Source 20250529-master-g10c159a79f
safeguards.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
16#ifndef SAFEGUARDS_H
17#define SAFEGUARDS_H
18
19/* Use std::vector/std::unique_ptr/new instead. */
20#define malloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
21#define calloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
22#define realloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
23
24/* Use std::string/std::string_view instead. */
25#define strdup SAFEGUARD_DO_NOT_USE_THIS_METHOD
26#define strndup SAFEGUARD_DO_NOT_USE_THIS_METHOD
27
28#define strcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
29#define strncpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
30
31#define strcat SAFEGUARD_DO_NOT_USE_THIS_METHOD
32#define strncat SAFEGUARD_DO_NOT_USE_THIS_METHOD
33
34#define sprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
35#define snprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
36#define vsprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
37#define vsnprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
38
39#define strcmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
40#define strncmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
41#ifdef strcasecmp
42#undef strcasecmp
43#endif
44#define strcasecmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
45#ifdef stricmp
46#undef stricmp
47#endif
48#define stricmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
49
50#define memcmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
51#define memcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
52#define memmove SAFEGUARD_DO_NOT_USE_THIS_METHOD
53#define memset SAFEGUARD_DO_NOT_USE_THIS_METHOD
54
55/* Use fgets instead. */
56#define gets SAFEGUARD_DO_NOT_USE_THIS_METHOD
57
58/* Use StringConsumer instead. */
59#define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
60#define sscanf SAFEGUARD_DO_NOT_USE_THIS_METHOD
61#define from_string SAFEGUARD_DO_NOT_USE_THIS_METHOD
62
63/* Use ParseInteger or StringConsumer instead. */
64#define atoi SAFEGUARD_DO_NOT_USE_THIS_METHOD
65#define atol SAFEGUARD_DO_NOT_USE_THIS_METHOD
66#define atoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
67#define strtol SAFEGUARD_DO_NOT_USE_THIS_METHOD
68#define strtoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
69#define strtoul SAFEGUARD_DO_NOT_USE_THIS_METHOD
70#define strtoull SAFEGUARD_DO_NOT_USE_THIS_METHOD
71#define stoi SAFEGUARD_DO_NOT_USE_THIS_METHOD
72#define stol SAFEGUARD_DO_NOT_USE_THIS_METHOD
73#define stoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
74#define stoul SAFEGUARD_DO_NOT_USE_THIS_METHOD
75#define stoull SAFEGUARD_DO_NOT_USE_THIS_METHOD
76#define stoimax SAFEGUARD_DO_NOT_USE_THIS_METHOD
77#define stoumax SAFEGUARD_DO_NOT_USE_THIS_METHOD
78
79/* Use fmt::print instead. */
80#define printf SAFEGUARD_DO_NOT_USE_THIS_METHOD
81#define fprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
82#define puts SAFEGUARD_DO_NOT_USE_THIS_METHOD
83#define fputs SAFEGUARD_DO_NOT_USE_THIS_METHOD
84#define putchar SAFEGUARD_DO_NOT_USE_THIS_METHOD
85
86/* Use fmt::format instead */
87#define to_string SAFEGUARD_DO_NOT_USE_THIS_METHOD
88
89/* Use our own templated implementation instead of a macro or function with only one type. */
90#ifdef min
91#undef min
92#endif
93
94/* Use our own templated implementation instead of a macro or function with only one type. */
95#ifdef max
96#undef max
97#endif
98
99/* Use our own templated implementation instead of a macro or function with only one type. */
100#ifdef abs
101#undef abs
102#endif
103
104#if defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32)
105/* Use NetworkError::GetLast() instead of errno, or do not (indirectly) include network/core/os_abstraction.h.
106 * Winsock does not set errno, but one should rather call WSAGetLastError. NetworkError::GetLast abstracts that away. */
107#ifdef errno
108#undef errno
109#endif
110#define errno SAFEGUARD_DO_NOT_USE_THIS_METHOD
111
112/* Use NetworkError::AsString() instead of strerror, or do not (indirectly) include network/core/os_abstraction.h.
113 * Winsock errors are not handled by strerror, but one should rather call FormatMessage. NetworkError::AsString abstracts that away. */
114#define strerror SAFEGUARD_DO_NOT_USE_THIS_METHOD
115#endif /* defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32) */
116
117#endif /* SAFEGUARDS_H */