Browse Source

* Renamed htons/htonl to hton16/hton32 to avoid useless conflicts.

tags/v0.99.beta14
Sam Hocevar sam 19 years ago
parent
commit
4a1507c398
5 changed files with 33 additions and 24 deletions
  1. +8
    -5
      common.h
  2. +1
    -1
      configure.ac
  3. +15
    -15
      cucul/font.c
  4. +7
    -1
      src/cacaserver.c
  5. +2
    -2
      tools/makefont.c

+ 8
- 5
common.h View File

@@ -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 <endian.h>
# 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


+ 1
- 1
configure.ac View File

@@ -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)



+ 15
- 15
cucul/font.c View File

@@ -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


+ 7
- 1
src/cacaserver.c View File

@@ -18,9 +18,15 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if defined(HAVE_ARPA_INET_H)
# include <arpa/inet.h>
#elif defined(HAVE_NETINET_IN_H)
# include <netinet/in.h>
#elif defined(HAVE_WINSOCK2_H)
# include <winsock2.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>


+ 2
- 2
tools/makefont.c View File

@@ -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);
}



Loading…
Cancel
Save