This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/6442] New: Adding cross-Unix endianness functions: betoh() / htobe() 64,32,16
- From: "nlcom_os at ii dot nl" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 22 Apr 2008 09:14:33 -0000
- Subject: [Bug libc/6442] New: Adding cross-Unix endianness functions: betoh() / htobe() 64,32,16
- Reply-to: sourceware-bugzilla at sourceware dot org
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?
--
Summary: Adding cross-Unix endianness functions: betoh() /
htobe() 64,32,16
Product: glibc
Version: unspecified
Status: NEW
Severity: enhancement
Priority: P3
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: nlcom_os at ii dot nl
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=6442
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.