On Wednesday, September 20 2023, I wrote:

> Hi,
>
> Ubuntu Mantic (current development version) already has glibc 2.38 which
> provides its own version of strlcpy.  This makes cmake define
> HAVE_STRLCPY with an empty value, which in turn causes apt-cacher-ng to
> FTBFS due to:
>
>  /<<PKGBUILDDIR>>/src/meta.h:326:44: error: operator '!' has no right operand
>    326 | #if !defined(HAVE_STRLCPY) || !HAVE_STRLCPY
>        |                                            ^
>
> I opted to fix this problem by using the idiom "+ 0" when checking for
> the macro value:
>
>   #if !defined(HAVE_STRLCPY) || !(HAVE_STRLCPY + 0)

Here's the patch.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
https://sergiodj.net/

From 9132aee28eda5e0233cbb9d53a8ca292ed24e99d Mon Sep 17 00:00:00 2001
From: Sergio Durigan Junior <sergi...@debian.org>
Date: Wed, 20 Sep 2023 16:38:19 -0400
Subject: [PATCH] Adjust !HAVE_STRLCPY macro check

When strlcpy is found (which is the case with glibc 2.38),
HAVE_STRLCPY will have an empty value, which makes the check
"!HAVE_STRLCPY" fail with:

 /<<PKGBUILDDIR>>/src/meta.h:326:44: error: operator '!' has no right operand
   326 | #if !defined(HAVE_STRLCPY) || !HAVE_STRLCPY
       |                                            ^

An easy fix is to use the "+ 0" idiom to make sure that the check
is performed against a valid value.

Signed-off-by: Sergio Durigan Junior <sergi...@debian.org>
---
 src/meta.cc | 2 +-
 src/meta.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/meta.cc b/src/meta.cc
index 9a2053f..e133f91 100644
--- a/src/meta.cc
+++ b/src/meta.cc
@@ -831,7 +831,7 @@ bool scaseequals(string_view a, string_view b)
     return true;
 }
 
-#if !defined(HAVE_STRLCPY) || !HAVE_STRLCPY
+#if !defined(HAVE_STRLCPY) || !(HAVE_STRLCPY + 0)
 size_t strlcpy(char *tgt, const char *src, size_t tgtSize)
 {
     auto p = src;
diff --git a/src/meta.h b/src/meta.h
index a1f4080..8f22c83 100644
--- a/src/meta.h
+++ b/src/meta.h
@@ -323,7 +323,7 @@ class NoCaseStringMap : public std::map<mstring, mstring, 
ltstring>
 static constexpr string_view svRN = szRN;
 static constexpr string_view svLF = "\n";
 
-#if !defined(HAVE_STRLCPY) || !HAVE_STRLCPY
+#if !defined(HAVE_STRLCPY) || !(HAVE_STRLCPY + 0)
 size_t strlcpy(char *tgt, const char *src, size_t tgtSize);
 #endif
 }
-- 
2.40.1

Attachment: signature.asc
Description: PGP signature

Reply via email to