This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Adding OpenBSD's endian functions betoh() / htobe() ?


Hello,

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.

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_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.

    * OpenBSD put it in #include <sys/types.h>, whereas glibc put
      bswap_32() etc. in #include <byteswap.h>
      (which is neater IMHO). 


----

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?


    Regards,
    Nanno


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]