OpenTTD Source 20260218-master-g2123fca5ea
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#define memset SAFEGUARD_DO_NOT_USE_THIS_METHOD
57
58/* Use fgets instead. */
59#define gets SAFEGUARD_DO_NOT_USE_THIS_METHOD
60
61/* Use StringConsumer instead. */
62#define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
63#define sscanf SAFEGUARD_DO_NOT_USE_THIS_METHOD
64#define from_string SAFEGUARD_DO_NOT_USE_THIS_METHOD
65
66/* Use ParseInteger or StringConsumer instead. */
67#define atoi SAFEGUARD_DO_NOT_USE_THIS_METHOD
68#define atol SAFEGUARD_DO_NOT_USE_THIS_METHOD
69#define atoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
70#define strtol SAFEGUARD_DO_NOT_USE_THIS_METHOD
71#define strtoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
72#define strtoul SAFEGUARD_DO_NOT_USE_THIS_METHOD
73#define strtoull SAFEGUARD_DO_NOT_USE_THIS_METHOD
74#define stoi SAFEGUARD_DO_NOT_USE_THIS_METHOD
75#define stol SAFEGUARD_DO_NOT_USE_THIS_METHOD
76#define stoll SAFEGUARD_DO_NOT_USE_THIS_METHOD
77#define stoul SAFEGUARD_DO_NOT_USE_THIS_METHOD
78#define stoull SAFEGUARD_DO_NOT_USE_THIS_METHOD
79#define stoimax SAFEGUARD_DO_NOT_USE_THIS_METHOD
80#define stoumax SAFEGUARD_DO_NOT_USE_THIS_METHOD
81
82/* Use fmt::print instead. */
83#define printf SAFEGUARD_DO_NOT_USE_THIS_METHOD
84#define fprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
85#define puts SAFEGUARD_DO_NOT_USE_THIS_METHOD
86#define fputs SAFEGUARD_DO_NOT_USE_THIS_METHOD
87#define putchar SAFEGUARD_DO_NOT_USE_THIS_METHOD
88
89/* Use fmt::format instead */
90#define to_string SAFEGUARD_DO_NOT_USE_THIS_METHOD
91
92/* Use our own templated implementation instead of a macro or function with only one type. */
93#ifdef min
94#undef min
95#endif
96
97/* Use our own templated implementation instead of a macro or function with only one type. */
98#ifdef max
99#undef max
100#endif
101
102/* Use our own templated implementation instead of a macro or function with only one type. */
103#ifdef abs
104#undef abs
105#endif
106
107#if defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32)
108/* Use NetworkError::GetLast() instead of errno, or do not (indirectly) include network/core/os_abstraction.h.
109 * Winsock does not set errno, but one should rather call WSAGetLastError. NetworkError::GetLast abstracts that away. */
110#ifdef errno
111#undef errno
112#endif
113#define errno SAFEGUARD_DO_NOT_USE_THIS_METHOD
114
115/* Use NetworkError::AsString() instead of strerror, or do not (indirectly) include network/core/os_abstraction.h.
116 * Winsock errors are not handled by strerror, but one should rather call FormatMessage. NetworkError::AsString abstracts that away. */
117#define strerror SAFEGUARD_DO_NOT_USE_THIS_METHOD
118#endif /* defined(NETWORK_CORE_OS_ABSTRACTION_H) && defined(_WIN32) */
119
120#endif /* DOXYGEN_API */
121#endif /* SAFEGUARDS_H */