_BSD_SOURCE vs. __BSD_VISIBLE

Peter Dufault dufault at hda.com
Fri Mar 19 09:51:43 PST 2004


On Mar 18, 2004, at 6:31 PM, Archie Cobbs wrote:

> Garrett Wollman wrote:
>>> On FreeBSD, _BSD_SOURCE is not recognized, but _POSIX_C_SOURCE is and
>>> it actually causes the BSD functions to be hidden. So I have to 
>>> manually
>>> add __BSD_VISIBLE to get them on FreeBSD.
>>
>> Then your code is wrong.  If you don't want POSIX namespace, then you
>> shouldn't be defining _POSIX_C_SOURCE.
>
> So you're saying that _POSIX_C_SOURCE is not an additive thing,
> it's a restrictive thing.
>
> This is different semantics from other flags (which serve to include
> symbols rather than omit them), which is contributing to my confusion.
> E.g. _GNU_SOURCE on Linux.
>
> Are these flags documented somewhere?

The POSIX ones are.  Bruce can cryptically correct me, but I think 
basically:

_POSIX_C_SOURCE specifies a set of symbols that must and that can be 
published,
based on what you set _POSIX_C_SOURCE to.  It is set to a date 
representing
one of the approved POSIX specs.  It must be defined before including 
<unistd.h>.

Additional symbols can not be published, unless they are enabled by 
another
feature test macro (e.g., __BSD_VISIBLE) or unless _POSIX_C_SOURCE is 
set
to a value representing a date newer than the specification you're 
reading,
which means if you set it to a value, newer stuff can't show up.

Got that part?

So (and I'm guilty for some of this), a feature test macro such as 
__BSD_VISIBLE
is not intended for the end user (the two underbars are supposed to 
imply that)
but is to set things up internally based on combinations of other items 
such as
the date setting of _POSIX_C_SOURCE, whether a given item is 
historically expected
to show up in a given environment, or other finer-grained selections.

I'll duck now, but maybe FreeBSD should set __BSD_VISIBLE if 
_BSD_SOURCE is defined.
I'm pretty sure the POSIX spec suggests exactly this sort of setting.

To be really portable, try setting _POSIX_C_SOURCE to a certain date, 
based on a
published POSIX spec, not setting any other feature test macros on the 
command line
or before including <unistd.h>, and getting the application to work.

If you can get your application to work, then a non-conforming system 
is at fault.

Good luck -

Peter

>
Peter Dufault
HD Associates, Inc.



More information about the freebsd-standards mailing list