Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Nov 2009 10:27:41 +0100
From:      "Matthias Andree" <matthias.andree@gmx.de>
To:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   header file bug sys/types.h sys/file.h vs. _XOPEN_SOURCE standard
Message-ID:  <op.u3mxwfh21e62zd@balu.cs.uni-paderborn.de>

next in thread | raw e-mail | index | archive | help
Greetings,

this little C program (which is actual a minimum excerpt from  
sysutils/e2fsprogs) fails to compile on - among others - 8.0-PRERELEASE:

$ cat fail.c
#define _XOPEN_SOURCE 600
#include <sys/file.h>

$ gcc -W -Wall -O -c fail.c
In file included from fail.c:2:
/usr/include/sys/file.h:161: error: expected specifier-qualifier-list  
before 'u_int'

I can get the code to compile by removing the "#define _XOPEN_SOURCE 600".

This happens here:

    146  /*
    147   * Userland version of struct file, for sysctl
    148   */
    149  struct xfile {
    150          size_t  xf_size;        /* size of struct xfile */
    151          pid_t   xf_pid;         /* owning process */
    152          uid_t   xf_uid;         /* effective uid of owning process  
*/
    153          int     xf_fd;          /* descriptor number */
    154          void    *xf_file;       /* address of struct file */
    155          short   xf_type;        /* descriptor type */
    156          int     xf_count;       /* reference count */
    157          int     xf_msgcount;    /* references from message queue */
    158          off_t   xf_offset;      /* file offset */
    159          void    *xf_data;       /* file descriptor specific data */
    160          void    *xf_vnode;      /* vnode pointer */
!! 161          u_int   xf_flag;        /* flags (see fcntl.h) */
    162  };


The flow here is as follows:

1. sys/file.h (non-standard header) includes sys/types.h (POSIX/XSI  
standard header) and implictly sys/cdefs.h

2. since _XOPEN_SOURCE is defined, nonstandard symbols such as u_int  
aren't defined by the standard headers (this is in line with IEEE Std  
1003.1-2008)

3. sys/file.h uses this non-standard and undefined u_int and breaks.

I've talked to Theodore Y. Ts'o, who is the sysutils/e2fsprogs upstream  
maintainer and proposed to remove the _XOPEN_SOURCE definition (my idea  
was that the code shouldn't be claiming standards compliance while it uses  
non-standard headers), but he refused that (since it would break the  
e2fsprogs build on Solaris).

Should non-standard system headers break if an application defines one of  
the standard feature test macros? Or could sys/file.h be changed (for  
instance by replacing u_int by unsigned int) to tolerate POSIX and XSI  
feature test macros?

TIA.

Cheers

-- 
Matthias Andree
mandree freebsd org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?op.u3mxwfh21e62zd>