From: havoc Date: Thu, 27 Mar 2003 08:58:07 +0000 (+0000) Subject: Elric added BuffBigLong, BuffBigShort, BuffLittleLong, and BuffLittleShort functions... X-Git-Tag: xonotic-v0.1.0preview~6714 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=1ae145acaf81ed231a047916ec42c786368bc560 Elric added BuffBigLong, BuffBigShort, BuffLittleLong, and BuffLittleShort functions intended for reading from misaligned locations in file memory buffers (these read as bytes rather than entire numbers, so memory misalignments are not a problem on Sparc and certain other CPUs) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2856 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/common.c b/common.c index c3ae64b0..cd6c392c 100644 --- a/common.c +++ b/common.c @@ -123,6 +123,30 @@ float FloatNoSwap (float f) } #endif + +// Extract integers from buffers + +unsigned int BuffBigLong (const qbyte *buffer) +{ + return (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]; +} + +unsigned short BuffBigShort (const qbyte *buffer) +{ + return (buffer[0] << 8) | buffer[1]; +} + +unsigned int BuffLittleLong (const qbyte *buffer) +{ + return (buffer[3] << 24) | (buffer[2] << 16) | (buffer[1] << 8) | buffer[0]; +} + +unsigned short BuffLittleShort (const qbyte *buffer) +{ + return (buffer[1] << 8) | buffer[0]; +} + + /* ============================================================================== diff --git a/common.h b/common.h index 80d80e48..743b499a 100644 --- a/common.h +++ b/common.h @@ -91,6 +91,12 @@ extern float (*BigFloat) (float l); extern float (*LittleFloat) (float l); #endif +unsigned int BuffBigLong (const qbyte *buffer); +unsigned short BuffBigShort (const qbyte *buffer); +unsigned int BuffLittleLong (const qbyte *buffer); +unsigned short BuffLittleShort (const qbyte *buffer); + + //============================================================================ void MSG_WriteChar (sizebuf_t *sb, int c);