view dmfile.c @ 96:6bf5220fa47e

Urgh .. use memset to silence some bogus GCC warnings about using potentially uninitialized values, while that will not actually be possible. In any case, it is annoying.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Oct 2012 18:52:28 +0300
parents 32250b436bca
children d0257d0004f6
line wrap: on
line source

/*
 * DMLib
 * -- Plain STDIO file endianess functions
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2011 Tecnic Software productions (TNSP)
 */
#include "dmfile.h"


BOOL dm_fread_str(FILE *f, void *buf, size_t len)
{
    return fread(buf, len, 1, f) == 1;
}


#define DM_DEFINE_FFUNC(xname, xtype, xmacro)         \
BOOL dm_fread_ ## xname (FILE *f, xtype *v) {         \
    xtype result;                                     \
    if (fread(&result, sizeof( xtype ), 1, f) != 1)   \
        return FALSE;                                 \
    *v = DM_ ## xmacro ## _TO_NATIVE (result);        \
    return TRUE;                                      \
}

#include "dmfiletmpl.h"


#undef DM_DEFINE_FFUNC

BOOL dm_fwrite_str(FILE *f, void *buf, size_t len)
{
    return fwrite(buf, len, 1, f) == 1;
}


#define DM_DEFINE_FFUNC(xname, xtype, xmacro)         \
BOOL dm_fwrite_ ## xname (FILE *f, xtype v) {         \
    xtype result = DM_NATIVE_TO_ ## xmacro (v);       \
    if (fwrite(&result, sizeof( xtype ), 1, f) != 1)  \
        return FALSE;                                 \
    return TRUE;                                      \
}

#include "dmfiletmpl.h"

#undef DM_DEFINE_FFUNC