Search
lxdream.org :: lxdream/src/util.c :: diff
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
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/util.c Tue Dec 13 14:47:59 2005 +0000
1.3 @@ -0,0 +1,24 @@
1.4 +#include "dream.h"
1.5 +#include "modules.h"
1.6 +
1.7 +void fwrite_string( char *s, FILE *f )
1.8 +{
1.9 + uint32_t len = 0;
1.10 + if( s == NULL ) {
1.11 + fwrite( &len, sizeof(len), 1, f );
1.12 + } else {
1.13 + len = strlen(s)+1;
1.14 + fwrite( &len, sizeof(len), 1, f );
1.15 + fwrite( s, len, 1, f );
1.16 + }
1.17 +}
1.18 +
1.19 +int fread_string( char *s, int maxlen, FILE *f )
1.20 +{
1.21 + uint32_t len;
1.22 + fread( &len, sizeof(len), 1, f );
1.23 + if( len != 0 ) {
1.24 + fread( s, len > maxlen ? maxlen : len, 1, f );
1.25 + }
1.26 + return len;
1.27 +}
.