Search
lxdream.org :: lxdream/src/util.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/util.c
changeset 17:944f75eea496
next31:495e480360d7
author nkeynes
date Tue Dec 13 14:47:59 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change More work on load/save state - save state a little more structured now
Memory save now in
file annotate diff log raw
nkeynes@17
     1
#include "dream.h"
nkeynes@17
     2
#include "modules.h"
nkeynes@17
     3
nkeynes@17
     4
void fwrite_string( char *s, FILE *f )
nkeynes@17
     5
{
nkeynes@17
     6
    uint32_t len = 0;
nkeynes@17
     7
    if( s == NULL ) {
nkeynes@17
     8
	fwrite( &len, sizeof(len), 1, f );
nkeynes@17
     9
    } else {
nkeynes@17
    10
	len = strlen(s)+1;
nkeynes@17
    11
	fwrite( &len, sizeof(len), 1, f );
nkeynes@17
    12
	fwrite( s, len, 1, f );
nkeynes@17
    13
    }
nkeynes@17
    14
}
nkeynes@17
    15
nkeynes@17
    16
int fread_string( char *s, int maxlen, FILE *f ) 
nkeynes@17
    17
{
nkeynes@17
    18
    uint32_t len;
nkeynes@17
    19
    fread( &len, sizeof(len), 1, f );
nkeynes@17
    20
    if( len != 0 ) {
nkeynes@17
    21
	fread( s, len > maxlen ? maxlen : len, 1, f );
nkeynes@17
    22
    }
nkeynes@17
    23
    return len;
nkeynes@17
    24
}
.