X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=util.c;h=bcffdcbf9fa43df7be0bb4925f33240a065e1ad1;hp=e9d4cfeb4b55e2263839f1290116885a2a9781ba;hb=1bf9ebabcce7731b83c302e8416bba41c3cdf5da;hpb=8a26ed7664cccb29ca4552321137ba9a1d3ba7f0 diff --git a/util.c b/util.c index e9d4cfe..bcffdcb 100644 --- a/util.c +++ b/util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, 2013 + * Copyright (C) 2012, 2013, 2014 * Dale Weiler * Wolfgang Bumiller * @@ -22,6 +22,7 @@ * SOFTWARE. */ #define GMQCC_PLATFORM_HEADER +#include #include "gmqcc.h" #include "platform.h" @@ -94,7 +95,7 @@ const char *util_instr_str[VINSTR_END] = { } #endif -void util_endianswap(void *_data, size_t length, unsigned int typesize) { +void util_tolittleendianarray(void *_data, size_t length, unsigned int typesize) { # if PLATFORM_BYTE_ORDER == -1 /* runtime check */ if (*((char*)&typesize)) return; @@ -110,21 +111,27 @@ void util_endianswap(void *_data, size_t length, unsigned int typesize) { switch (typesize) { case 1: return; case 2: - util_swap16((uint16_t*)_data, length>>1); + util_swap16((uint16_t*)_data, length); return; case 4: - util_swap32((uint32_t*)_data, length>>2); + util_swap32((uint32_t*)_data, length); return; case 8: - util_swap64((uint32_t*)_data, length>>3); + util_swap64((uint32_t*)_data, length); return; - default: exit(EXIT_FAILURE); /* please blow the fuck up! */ + default: + con_err ("util_tolittleendianarray: I don't know how to swap a %d byte structure!\n", typesize); + exit(EXIT_FAILURE); /* please blow the fuck up! */ } # endif #endif } +void util_tolittleendian(void *_data, unsigned int typesize) { + util_tolittleendianarray(_data, 1, typesize); +} + /* * Based On: * Slicing-by-8 algorithms by Michael E. @@ -499,7 +506,7 @@ uint16_t util_crc16(uint16_t current, const char *GMQCC_RESTRICT k, size_t len) * modifier is the match to make and the transposition from it, while add is the upper-value that determines the * transposition from uppercase to lower case. */ -static GMQCC_INLINE size_t util_strtransform(const char *in, char *out, size_t outsz, const char *mod, int add) { +static size_t util_strtransform(const char *in, char *out, size_t outsz, const char *mod, int add) { size_t sz = 1; for (; *in && sz < outsz; ++in, ++out, ++sz) { *out = (*in == mod[0])