Hello

i would like to introduce in  eina (more precisely in eina_cpu)
implementations of ntohl and al. The reason is: on Windows, it
requires to link against winsock2 and include winsock2.h, with
introduce compilation errors with libjpeg in Emile (they both redefine
the same types, with different definition (bool is an int or a char,
etc...)

On unix, it requires also network header files.

so a solution would be to redefine ntohl in eina, using eina_swap*
ntohl and al. are not critical functions. I also looked at the asm
code generated by gcc with optimizations and it uses bswap, so the
functions are well optimized.

it would also reduce non cross platform code (inclusion of winsock2.h
or netinet/in.h or arpa/inet.h, no more -lws2_32 link (and even better
: no more dynamic link with ws2_32.dll in non-network files))

I've attached the source code. I would like your opinion about the names.

raster proposed eina_swap_from_bigendian_*()
i would prefer eina_ntoh*() : it's a smaller name, the functions are well known

thank you

Vincent
/*
ntoh --> from_bigendian
hton --> to_bigendian
*/

/* ntohs, ntohl, ntohll */

unsigned short
eina_swap_from_bigendian_16(unsigned short net)
{
#if WORDS_BIGENDIAN
   return net;
#else
   return eina_swap16(net);
#endif
}

unsigned int
eina_swap_from_bigendian_32(unsigned int net)
{
#if WORDS_BIGENDIAN
   return net;
#else
   return eina_swap32(net);
#endif
}

unsigned long long
eina_swap_from_bigendian_64(unsigned long long net)
{
#if WORDS_BIGENDIAN
   return net;
#else
   return eina_swap64(net);
#endif
}

/* htons, htonl, htonll */

unsigned short
eina_swap_to_bigendian_16(unsigned short x)
{
#if WORDS_BIGENDIAN
   return x;
#else
   return eina_swap16(x);
#endif
}

unsigned int
eina_swap_to_bigendian_32(unsigned int x)
{
#if WORDS_BIGENDIAN
   return x;
#else
   return eina_swap32(x);
#endif
}

unsigned long long
eina_swap_to_bigendian_64(unsigned long long x)
{
#if WORDS_BIGENDIAN
   return x;
#else
   return eina_swap64(x);
#endif
}
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to