From: Thomas Haller <thaller@redhat.com>
To: NetFilter <netfilter-devel@vger.kernel.org>
Cc: Thomas Haller <thaller@redhat.com>
Subject: [PATCH nft v2 1/6] meta: define _GNU_SOURCE to get strptime() from <time.h>
Date: Fri, 25 Aug 2023 13:36:29 +0200 [thread overview]
Message-ID: <20230825113810.2620133-2-thaller@redhat.com> (raw)
In-Reply-To: <20230825113810.2620133-1-thaller@redhat.com>
To use `strptime()`, the documentation indicates
#define _XOPEN_SOURCE
#include <time.h>
However, previously this was done wrongly.
For example, when building with musl we got a warning:
CC meta.lo
meta.c:40: warning: "_XOPEN_SOURCE" redefined
40 | #define _XOPEN_SOURCE
|
In file included from /usr/include/errno.h:8,
from meta.c:13:
/usr/include/features.h:16: note: this is the location of the previous definition
16 | #define _XOPEN_SOURCE 700
|
Defining "__USE_XOPEN" is wrong. This is a glibc internal define not for
the user.
Note that if we just set _XOPEN_SOURCE (or _XOPEN_SOURCE=700), we won't
get other things like "struct tm.tm_gmtoff".
Instead, we already define _GNU_SOURCE at other places. Do that here
too, it will give us strptime() and all is good.
Also, those directives should be defined as first thing (or via "-D"
command line). See [1].
This is also important, because to use "time_t" in a header, we would
need to include <time.h>. That only works, if we get the feature test
macros right. That is, define the _?_SOURCE macro as first thing.
[1] https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
Signed-off-by: Thomas Haller <thaller@redhat.com>
---
src/meta.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/meta.c b/src/meta.c
index bf2201009a8c..8508b11e70ce 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -10,6 +10,8 @@
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
+#define _GNU_SOURCE
+
#include <errno.h>
#include <limits.h>
#include <stddef.h>
@@ -25,6 +27,7 @@
#include <linux/netfilter.h>
#include <linux/pkt_sched.h>
#include <linux/if_packet.h>
+#include <time.h>
#include <nftables.h>
#include <expression.h>
@@ -37,10 +40,6 @@
#include <iface.h>
#include <json.h>
-#define _XOPEN_SOURCE
-#define __USE_XOPEN
-#include <time.h>
-
static void tchandle_type_print(const struct expr *expr,
struct output_ctx *octx)
{
--
2.41.0
next prev parent reply other threads:[~2023-08-25 11:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-25 11:36 [PATCH nft v2 0/6] cleanup base includes and add <nft.h> header Thomas Haller
2023-08-25 11:36 ` Thomas Haller [this message]
2023-08-25 11:36 ` [PATCH nft v2 2/6] src: add <nft.h> header and include it as first Thomas Haller
2023-08-25 11:36 ` [PATCH nft v2 3/6] include: don't define _GNU_SOURCE in public header Thomas Haller
2023-08-25 11:36 ` [PATCH nft v2 4/6] configure: use AC_USE_SYSTEM_EXTENSIONS to get _GNU_SOURCE Thomas Haller
2023-08-25 11:36 ` [PATCH nft v2 5/6] include: include <std{bool,int}.h> via <nft.h> Thomas Haller
2023-08-25 11:36 ` [PATCH nft v2 6/6] configure: drop AM_PROG_CC_C_O autoconf check Thomas Haller
2023-08-25 13:01 ` [PATCH nft v2 0/6] cleanup base includes and add <nft.h> header Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230825113810.2620133-2-thaller@redhat.com \
--to=thaller@redhat.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).