Mercurial > hg > th-libs
diff th_endian2.h @ 0:bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
here, because it's cluttered and commit messages are mostly crap.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Mar 2008 04:41:58 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/th_endian2.h Wed Mar 26 04:41:58 2008 +0200 @@ -0,0 +1,49 @@ +/* + * Endianess handling + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2002-2007 Tecnic Software productions (TNSP) + * + * Please read file 'COPYING' for information on license and distribution. + */ +#if (!defined(TH_RNAME) || !defined(TH_FILE) || !defined(TH_FREAD) || !defined(TH_FGETC)) +#error Some required preprocessor macros NOT defined, but th_endian2.h included! +#endif + +#ifdef TH_CODE_ENDIAN2 +BOOL TH_RNAME(STR) (TH_FILE *f, uint8_t *s, size_t l) +{ + return (TH_FREAD(s, sizeof(uint8_t), l, f) == l); +} + + +uint16_t TH_RNAME(BE16) (TH_FILE *f) +{ + return (((uint16_t) TH_FGETC(f)) << 8) | + ((uint16_t) TH_FGETC(f)); +} + + +uint32_t TH_RNAME(BE32) (TH_FILE *f) +{ + return (((uint32_t) TH_FGETC(f)) << 24) | + (((uint32_t) TH_FGETC(f)) << 16) | + (((uint32_t) TH_FGETC(f)) << 8) | + ((uint32_t) TH_FGETC(f)); +} + + +uint16_t TH_RNAME(LE16) (TH_FILE *f) +{ + return ((uint16_t) TH_FGETC(f)) | + (((uint16_t) TH_FGETC(f)) << 8); +} + + +uint32_t TH_RNAME(LE32) (TH_FILE *f) +{ + return ((uint32_t) TH_FGETC(f)) | + (((uint32_t) TH_FGETC(f)) << 8) | + (((uint32_t) TH_FGETC(f)) << 16) | + (((uint32_t) TH_FGETC(f)) << 24); +} +#endif