NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
standards/48339: _POSIX_C_SOURCE and <dev/usb/usb.h> don't mix
>Number: 48339
>Category: standards
>Synopsis: _POSIX_C_SOURCE and <dev/usb/usb.h> don't mix
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: standards-manager
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Oct 24 19:40:00 +0000 2013
>Originator: Rhialto
>Release: NetBSD 6.1.1
>Organization:
>Environment:
System: NetBSD murthe.falu.nl 6.1.1 NetBSD 6.1.1 (MURTHE6.1.1) #4: Sat Sep 28
12:38:49 CEST 2013
rhialto%murthe.falu.nl@localhost:/usr/src/sys/arch/amd64/compile/MURTHE6.1.1
amd64
Architecture: x86_64
Machine: amd64
>Description:
The following small program fails to compile:
$ cat j.c
#define _POSIX_C_SOURCE
#include <dev/usb/usb.h>
int main(int argc, char *argv[])
{
return 0;
}
$ gcc j.c
In file included from j.c:2:0:
/usr/include/dev/usb/usb.h:663:2: error: expected specifier-qualifier-list
before 'u_int'
/usr/include/dev/usb/usb.h:675:2: error: expected specifier-qualifier-list
before 'u_char'
/usr/include/dev/usb/usb.h:735:2: error: expected specifier-qualifier-list
before 'u_char'
/usr/include/dev/usb/usb.h:739:2: error: expected specifier-qualifier-list
before 'u_long'
/usr/include/dev/usb/usb.h:743:2: error: expected specifier-qualifier-list
before 'u_int'
>How-To-Repeat:
See above.
Analysis:
<dev/usb/usb.h> does include <sys/types.h> so one expects u_int,
u_char and u_long to be defined.
38 #include <sys/types.h>
...
661 struct usb_full_desc {
662 int ufd_config_index;
663 u_int ufd_size;
664 u_char *ufd_data;
665 };
...
673 struct usb_ctl_report_desc {
674 int ucrd_size;
675 u_char ucrd_data[1024]; /* filled data size will vary */
676 };
...
However, it turns out that <sys/types.h> protects these
definitions by a _NETBSD_SOURCE:
100 #if defined(_NETBSD_SOURCE)
101 typedef unsigned char u_char;
102 typedef unsigned short u_short;
103 typedef unsigned int u_int;
104 typedef unsigned long u_long;
...
110 #endif
Normally, _NETBSD_SOURCE is #defined in <sys/featuretest.h>,
which is #included from <sys/types.h>
42 #include <sys/featuretest.h>
However, _NETBSD_SOURCE is not always defined. If certain
*_SOURCE symbols are defined, _NETBSD_SOURCE won't be:
63 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
64 #define _POSIX_C_SOURCE 1L
65 #endif
66
67 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
68 !defined(_XOPEN_SOURCE) && !defined(_NETBSD_SOURCE)
69 #define _NETBSD_SOURCE 1
70 #endif
>Fix:
Probably <dev/usb/usb.h> should use more (standard or at least
certain to be defined) types, such as uint{8,16,32}_t or plain
unsigned char, unsigned int and unsigned long.
It uses both {u,}int{8,16,32}_t and char,int,long in plenty of
places already.
-Olaf.
--
___ Olaf 'Rhialto' Seibert -- The Doctor: No, 'eureka' is Greek for
\X/ rhialto/at/xs4all.nl -- 'this bath is too hot.'
>Unformatted:
Home |
Main Index |
Thread Index |
Old Index