From 4a1507c398250a8b3900281d1bf08895c0c2f55e Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 24 Apr 2006 21:09:06 +0000 Subject: [PATCH] * Renamed htons/htonl to hton16/hton32 to avoid useless conflicts. --- common.h | 13 ++++++++----- configure.ac | 2 +- cucul/font.c | 30 +++++++++++++++--------------- src/cacaserver.c | 8 +++++++- tools/makefont.c | 4 ++-- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/common.h b/common.h index bba7bbf..997ea4f 100644 --- a/common.h +++ b/common.h @@ -32,16 +32,19 @@ typedef long int intptr_t; typedef unsigned long int uintptr_t; #endif -#if !defined(HAVE_HTONS) && !defined(HAVE_NETINET_IN_H) +#if defined(HAVE_HTONS) +# define hton16 htons +# define hton32 htonl +#else # if defined(HAVE_ENDIAN_H) # include # endif -static inline uint16_t htons(uint16_t x) +static inline uint16_t hton16(uint16_t x) { + /* This is compile-time optimised with at least -O1 or -Os */ #if defined(HAVE_ENDIAN_H) if(__BYTE_ORDER == __BIG_ENDIAN) #else - /* This is compile-time optimised with at least -O1 or -Os */ uint32_t const dummy = 0x12345678; if(*(uint8_t const *)&dummy == 0x12) #endif @@ -50,12 +53,12 @@ static inline uint16_t htons(uint16_t x) return (x >> 8) | (x << 8); } -static inline uint32_t htonl(uint32_t x) +static inline uint32_t hton32(uint32_t x) { + /* This is compile-time optimised with at least -O1 or -Os */ #if defined(HAVE_ENDIAN_H) if(__BYTE_ORDER == __BIG_ENDIAN) #else - /* This is compile-time optimised with at least -O1 or -Os */ uint32_t const dummy = 0x12345678; if(*(uint8_t const *)&dummy == 0x12) #endif diff --git a/configure.ac b/configure.ac index b9429f4..9e4fb5c 100644 --- a/configure.ac +++ b/configure.ac @@ -61,7 +61,7 @@ dnl conditional builds AC_ARG_ENABLE(doc, [ --enable-doc build documentation (needs doxygen and LaTeX)]) -AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h) +AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h) AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp htons) AC_CHECK_FUNCS(usleep gettimeofday) diff --git a/cucul/font.c b/cucul/font.c index 5fed167..b3f4411 100644 --- a/cucul/font.c +++ b/cucul/font.c @@ -136,15 +136,15 @@ cucul_font_t *cucul_load_font(void const *data, unsigned int size) f->private = (void *)(uintptr_t)data; memcpy(&f->header, f->private + 8, sizeof(struct font_header)); - f->header.control_size = htonl(f->header.control_size); - f->header.data_size = htonl(f->header.data_size); - f->header.version = htons(f->header.version); - f->header.blocks = htons(f->header.blocks); - f->header.glyphs = htonl(f->header.glyphs); - f->header.bpp = htons(f->header.bpp); - f->header.width = htons(f->header.width); - f->header.height = htons(f->header.height); - f->header.flags = htons(f->header.flags); + f->header.control_size = hton32(f->header.control_size); + f->header.data_size = hton32(f->header.data_size); + f->header.version = hton16(f->header.version); + f->header.blocks = hton16(f->header.blocks); + f->header.glyphs = hton32(f->header.glyphs); + f->header.bpp = hton16(f->header.bpp); + f->header.width = hton16(f->header.width); + f->header.height = hton16(f->header.height); + f->header.flags = hton16(f->header.flags); if(size != 8 + f->header.control_size + f->header.data_size || (f->header.bpp != 8 && f->header.bpp != 4 && @@ -161,9 +161,9 @@ cucul_font_t *cucul_load_font(void const *data, unsigned int size) f->header.blocks * sizeof(struct block_info)); for(i = 0; i < f->header.blocks; i++) { - f->block_list[i].start = htonl(f->block_list[i].start); - f->block_list[i].stop = htonl(f->block_list[i].stop); - f->block_list[i].index = htonl(f->block_list[i].index); + f->block_list[i].start = hton32(f->block_list[i].start); + f->block_list[i].stop = hton32(f->block_list[i].stop); + f->block_list[i].index = hton32(f->block_list[i].index); if(f->block_list[i].start > f->block_list[i].stop || (i > 0 && f->block_list[i].start < f->block_list[i - 1].stop) @@ -182,9 +182,9 @@ cucul_font_t *cucul_load_font(void const *data, unsigned int size) f->header.glyphs * sizeof(struct glyph_info)); for(i = 0; i < f->header.glyphs; i++) { - f->glyph_list[i].width = htons(f->glyph_list[i].width); - f->glyph_list[i].height = htons(f->glyph_list[i].height); - f->glyph_list[i].data_offset = htonl(f->glyph_list[i].data_offset); + f->glyph_list[i].width = hton16(f->glyph_list[i].width); + f->glyph_list[i].height = hton16(f->glyph_list[i].height); + f->glyph_list[i].data_offset = hton32(f->glyph_list[i].data_offset); if(f->glyph_list[i].data_offset >= f->header.data_size || f->glyph_list[i].data_offset diff --git a/src/cacaserver.c b/src/cacaserver.c index b4d0e6d..020816e 100644 --- a/src/cacaserver.c +++ b/src/cacaserver.c @@ -18,9 +18,15 @@ #include #include #include +#if defined(HAVE_ARPA_INET_H) +# include +#elif defined(HAVE_NETINET_IN_H) +# include +#elif defined(HAVE_WINSOCK2_H) +# include +#endif #include #include -#include #include #include #include diff --git a/tools/makefont.c b/tools/makefont.c index 8793b59..c59a66f 100644 --- a/tools/makefont.c +++ b/tools/makefont.c @@ -272,13 +272,13 @@ int main(int argc, char *argv[]) static int printf_u32(char const *fmt, uint32_t i) { - uint32_t ni = htonl(i); + uint32_t ni = hton32(i); return printf_hex(fmt, (uint8_t *)&ni, 4); } static int printf_u16(char const *fmt, uint16_t i) { - uint16_t ni = htons(i); + uint16_t ni = hton16(i); return printf_hex(fmt, (uint8_t *)&ni, 2); }