summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Fedoryshchenko <denys.f@collabora.com>2026-08-11 21:37:18 +0300
committerDenys Fedoryshchenko <denys.f@collabora.com>2026-08-11 21:42:07 +0300
commit1c69485e1ebd17bf3cc6e8fc4728f9bdb431de94 (patch)
treefa86681a712ff3c0605c96883c000d864cb60b53
parent86e71f2aa48d62e1c63253f0986d5f643410a263 (diff)
downloadaccel-ppp-1c69485e1ebd17bf3cc6e8fc4728f9bdb431de94.tar.gz
accel-ppp-1c69485e1ebd17bf3cc6e8fc4728f9bdb431de94.zip
utils: centralize min macro
Several userspace translation units carry identical local min() definitions. Move the guarded definition to utils.h and include it from each user so there is one implementation to maintain. The Linux min() macro lives in kernel-internal headers and is not part of the userspace UAPI. Clang/LLVM does not provide a compatible min macro either: C++ code uses std::min and Clang's similarly named operations use explicit builtin names. The userspace <sys/param.h> interface, where available, exposes uppercase MIN instead. Keep the #ifndef guard to preserve the behavior of the existing local definitions and avoid redefining a lowercase min macro supplied by an unrelated third-party header.
-rw-r--r--accel-pppd/ctrl/pppoe/pppoe.c5
-rw-r--r--accel-pppd/ctrl/sstp/sstp.c3
-rw-r--r--accel-pppd/log.c5
-rw-r--r--accel-pppd/logs/log_pgsql.c3
-rw-r--r--accel-pppd/ppp/ppp_lcp.c5
-rw-r--r--accel-pppd/utils.h4
6 files changed, 8 insertions, 17 deletions
diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c
index 72faab4e..0e65168d 100644
--- a/accel-pppd/ctrl/pppoe/pppoe.c
+++ b/accel-pppd/ctrl/pppoe/pppoe.c
@@ -24,6 +24,7 @@
#endif
#include "iputils.h"
+#include "utils.h"
#include "connlimit.h"
#include "vlan_mon.h"
@@ -33,10 +34,6 @@
#define SID_MAX 65536
-#ifndef min
-#define min(x,y) ((x)<(y)?(x):(y))
-#endif
-
struct pppoe_conn_t {
struct list_head entry;
struct triton_context_t ctx;
diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c
index 2fd8cb35..72004cf8 100644
--- a/accel-pppd/ctrl/sstp/sstp.c
+++ b/accel-pppd/ctrl/sstp/sstp.c
@@ -47,9 +47,6 @@
#include "sstp_prot.h"
#include "if_ppposeq.h"
-#ifndef min
-#define min(x,y) ((x) < (y) ? (x) : (y))
-#endif
#ifndef max
#define max(x,y) ((x) > (y) ? (x) : (y))
#endif
diff --git a/accel-pppd/log.c b/accel-pppd/log.c
index e4a1e6ed..7fac66df 100644
--- a/accel-pppd/log.c
+++ b/accel-pppd/log.c
@@ -11,15 +11,12 @@
#include "triton/mempool.h"
#include "events.h"
#include "ppp.h"
+#include "utils.h"
#include "log.h"
#include "memdebug.h"
-#ifndef min
-#define min(x,y) ((x)<(y)?(x):(y))
-#endif
-
#define LOG_MSG 0
#define LOG_ERROR 1
#define LOG_WARN 2
diff --git a/accel-pppd/logs/log_pgsql.c b/accel-pppd/logs/log_pgsql.c
index 99be5e64..5b3fd6ae 100644
--- a/accel-pppd/logs/log_pgsql.c
+++ b/accel-pppd/logs/log_pgsql.c
@@ -9,11 +9,10 @@
#include "log.h"
#include "list.h"
#include "ap_session.h"
+#include "utils.h"
#include "memdebug.h"
-#define min(x,y) ((x)<(y)?(x):(y))
-
static char *conf_conninfo;
static int conf_queue_max = 1000;
static char *conf_query;
diff --git a/accel-pppd/ppp/ppp_lcp.c b/accel-pppd/ppp/ppp_lcp.c
index 05b6c4a6..ed085b3b 100644
--- a/accel-pppd/ppp/ppp_lcp.c
+++ b/accel-pppd/ppp/ppp_lcp.c
@@ -13,13 +13,10 @@
#include "ppp_lcp.h"
#include "events.h"
#include "iputils.h"
+#include "utils.h"
#include "memdebug.h"
-#ifndef min
-#define min(x,y) ((x)<(y)?(x):(y))
-#endif
-
struct recv_opt_t
{
struct list_head entry;
diff --git a/accel-pppd/utils.h b/accel-pppd/utils.h
index aad4025f..63c1db0d 100644
--- a/accel-pppd/utils.h
+++ b/accel-pppd/utils.h
@@ -4,6 +4,10 @@
#include <netinet/in.h>
#include <stdint.h>
+#ifndef min
+#define min(x, y) ((x) < (y) ? (x) : (y))
+#endif
+
char *u_ip6str(const struct in6_addr *addr, char *buf);
char *u_ip4str(const struct in_addr *addr, char *buf);