NetBSD Problem Report #48339
From rhialto@falu.nl Thu Oct 24 19:38:08 2013
Return-Path: <rhialto@falu.nl>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id DB246A5A91
for <gnats-bugs@gnats.NetBSD.org>; Thu, 24 Oct 2013 19:38:08 +0000 (UTC)
Message-Id: <201310241938.r9OJc20b009164@murthe.falu.nl>
Date: Thu, 24 Oct 2013 21:38:02 +0200 (CEST)
From: rhialto@falu.nl
Reply-To: rhialto@falu.nl
To: gnats-bugs@gnats.NetBSD.org
Cc: rhialto@falu.nl
Subject: _POSIX_C_SOURCE and <dev/usb/usb.h> don't mix
X-Send-Pr-Version: 3.95
>Number: 48339
>Category: kern
>Synopsis: _POSIX_C_SOURCE and <dev/usb/usb.h> don't mix
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Oct 24 19:40:00 +0000 2013
>Closed-Date: Fri Aug 23 07:18:04 +0000 2019
>Last-Modified: Fri Aug 23 07:20:01 +0000 2019
>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:/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.'
>Release-Note:
>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: standards-manager@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Subject: Re: standards/48339: _POSIX_C_SOURCE and <dev/usb/usb.h> don't mix
Date: Sat, 2 Nov 2013 17:33:39 +0000
On Thu, Oct 24, 2013 at 07:40:00PM +0000, rhialto@falu.nl wrote:
> 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;
> }
"don't do that"
POSIX doesn't define USB drivers, so in principle once you do set
_POSIX_C_SOURCE it should refuse to even find usb.h.
That said, this:
> >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.
probably won't hurt anything.
--
David A. Holland
dholland@netbsd.org
Responsible-Changed-From-To: standards-manager->kern-bug-people
Responsible-Changed-By: dholland@NetBSD.org
Responsible-Changed-When: Sat, 02 Nov 2013 17:46:59 +0000
Responsible-Changed-Why:
not standards compliance
From: Klaus Klein <kleink@kleink.org>
To: David Holland <dholland-bugs@netbsd.org>
Cc: gnats-bugs@NetBSD.org
Subject: Re: standards/48339: _POSIX_C_SOURCE and <dev/usb/usb.h> don't mix
Date: Sat, 2 Nov 2013 23:57:57 +0100
Am 02.11.2013 um 18:33 schrieb David Holland <dholland-bugs@netbsd.org>:
> On Thu, Oct 24, 2013 at 07:40:00PM +0000, rhialto@falu.nl wrote:
>> The following small program fails to compile:
>>=20
>> $ cat j.c
>> #define _POSIX_C_SOURCE
>> #include <dev/usb/usb.h>
>>=20
>> int main(int argc, char *argv[])
>> {
>> return 0;
>> }
>=20
> "don't do that"
>=20
> POSIX doesn't define USB drivers, so in principle once you do set
> _POSIX_C_SOURCE it should refuse to even find usb.h.
Actually the application might be what=92s called a conforming POSIX =
application using extensions; while the feature test macro restricts =
what=92s made visible by the headers defined in the standard it doesn=92t =
preclude the use of non-POSIX headers in such an application (that=92d =
be a requirement for a strictly conforming application).
That said, I think having this work could be worthwhile to have, so...
>>> 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.
>=20
> probably won't hurt anything.
...I=92ll have a look. (Dito kern/48340.)
- Klaus
State-Changed-From-To: open->closed
State-Changed-By: mrg@NetBSD.org
State-Changed-When: Fri, 23 Aug 2019 07:18:04 +0000
State-Changed-Why:
i fixed this, and maybe it will end up on netbsd-9 along with other
usb code, but don't count on it. thanks!
From: "matthew green" <mrg@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/48339 CVS commit: src/sys/dev/usb
Date: Fri, 23 Aug 2019 07:17:31 +0000
Module Name: src
Committed By: mrg
Date: Fri Aug 23 07:17:31 UTC 2019
Modified Files:
src/sys/dev/usb: usb.h
Log Message:
avoid using old bsd types (u_int etc) so that this compiles with
_POSIX_C_SOURCE as noted in PR#48339.
To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/dev/usb/usb.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.