OpenTTD Source 20261123-master-g1c55c72fd0
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
15
16#ifndef SAFEGUARDS_H
17#define SAFEGUARDS_H
18
19/* Ignore everything in here for doxygen. These should not be used, so also not show up in the documentation. */
20#ifndef DOXYGEN_API
21
22/* Use std::vector/std::unique_ptr/new instead. */
23#define malloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
24#define calloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
25#define realloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
26
27/* Use std::string/std::string_view instead. */
28#define strdup SAFEGUARD_DO_NOT_USE_THIS_METHOD
29#define strndup SAFEGUARD_DO_NOT_USE_THIS_METHOD
30
31#define strcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
32#define strncpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
33
34#define strcat SAFEGUARD_DO_NOT_USE_THIS_METHOD
35#define strncat SAFEGUARD_DO_NOT_USE_THIS_METHOD
36
37#define sprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
38#define snprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
39#define vsprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
40#define vsnprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
41
42#define strcmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
43#define strncmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
44#ifdef strcasecmp
45#undef strcasecmp
46#endif
47#define strcasecmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
48#ifdef stricmp
49#undef stricmp
50#endif
51#define stricmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
52
53#define memcmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
54#define memcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
55#define memmove SAFEGUARD_DO_NOT_USE_THIS_METHOD
56/* Haiku uses memset for the FD_ZERO macro, meaning we cannot prevent it there. */
57#ifndef __HAIKU__
58# define memset SAFEGUARD_DO_NOT_USE_THIS_METHOD
59#endif
60
61/* Use fgets instead. */
62#define gets SAFEGUARD_DO_NOT_USE_THIS_METHOD
63
64/* Use StringConsumer instead. */
65#define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
66#define sscanf SAFEGUARD_DO_NOT_USE_THIS_METHOD
67#define from_string SAFEGUARD_DO_NOT_USE_THIS_METHOD
68
69/* Use ParseInteger or StringConsumer instead. */
70#define atoi SAFEGUARD_DO_NOT_USE_THIS_METHOD
71#define atol SAFEGUARD_DO_NOT_USE_THIS_METHOD
72#define atoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
73#define strtol SAFEGUARD_DO_NOT_USE_THIS_METHOD
74#define strtoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
75#define strtoul SAFEGUARD_DO_NOT_USE_THIS_METHOD
76#define strtoull SAFEGUARD_DO_NOT_USE_THIS_METHOD
77#define stoi SAFEGUARD_DO_NOT_USE_THIS_METHOD
78#define stol SAFEGUARD_DO_NOT_USE_THIS_METHOD
79#define stoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
80#define stoul SAFEGUARD_DO_NOT_USE_THIS_METHOD
81#define stoull SAFEGUARD_DO_NOT_USE_THIS_METHOD
82#define stoimax SAFEGUARD_DO_NOT_USE_THIS_METHOD
83#define stoumax SAFEGUARD_DO_NOT_USE_THIS_METHOD
84
85/* Use fmt::print instead. */
86#define printf SAFEGUARD_DO_NOT_USE_THIS_METHOD
87#define fprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
88#define puts SAFEGUARD_DO_NOT_USE_THIS_METHOD
89#define fputs SAFEGUARD_DO_NOT_USE_THIS_METHOD
90#define putchar SAFEGUARD_DO_NOT_USE_THIS_METHOD
91
92/* Use fmt::format instead */
93#define to_string SAFEGUARD_DO_NOT_USE_THIS_METHOD
94
95/* Use our own templated implementation instead of a macro or function with only one type. */
96#ifdef min
97#undef min
98#endif
99
100/* Use our own templated implementation instead of a macro or function with only one type. */
101#ifdef max
102#undef max
103#endif
104
105/* Use our own templated implementation instead of a macro or function with only one type. */
106#ifdef abs
107#undef abs
108#endif
109
110#if defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32)
111/* Use NetworkError::GetLast() instead of errno, or do not (indirectly) include network/core/os_abstraction.h.
112 * Winsock does not set errno, but one should rather call WSAGetLastError. NetworkError::GetLast abstracts that away. */
113#ifdef errno
114#undef errno
115#endif
116#define errno SAFEGUARD_DO_NOT_USE_THIS_METHOD
117
118/* Use NetworkError::AsString() instead of strerror, or do not (indirectly) include network/core/os_abstraction.h.
119 * Winsock errors are not handled by strerror, but one should rather call FormatMessage. NetworkError::AsString abstracts that away. */
120#define strerror SAFEGUARD_DO_NOT_USE_THIS_METHOD
121#endif /* defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32) */
122
123#endif /* DOXYGEN_API */
124#endif /* SAFEGUARDS_H */