X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=util.c;h=e634186bd0b56efcf4c1d4c83abcd41202fe5dfe;hb=24763aad65b8a6cb7fda9e038ee058b2ea02b875;hp=ba7db5ff510a496e2fefe71976cc9bcc147f0803;hpb=3070c03fc0df299df630d5bbaddc3b767b0a1566;p=xonotic%2Fgmqcc.git diff --git a/util.c b/util.c index ba7db5f..e634186 100644 --- a/util.c +++ b/util.c @@ -85,6 +85,7 @@ const char *util_instr_str[VINSTR_END] = { d[l] = (v << 32) | (v >> 32); } */ + l *= 2; size_t i; for (i = 0; i < l; i += 2) { uint32_t v1 = d[i]; @@ -95,43 +96,39 @@ const char *util_instr_str[VINSTR_END] = { } #endif -void util_tolittleendianarray(void *_data, size_t length, unsigned int typesize) { +void util_endianswap(void *_data, size_t count, unsigned int typesize) { # if PLATFORM_BYTE_ORDER == -1 /* runtime check */ if (*((char*)&typesize)) return; #else - /* prevent unused warnings */ - (void) _data; - (void) length; - (void) typesize; # if PLATFORM_BYTE_ORDER == GMQCC_BYTE_ORDER_LITTLE + /* prevent unused warnings */ + (void) _data; + (void) count; + (void) typesize; return; # else switch (typesize) { case 1: return; case 2: - util_swap16((uint16_t*)_data, length); + util_swap16((uint16_t*)_data, count); return; case 4: - util_swap32((uint32_t*)_data, length); + util_swap32((uint32_t*)_data, count); return; case 8: - util_swap64((uint32_t*)_data, length<<1); /* swap64 operates on 32 bit words, thus scale to that length. */ + util_swap64((uint32_t*)_data, count); return; default: - con_err ("util_tolittleendianarray: I don't know how to swap a %d byte structure!\n", typesize); + con_err ("util_endianswap: I don't know how to swap a %u 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.