Mercurial > hg > th-libs
view th_endian.c @ 10:a25f5d22483e
Updates.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 20 Apr 2009 00:01:43 +0300 |
parents | 8552edc844a7 |
children | 5ab4c28b85cd |
line wrap: on
line source
/* * 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. */ #include "th_endian.h" BOOL th_read_str(FILE *f, uint8_t *s, size_t l) { return (fread(s, sizeof(uint8_t), l, f) == l); } BOOL th_write_str(FILE * f, uint8_t * s, size_t l) { return (fwrite(s, sizeof(uint8_t), l, f) == l); } /* File routines for endian-dependant data */ #define TH_DEFINE_FUNC(xname, xtype, xmacro) \ BOOL th_read_ ## xname (FILE *f, xtype *v) { \ xtype result; \ if (fread(&result, sizeof( xtype ), 1, f) != 1) \ return FALSE; \ *v = TH_ ## xmacro ## _TO_NATIVE (result); \ return TRUE; \ } \ \ BOOL th_write_ ## xname (FILE *f, xtype v) { \ xtype result = TH_NATIVE_TO_ ## xmacro (v); \ if (fwrite(&result, sizeof( xtype ), 1, f) != 1) \ return FALSE; \ return TRUE; \ } TH_DEFINE_FUNC(le16, uint16_t, LE16) TH_DEFINE_FUNC(le32, uint32_t, LE32) TH_DEFINE_FUNC(be16, uint16_t, BE16) TH_DEFINE_FUNC(be32, uint32_t, BE32) #ifdef TH_HAVE_64BIT TH_DEFINE_FUNC(le64, uint64_t, LE64) TH_DEFINE_FUNC(be64, uint64_t, BE64) #endif #undef TH_DEFINE_FUNC