[lxc-devel] [lxc/master] Config: check for %m availability

Rachid-Koucha on Github lxc-bot at linuxcontainers.org
Mon May 13 11:13:39 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 520 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190513/facae663/attachment.bin>
-------------- next part --------------
From 720bbb3118e8eb094be2d17aca841046f581bc7e Mon Sep 17 00:00:00 2001
From: Rachid Koucha <47061324+Rachid-Koucha at users.noreply.github.com>
Date: Mon, 13 May 2019 13:13:18 +0200
Subject: [PATCH] Config: check for %m availability

GLIBC supports %m to avoid calling strerror(). Using it saves some code space.
==> This check will define HAVE_M_FORMAT to be use wherever possible (e.g. log.h)

Signed-off-by: Rachid Koucha <rachid.koucha at gmail.com>
---
 configure.ac | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/configure.ac b/configure.ac
index 8d6774f236..029953e818 100644
--- a/configure.ac
+++ b/configure.ac
@@ -637,6 +637,33 @@ AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat ge
 # - STRERROR_R_CHAR_P if it returns char *
 AC_FUNC_STRERROR_R
 
+# Check if "%m" is supported by printf and Co
+AC_MSG_CHECKING([%m format])
+AC_TRY_RUN([
+#include <stdio.h>
+int main(void)
+{
+  char msg[256];
+  int rc;
+
+  rc = snprintf(msg, sizeof(msg), "%m\n");
+  if ((rc > 1) && (msg[0] != '%'))
+  {
+    return 0;
+  }
+  else
+  {
+    return 1;
+  }
+}],
+[fmt_m=yes], [fmt_m=no])
+if test "x$fmt_m" = "xyes"; then
+	AC_DEFINE([HAVE_M_FORMAT], 1, [Have %m format])
+	AC_MSG_RESULT([yes])
+else
+	AC_MSG_RESULT([no])
+fi
+
 # Check for some functions
 AC_CHECK_LIB(pthread, main)
 AC_CHECK_FUNCS(statvfs)


More information about the lxc-devel mailing list