This is a "repost" of an email on libc-alpha which got no responses. I am porting an application from OpenBSD to Linux, the application uses OpenBSD's betoh64() etc. to do 64-bit endiannes conversion. It appears that there is no cross-Linux-BSD set of ready-made endian-conversion functions. From what I see, all application roll their own with a tangle of #ifdefs. E.g. WPA_supplicant http://hostap.epitest.fi/wpa_supplicant/devel/common_8h-source.html I think that it would be nice for Linux and FreeBSD to adapt OpenBSD's endianness functions to set a standard. u_int64_t htobe64(u_int64_t host64); u_int64_t htole64(u_int64_t host64); u_int64_t betoh64(u_int64_t host64); u_int32_t htobe32(u_int32_t host32); etc. ---- FreeBSD libc doesn't have them either (just htonl() etc. like Linux). But FreeBSD's kernel does have lookalikes, and has variants that work on any alignment. The latter would be very useful to add, while we're at it. ---- There are three sore points that I can think of: * OpenBSD's function signatures don't use the standard uint*_t types. (IMHO safe to "fix" because these are just different names for the exact same base types) * glibc has bswap_32() etc. OpenBSD has a different name pattern: swap32(), htobe32() etc. The latter does match nicely with "uint*_t". * OpenBSD put it in #include <sys/types.h>, whereas glibc put bswap_32() etc. in #include <byteswap.h> (which is neater IMHO). Very probably needs a new include file altogether to avoid name clashes in applications. ---- My questions are: * Is there some interest in adding these convenience functions to glibc? If so, I'll whip up a proposal patch. * If so, how do we coordinate with FreeBSD (and, if deviations are required, OpenBSD) ? The point would be to get the same set of functions everywhere. I don't mind trying via their open mailing lists, but perhaps there are existing relations between glibc & BSD maintainers that are better suited?
Added in cvs.