According to the recent changes to byteorder(3), including <endian.h> is
sufficient to use the byteorder functions. However, <endian.h> does not
pull in <sys/cdefs.h>. This causes two problems:

1. Various byteorder functions are hidden behind __BSD_VISIBLE. Programs
wishing to use these functions therefore explicitly have to define
__BSD_VISIBLE. This is unlike other extensions where the relevant
headers do include <sys/cdefs.h> (which by default defines __BSD_VISIBLE
appropriately).

2. <sys/_endian.h> (which is included by <endian.h>) uses __statement()
which is defined by <sys/cdefs.h>. As a result, programs that use a
byteorder function but include only <endian.h> won't compile.

Perhaps this sums it up best:

$ cat test.c
#include <endian.h>
main() { swap16(0); }
$ cc test.c
/tmp//ccRwShqf.o(.text+0x25): In function `main':
: undefined reference to `swap16'
collect2: ld returned 1 exit status
$ cc -D__BSD_VISIBLE test.c
test.c: In function 'main':
test.c:2: error: expected expression before '{' token
$ cc -D__BSD_VISIBLE "-D__statement(x)" test.c
$

A straightforward fix is to include <sys/cdefs.h>. The diff below does
just that, but I'm not sure about the ramifications.

Index: endian.h
===================================================================
RCS file: /cvs/src/sys/sys/endian.h,v
retrieving revision 1.24
diff -p -u -r1.24 endian.h
--- endian.h    20 Jul 2014 21:41:54 -0000      1.24
+++ endian.h    12 Aug 2014 18:15:24 -0000
@@ -37,6 +37,7 @@
 #ifndef _SYS_ENDIAN_H_
 #define _SYS_ENDIAN_H_
 
+#include <sys/cdefs.h>
 #include <sys/_endian.h>
 
 /* Public names */

Reply via email to