This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Make sys/timerfd.h usable without __USE_POSIX199309
Ulrich Drepper wrote:
> Jonathan Nieder wrote:
>> 2011-10-16 Jonathan Nieder <jrnieder@gmail.com>
>>
>> * sysdeps/unix/sysv/linux/sys/timerfd.h (everything): Only
>> declare under _GNU_SOURCE.
>> * sysdeps/unix/sysv/linux/sparc/sys/timerfd.h: Likewise.
[...]
> This is a rats nest. I really don't want to go through all the
> headers and do that.
Ping. I believe there must be a way to achieve both your and my
goals, if some kind reviewer would only say what the problem with the
patch is.
To be clear, my perspective is that a simple C source file that
#includes some public header provided by glibc and does nothing else
should either:
A. compile cleanly, or
B. #error with a relevant message.
Yes, I understand that glibc does not always meet this criterion even
after the above patch. If that bothers you, if you point out some
examples then I can look into them as well, but I don't think they
should block getting sys/timerfd.h to work.
Why do I want that? Well, I've experienced other platforms where the
order of #include-s was significant, or which required incantations
like
#if defined(__sun__)
/*
* On Solaris, when _XOPEN_EXTENDED is set, its header file
* forces the programs to be XPG4v2, defeating any _XOPEN_SOURCE
* setting to say we are XPG5 or XPG6. Also on Solaris,
* XPG6 programs must be compiled with a c99 compiler, while
* non XPG6 programs must be compiled with a pre-c99 compiler.
*/
# if __STDC_VERSION__ - 0 >= 199901L
# define _XOPEN_SOURCE 600
# else
# define _XOPEN_SOURCE 500
# endif
#else
...
I don't want to go back. The criterion I described above seems simple
and not too hard to aim for on a best-effort basis.
For the example at hand, would you prefer the following?
-- >8 --
Subject: sys/timerfd.h: #error out when included without __USE_GNU
2011-10-19 Jonathan Nieder <jrnieder@gmail.com>
* sysdeps/unix/sysv/linux/sys/timerfd.h: #error out with a
meaningful error message when included without _GNU_SOURCE
set. Such inclusion was never supported, and previously
including the header would produce compile-time errors due
to use of the clockid_t type when included without either
including sys/types.h first or defining _POSIX_C_SOURCE to
199309L or newer.
* sysdeps/unix/sysv/linux/sparc/sys/timerfd.h: Likewise.
---
sysdeps/unix/sysv/linux/sparc/sys/timerfd.h | 7 ++++++-
sysdeps/unix/sysv/linux/sys/timerfd.h | 7 ++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/sparc/sys/timerfd.h b/sysdeps/unix/sysv/linux/sparc/sys/timerfd.h
index 833d050..8d3c9b4 100644
--- a/sysdeps/unix/sysv/linux/sparc/sys/timerfd.h
+++ b/sysdeps/unix/sysv/linux/sparc/sys/timerfd.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -19,9 +19,14 @@
#ifndef _SYS_TIMERFD_H
#define _SYS_TIMERFD_H 1
+#include <features.h>
#include <time.h>
+#ifndef __USE_GNU
+# error "Must have '_GNU_SOURCE' feature test macro to use this file"
+#endif
+
/* Bits to be set in the FLAGS parameter of `timerfd_create'. */
enum
{
diff --git a/sysdeps/unix/sysv/linux/sys/timerfd.h b/sysdeps/unix/sysv/linux/sys/timerfd.h
index c1bb06f..e331c77 100644
--- a/sysdeps/unix/sysv/linux/sys/timerfd.h
+++ b/sysdeps/unix/sysv/linux/sys/timerfd.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -19,9 +19,14 @@
#ifndef _SYS_TIMERFD_H
#define _SYS_TIMERFD_H 1
+#include <features.h>
#include <time.h>
+#ifndef __USE_GNU
+# error "Must have '_GNU_SOURCE' feature test macro to use this file"
+#endif
+
/* Bits to be set in the FLAGS parameter of `timerfd_create'. */
enum
{
--
1.7.7