From 181e9c6d5d11cb1e5d36a2777eeb233ad8ed00e5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 9 Oct 2008 18:15:23 +0200 Subject: big pile of updates to match more what happened with libcanberra --- src/bswap.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'src/bswap.c') diff --git a/src/bswap.c b/src/bswap.c index 501f98a..4e965ad 100644 --- a/src/bswap.c +++ b/src/bswap.c @@ -1,11 +1,27 @@ +/*** + This file is part of libsydney. + + Copyright 2007-2008 Lennart Poettering + + libsydney is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 2.1 of the + License, or (at your option) any later version. + + libsydney is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with libsydney. If not, see + . +***/ + #ifdef HAVE_CONFIG_H #include #endif -#ifdef HAVE_BYTESWAP_H -#include -#endif - #include #include "macro.h" @@ -14,15 +30,10 @@ static void byteswap16(void *_dst, size_t dstr, const void *_src, size_t sstr, size_t bytes) { uint16_t *dst = _dst; const uint16_t *src = _src; - unsigned n = bytes / sizeof(uint16_t); + size_t n = bytes / sizeof(uint16_t); for (; n > 0; n--) { - -#ifdef HAVE_BYTESWAP_H - *dst = bswap_16(*src); -#else - *dst = (*src >> 8) | (*src << 8); -#endif + *dst = SA_UINT16_SWAP(*src); src += sstr / sizeof(uint16_t); dst += dstr / sizeof(uint16_t); @@ -32,7 +43,7 @@ static void byteswap16(void *_dst, size_t dstr, const void *_src, size_t sstr, s static void byteswap24(void *_dst, size_t dstr, const void *_src, size_t sstr, size_t bytes) { uint8_t *dst = _dst; const uint8_t *src = _src; - unsigned n = bytes / (sizeof(uint8_t)*3); + size_t n = bytes / 3; for (; n > 0; n--) { dst[0] = src[2]; @@ -46,14 +57,11 @@ static void byteswap24(void *_dst, size_t dstr, const void *_src, size_t sstr, s static void byteswap32(void *_dst, size_t dstr, const void *_src, size_t sstr, size_t bytes) { uint32_t *dst = _dst; const uint32_t *src = _src; - unsigned n = bytes / sizeof(uint32_t); + size_t n = bytes / sizeof(uint32_t); for (; n > 0; n--) { -#ifdef HAVE_BYTESWAP_H - *dst = bswap_32(*src); -#else - *dst = (*src << 24) | ((*src & 0xFF00) << 8) | ((*src >> 8) & 0xFF00) | (*src >> 24); -#endif + *dst = SA_UINT32_SWAP(*src); + src += sstr / sizeof(uint32_t); dst += dstr / sizeof(uint32_t); } -- cgit