This is the mail archive of the cygwin mailing list for the Cygwin 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]

Re: diff /usr/include/endian.orig.h /usr/include/endian.h > endian.h.diff


--- Eric Blake <eblake@...> wrote:
>
> Umm - did you copy straight from glibc's endian.h? ÂThat's a no-no;
> cygwin generally doesn't want to borrow LGPL sources to avoid any
> licensing questions (borrowing from BSD is okay, on the other hand).
> You would have to implement things from scratch from a documentation
> page, or copy from a less-questionable source, rather than using glibc's
> implementation.
>
> I'm stopping right here, so I don't risk tainting myself. ÂHow about you
> instead describe which macros you are missing, so someone can do a
> clean-room implementation of those macros.

  I did not copy my code from glibc's endian.h: I wrote my code
yesterday, while on Windows Vista for 32 bits using joe on Cygwin and
notepad. Now I'm using Ubuntu for x86-64. I'm also surprised that
glibc's code is similar to mine:

glibc's folks wrote:
#ifdef __USE_BSD
/* Conversion interfaces.  */
# include <bits/byteswap.h>

I wrote:
#ifdef _BSD_SOURCE

#include <byteswap.h>

  The man 3 page, from Linux and from the web, does not tell about __USE_BSD.

  The next line is equal, probably because the glibc's guy who wrote
it also was using x86-32. If I would be using Ubuntu for x86-64
yesterday I would have written the opposite.
#if __BYTE_ORDER == __LITTLE_ENDIAN
  If you want, to swap the order of my macros is very easy.

  Then glibc continues, interleaving be with le, and a pair of hto
with another pair of toh:
#  define htobe16(x) __bswap_16 (x)
#  define htole16(x) (x)
#  define be16toh(x) __bswap_16 (x)
#  define le16toh(x) (x)
  It is very different from what I wrote. I interleaved the types:
#define htobe16(x) bswap_16(x)
#define htobe32(x) bswap_32(x)
#define htobe64(x) bswap_64(x)

  To use bswap to implement hto and toh macros is the most intelligent
approach. Fortunately, glibc's __bswap_16 differs from Cygwin's
bswap_16.

  Also: glibc's style is different from mine: They use a space between
the # and the define.

  After writing this message I'm proud that I'm as smart as the glibc's coder.

  I need the 64 bits macros only. I wrote the other macros for
completeness. In my project, that can not be disclosed now, I use the
arpa/inet.h macros for the smaller types.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


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