summaryrefslogtreecommitdiffstats
path: root/src/bswap.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-10-09 18:15:23 +0200
committerLennart Poettering <lennart@poettering.net>2008-10-09 18:15:23 +0200
commit181e9c6d5d11cb1e5d36a2777eeb233ad8ed00e5 (patch)
tree7c280968ce3fded5b325b1480d7f2440ddf93207 /src/bswap.c
parent30a4b516c8d591c11f05df38531f46452d930d2b (diff)
big pile of updates to match more what happened with libcanberra
Diffstat (limited to 'src/bswap.c')
-rw-r--r--src/bswap.c44
1 files changed, 26 insertions, 18 deletions
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
+ <http://www.gnu.org/licenses/>.
+***/
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-#ifdef HAVE_BYTESWAP_H
-#include <byteswap.h>
-#endif
-
#include <inttypes.h>
#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);
}