Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Oct 1996 18:03:16 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        bde@freefall.freebsd.org, peter@spinner.DIALix.COM
Cc:        cvs-all@freefall.freebsd.org, CVS-committers@freefall.freebsd.org, cvs-lib@freefall.freebsd.org, cvs-sbin@freefall.freebsd.org
Subject:   Re: cvs commit: src/lib/libmd mdXhl.c src/sbin/md5 md5.c
Message-ID:  <199610250803.SAA11209@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>>   Modified:    lib/libmd  mdXhl.c
>>                sbin/md5  md5.c
>>   Log:
>>   Moved #include of <sys/types.h> earlier so that this compiles when
>>   <stdio.h> doesn't (bogusly) include <sys/types.h>.
>
>Bogus it may be, but if we're even going to pretend that we are trying to  
>conform to important standards where possible (such as Spec1170 aka the 
>"Single Unix" spec), stdio.h and all the other major include files _must_ 
>be self contained.  POSIX may not require it, but the X/Open stuff does.

If we're going to pretend to be ANSI and POSIX conformant, then standard
headers must not include massive namespace pollution from other headers.

POSIX specifies that only a few names in the application namespace may
be defined in <sys/types.h>:

1. dev_t, gid_t, ino_t, mode_t, nlink_t, off_t, pid_t, size_t, ssize_t, uid_t
2. all other names ending with _t (this applies all POSIX headers)

(2) says that including <sys/types.h> in any POSIX header is OK provided
<sys/types.h> doesn't define any junk.  The FreeBSD <sys/types.h>
defines a lot of junk :-(.  See my list posted a few months ago.
Even if _POSIX_SOURCE is defined, the junk includes everything in
<machine/endian.h>.

Even if <sys/types.h> were clean, it isn't convenient to depend on it to
define enough types in POSIX headers that are also specified ANSI, because
it can't be included in the _ANSI_SOURCE case (if we pretend to be ANSI
conformant) unless it has zillions of ifdefs to prevent exportation of
the non-ANSI parts in the _ANSI_SOURCE case, and then it would still need
to define the necessary types in the implementation namespace, but we can
types in the implementation namespace just by including <machine/ansi.h>.
The problem in <stdio.h> is that fpos_t needs to be the same as off_t,
but off_t is not allowed in the ANSI namespace.

Of course headers should be self-contained.  The ones defined by ANSI
are specified to be self-contained, although the POSIX ones aren't.

Here are my diffs for making stdio.h self contained.  I've been using
essentially the same version for 3 years now.

Bruce

diff -c2 stdio.h~ stdio.h
*** stdio.h~	Wed Jul  3 17:15:02 1996
--- stdio.h	Tue May 28 02:34:06 1996
***************
*** 40,50 ****
  #define	_STDIO_H_
  
- #if !defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)
- #include <sys/types.h>
- #endif
- 
  #include <sys/cdefs.h>
- 
  #include <machine/ansi.h>
  #ifdef	_BSD_SIZE_T_
  typedef	_BSD_SIZE_T_	size_t;
--- 40,46 ----
  #define	_STDIO_H_
  
  #include <sys/cdefs.h>
  #include <machine/ansi.h>
+ 
  #ifdef	_BSD_SIZE_T_
  typedef	_BSD_SIZE_T_	size_t;
***************
*** 68,72 ****
   */
  #if !defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)
! typedef off_t fpos_t;
  #else
  typedef struct __sfpos {
--- 64,68 ----
   */
  #if !defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)
! typedef	_BSD_OFF_T_	fpos_t;
  #else
  typedef struct __sfpos {



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