public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* linux/time.h annoyance
@ 2003-09-25  9:48 Ronald Bultje
  2003-09-25  9:54 ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Ronald Bultje @ 2003-09-25  9:48 UTC (permalink / raw)
  To: linux-kernel

Hi,

I'm annoyed by something in linux/time.h. The issue is as follows:

-
#include <sys/time.h>
#include <linux/time.h>
int main () { return 0; }
-

... compile with -Wall -Werror, and you'll get ...

-
In file included from test.c:2:
/usr/include/linux/time.h:9: redefinition of `struct timespec'
/usr/include/linux/time.h:88: redefinition of `struct timeval'
/usr/include/linux/time.h:93: redefinition of `struct timezone'
/usr/include/linux/time.h:124: redefinition of `struct itimerval'
-

... and the compile fails. In 2.6.x, there'll be some additional
warnings ...

-
In file included from test.c:2:
/usr/src/linux-2.6.0-test4/include/linux/time.h:9: redefinition of
`struct timespec'
/usr/src/linux-2.6.0-test4/include/linux/time.h:15: redefinition of
`struct timeval'
/usr/src/linux-2.6.0-test4/include/linux/time.h:20: redefinition of
`struct timezone'
In file included from test.c:2:
/usr/src/linux-2.6.0-test4/include/linux/time.h:341:1: "FD_SET"
redefined
In file included from /usr/include/sys/time.h:31,
                 from test.c:1:
/usr/include/sys/select.h:93:1: this is the location of the previous
definition
In file included from test.c:2:
/usr/src/linux-2.6.0-test4/include/linux/time.h:342:1: "FD_CLR"
redefined
In file included from /usr/include/sys/time.h:31,
                 from test.c:1:
/usr/include/sys/select.h:94:1: this is the location of the previous
definition
In file included from test.c:2:
/usr/src/linux-2.6.0-test4/include/linux/time.h:343:1: "FD_ISSET"
redefined
In file included from /usr/include/sys/time.h:31,
                 from test.c:1:
/usr/include/sys/select.h:95:1: this is the location of the previous
definition
In file included from test.c:2:
/usr/src/linux-2.6.0-test4/include/linux/time.h:344:1: "FD_ZERO"
redefined
In file included from /usr/include/sys/time.h:31,
                 from test.c:1:
/usr/include/sys/select.h:96:1: this is the location of the previous
definition
In file included from test.c:2:
/usr/src/linux-2.6.0-test4/include/linux/time.h:350:1: "ITIMER_REAL"
redefined
In file included from test.c:1:
/usr/include/sys/time.h:96:1: this is the location of the previous
definition
In file included from test.c:2:
/usr/src/linux-2.6.0-test4/include/linux/time.h:351:1: "ITIMER_VIRTUAL"
redefined
In file included from test.c:1:
/usr/include/sys/time.h:99:1: this is the location of the previous
definition
In file included from test.c:2:
/usr/src/linux-2.6.0-test4/include/linux/time.h:352:1: "ITIMER_PROF"
redefined
In file included from test.c:1:
/usr/include/sys/time.h:103:1: this is the location of the previous
definition
/usr/src/linux-2.6.0-test4/include/linux/time.h:359: redefinition of
`struct itimerval'
-

... and it still fails.

This is an issue in various ways. Most importantly, several linux kernel
headers that are not found in sys/ or for which sys/ is simply a
boilerplate-code-include (such as sys/soundcard.h) include linux/time.h
themselves (example: linux/videodev2.h). Also, many userspace tools
include sys/time.h automatically (example: glib2). Consequently, without
using ugly hacks, such as #define _LINUX_TIME_H 1 before including
glib.h and linux/videodev2.h, I cannot make a gnome2 video application
that will compile properly with -Wall -Werror. And that sucks.

sys/time.h & related headers seems to have a few macros to check for
struct definitions for each of the above-mentioned. I'm not sure how
official any of this is, but the fix for the first two of the warnings
seems very simple: add the same macro checks to linux/time.h. For struct
timespec, this is __timespec_defined. For struct timeval, this is
_STRUCT_TIMEVAL. Amusingly, linux/time.h uses _STRUCT_TIMESPEC for the
first. Code would look like:

#ifndef macro
#define macro
struct foo {
  int bar;
}
#endif /* macro */

The third and fourth warning (timezone/itimerval) are harder, because
sys/time.h & co don't have macros to check for redifinitions here. Does
anyone have suggestions on how to fix those two? Perhaps a check to see
whether time.h or sys/time.h was already included before defining the
structs (although that would still break if you reverse the order of
including those files, i.e. first #include linux/time.h and then
sys/time.h)?
For the 2.6.x-only warnings (FD_CLR etc.), these are all macro's and
could thus simply be checked by doing a "#ifndef ... #define ... #endif
/* ... */" for each of the ones that give a warning.

If wanted, I can provide a patch to fix parts of this, but this is so
simple that it shouldn't be needed for me to send one. Besides, I'm not
sure whether my proposed fixes are the right ones.

Thanks,

Ronald
(please CC me, I'm not subscribed)

-- 
Ronald Bultje <rbultje@ronald.bitfreak.net>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-09-25 18:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-25  9:48 linux/time.h annoyance Ronald Bultje
2003-09-25  9:54 ` Christoph Hellwig
2003-09-25 10:17   ` Ronald Bultje
2003-09-25 10:23     ` Christoph Hellwig
2003-09-25 10:55       ` Ronald Bultje
2003-09-25 11:25         ` Gerd Knorr
2003-09-25 11:07       ` Måns Rullgård
2003-09-25 18:00   ` Sam Ravnborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox