Skip to content

Commit fa7d9c4

Browse files
committed
refactor: simplify #if (!)defined directives to #ifdef or #ifndef
Signed-off-by: Leonard Ossa <leonard.ossa@openvpn.com>
1 parent 6bfb3f5 commit fa7d9c4

36 files changed

+91
-91
lines changed

client/ovpncli.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
// Set up export of our public interface unless
2323
// OPENVPN_CORE_API_VISIBILITY_HIDDEN is defined
24-
#if defined(__GNUC__)
24+
#ifdef __GNUC__
2525
#define OPENVPN_CLIENT_EXPORT
2626
#ifndef OPENVPN_CORE_API_VISIBILITY_HIDDEN
2727
#pragma GCC visibility push(default)
@@ -860,7 +860,7 @@ OPENVPN_CLIENT_EXPORT void OpenVPNClient::process_epki_cert_chain(const External
860860

861861
OPENVPN_CLIENT_EXPORT Status OpenVPNClient::connect()
862862
{
863-
#if !defined(OPENVPN_OVPNCLI_SINGLE_THREAD)
863+
#ifndef OPENVPN_OVPNCLI_SINGLE_THREAD
864864
openvpn_io::detail::signal_blocker signal_blocker; // signals should be handled by parent thread
865865
#endif
866866
#if defined(OPENVPN_LOG_LOGTHREAD_H) && !defined(OPENVPN_LOG_LOGBASE_H)
@@ -882,7 +882,7 @@ OPENVPN_CLIENT_EXPORT Status OpenVPNClient::do_connect()
882882
try
883883
{
884884
connect_attach();
885-
#if defined(OPENVPN_OVPNCLI_ASYNC_SETUP)
885+
#ifdef OPENVPN_OVPNCLI_ASYNC_SETUP
886886
openvpn_io::post(*state->io_context(), [this]()
887887
{ do_connect_async(); });
888888
#else
@@ -953,18 +953,18 @@ OPENVPN_CLIENT_EXPORT void OpenVPNClient::connect_setup(Status &status, bool &se
953953
cc.extra_peer_info = state->extra_peer_info;
954954
cc.stop = state->async_stop_local();
955955
cc.socket_protect = &state->socket_protect;
956-
#if defined(USE_TUN_BUILDER)
956+
#ifdef USE_TUN_BUILDER
957957
cc.builder = this;
958958
#endif
959-
#if defined(OPENVPN_EXTERNAL_TUN_FACTORY)
959+
#ifdef OPENVPN_EXTERNAL_TUN_FACTORY
960960
cc.extern_tun_factory = this;
961961
#endif
962-
#if defined(OPENVPN_EXTERNAL_TRANSPORT_FACTORY)
962+
#ifdef OPENVPN_EXTERNAL_TRANSPORT_FACTORY
963963
cc.extern_transport_factory = this;
964964
#endif
965965

966966
// external PKI
967-
#if !defined(USE_APPLE_SSL)
967+
#ifndef USE_APPLE_SSL
968968
if (state->eval.externalPki && !state->clientconf.disableClientCert)
969969
{
970970
if (!state->clientconf.external_pki_alias.empty())

openvpn/client/cliopt.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@
5757
#include <openvpn/transport/gremlin.hpp>
5858
#endif
5959

60-
#if defined(OPENVPN_PLATFORM_ANDROID)
60+
#ifdef OPENVPN_PLATFORM_ANDROID
6161
#include <openvpn/client/cliemuexr.hpp>
6262
#endif
6363

64-
#if defined(OPENVPN_EXTERNAL_TRANSPORT_FACTORY)
64+
#ifdef OPENVPN_EXTERNAL_TRANSPORT_FACTORY
6565
#include <openvpn/transport/client/extern/config.hpp>
6666
#include <openvpn/transport/client/extern/fw.hpp>
6767
#endif
6868

69-
#if defined(OPENVPN_EXTERNAL_TUN_FACTORY)
69+
#ifdef OPENVPN_EXTERNAL_TUN_FACTORY
7070
// requires that client implements ExternalTun::Factory::new_tun_factory
7171
#include <openvpn/tun/extern/config.hpp>
7272
#elif defined(USE_TUN_BUILDER)
@@ -180,15 +180,15 @@ class ClientOptions : public RC<thread_unsafe_refcount>
180180
ReconnectNotify *reconnect_notify = nullptr;
181181
RemoteList::RemoteOverride *remote_override = nullptr;
182182

183-
#if defined(USE_TUN_BUILDER)
183+
#ifdef USE_TUN_BUILDER
184184
TunBuilderBase *builder = nullptr;
185185
#endif
186186

187-
#if defined(OPENVPN_EXTERNAL_TUN_FACTORY)
187+
#ifdef OPENVPN_EXTERNAL_TUN_FACTORY
188188
ExternalTun::Factory *extern_tun_factory = nullptr;
189189
#endif
190190

191-
#if defined(OPENVPN_EXTERNAL_TRANSPORT_FACTORY)
191+
#ifdef OPENVPN_EXTERNAL_TRANSPORT_FACTORY
192192
ExternalTransport::Factory *extern_transport_factory = nullptr;
193193
#endif
194194
};
@@ -360,15 +360,15 @@ class ClientOptions : public RC<thread_unsafe_refcount>
360360
tunconf.tun_prop.remote_list = remote_list;
361361
tunconf.stop = config.stop;
362362
tunconf.allow_local_dns_resolvers = config.clientconf.allowLocalDnsResolvers;
363-
#if defined(OPENVPN_PLATFORM_WIN)
363+
#ifdef OPENVPN_PLATFORM_WIN
364364
if (config.clientconf.tunPersist)
365365
tunconf.tun_persist.reset(new TunWin::DcoTunPersist(true, TunWrapObjRetain::NO_RETAIN_NO_REPLACE, nullptr));
366366
#endif
367367
tun_factory = dco->new_tun_factory(tunconf, opt);
368368
}
369369
else
370370
{
371-
#if defined(OPENVPN_EXTERNAL_TUN_FACTORY)
371+
#ifdef OPENVPN_EXTERNAL_TUN_FACTORY
372372
{
373373
ExternalTun::Config tunconf;
374374
tunconf.tun_prop.layer = layer;
@@ -598,7 +598,7 @@ class ClientOptions : public RC<thread_unsafe_refcount>
598598
* string property (if applicable) */
599599
static std::tuple<bool, std::string> check_dco_compatibility(const ClientAPI::ConfigCommon &config, const OptionList &opt)
600600
{
601-
#if defined(ENABLE_KOVPN)
601+
#ifdef ENABLE_KOVPN
602602
// only care about dco/dco-win
603603
return std::make_tuple(true, "");
604604
#else

openvpn/common/endian.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <openvpn/common/endian_platform.hpp>
1515

1616
namespace openvpn::Endian {
17-
#if defined(OPENVPN_LITTLE_ENDIAN)
17+
#ifdef OPENVPN_LITTLE_ENDIAN
1818
inline size_t e16(const size_t v)
1919
{
2020
return v;

openvpn/common/endian64.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ inline std::uint64_t mingw_bswap64(const std::uint64_t val)
3232
inline std::uint64_t rev64(const std::uint64_t value)
3333
{
3434
#ifdef OPENVPN_LITTLE_ENDIAN
35-
#if defined(_MSC_VER)
35+
#ifdef _MSC_VER
3636
return _byteswap_uint64(value);
3737
#elif defined(__MINGW32__)
3838
return mingw_bswap64(value);

openvpn/common/ffs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace openvpn {
2222

23-
#if defined(__GNUC__)
23+
#ifdef __GNUC__
2424

2525
template <typename T>
2626
inline constexpr int n_bits_type()

openvpn/common/file.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <openvpn/buffer/bufstr.hpp>
2626
#include <openvpn/buffer/buflist.hpp>
2727

28-
#if defined(OPENVPN_PLATFORM_WIN)
28+
#ifdef OPENVPN_PLATFORM_WIN
2929
#include <filesystem>
3030
#include <openvpn/win/unicode.hpp>
3131
#endif
@@ -57,7 +57,7 @@ inline BufferPtr read_binary(const std::string &filename,
5757
const std::uint64_t max_size = 0,
5858
const BufferFlags buffer_flags = BufAllocFlags::NO_FLAGS)
5959
{
60-
#if defined(OPENVPN_PLATFORM_WIN)
60+
#ifdef OPENVPN_PLATFORM_WIN
6161
Win::UTF16 filenamew(Win::utf16(filename));
6262
std::filesystem::path path(filenamew.get());
6363
std::ifstream ifs(path, std::ios::binary);

openvpn/common/getopt.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <openvpn/common/size.hpp>
3737
#include <openvpn/common/exception.hpp>
3838

39-
#if !defined(OPENVPN_PLATFORM_WIN)
39+
#ifndef OPENVPN_PLATFORM_WIN
4040
#include <getopt.h>
4141
#else
4242

openvpn/common/getpw.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <openvpn/common/platform.hpp>
1616

17-
#if !defined(OPENVPN_PLATFORM_WIN)
17+
#ifndef OPENVPN_PLATFORM_WIN
1818
#include <pwd.h>
1919
#include <unistd.h>
2020
#else
@@ -28,7 +28,7 @@
2828
namespace openvpn {
2929
inline std::string get_password(const char *prompt)
3030
{
31-
#if !defined(OPENVPN_PLATFORM_WIN)
31+
#ifndef OPENVPN_PLATFORM_WIN
3232
char *ret = getpass(prompt);
3333
return ret;
3434
#else

openvpn/common/jsonlib.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#pragma once
1313

14-
#if defined(HAVE_JSONCPP)
14+
#ifdef HAVE_JSONCPP
1515
#define HAVE_JSON
1616
#include "json/json.h" // JsonCpp library
1717
#elif defined(HAVE_OPENVPN_COMMON)

openvpn/common/likely.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// Branch prediction hints (these make a difference on ARM)
1616
#if !defined(likely) && !defined(unlikely)
17-
#if defined(__GNUC__)
17+
#ifdef __GNUC__
1818
#define likely(x) __builtin_expect((x), 1)
1919
#define unlikely(x) __builtin_expect((x), 0)
2020
#else

0 commit comments

Comments
 (0)