]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
compatibility: handle strscpy_pad()
authorJozsef Kadlecsik <kadlec@netfilter.org>
Mon, 18 Sep 2023 21:06:59 +0000 (23:06 +0200)
committerJozsef Kadlecsik <kadlec@netfilter.org>
Mon, 18 Sep 2023 21:06:59 +0000 (23:06 +0200)
configure.ac
kernel/include/linux/netfilter/ipset/ip_set_compat.h.in

index dc11b142c864dfdca939e0b42b3adaff2884db2f..59a342159df0de3f1ea8ede085001b9b241cbc94 100644 (file)
@@ -754,6 +754,16 @@ else
        AC_SUBST(HAVE_STRSCPY, undef)
 fi
 
+AC_MSG_CHECKING([kernel source for strscpy_pad() in string.h])
+if test -f $ksourcedir/include/linux/timer.h && \
+   $GREP -q ' strscpy_pad' $ksourcedir/include/linux/string.h; then
+       AC_MSG_RESULT(yes)
+       AC_SUBST(HAVE_STRSCPY_PAD, define)
+else
+       AC_MSG_RESULT(no)
+       AC_SUBST(HAVE_STRSCPY, undef)
+fi
+
 AC_MSG_CHECKING([kernel source for synchronize_rcu_bh() in rcutiny.h and rcupdate.h])
 if test -f $ksourcedir/include/linux/rcupdate.h && \
    $GREP -q 'static inline void synchronize_rcu_bh' \
index 7d3f5363403fa5e4dea81843bed00e2181b42a74..b1095493b9545f0c136a00313eff45b334746326 100644 (file)
@@ -52,6 +52,7 @@
 #@HAVE_TYPEDEF_SCTP_SCTPHDR_T@ HAVE_TYPEDEF_SCTP_SCTPHDR_T
 #@HAVE_TIMER_SETUP@ HAVE_TIMER_SETUP
 #@HAVE_STRSCPY@ HAVE_STRSCPY
+#@HAVE_STRSCPY_PAD@ HAVE_STRSCPY_PAD
 #@HAVE_SYNCHRONIZE_RCU_BH@ HAVE_SYNCHRONIZE_RCU_BH
 #@HAVE_LOCKDEP_NFNL_IS_HELD@ HAVE_LOCKDEP_NFNL_IS_HELD
 #@HAVE_COND_RESCHED_RCU@ HAVE_COND_RESCHED_RCU
@@ -514,6 +515,21 @@ static inline ssize_t strscpy(char * dest, const char * src, size_t count)
 }
 #endif
 
+#ifndef HAVE_STRSCPY_PAD
+static inline ssize_t strscpy_pad(char *dest, const char *src, size_t count)
+{
+       ssize_t written;
+
+       written = strscpy(dest, src, count);
+       if (written < 0 || written == count - 1)
+               return written;
+
+       memset(dest + written + 1, 0, count - written - 1);
+
+       return written;
+}
+#endif
+
 #ifndef HAVE_NLA_STRSCPY
 #define nla_strscpy    nla_strlcpy
 #endif