Search
lxdream.org :: lxdream/src/util.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/util.c
changeset 31:495e480360d7
prev17:944f75eea496
next35:21a4be098304
author nkeynes
date Sun Dec 25 08:24:11 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Finish adding header blocks to all files
view annotate diff log raw
     1 /**
     2  * $Id: util.c,v 1.2 2005-12-25 08:24:07 nkeynes Exp $
     3  *
     4  * Miscellaneous utility functions.
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include "dream.h"
    20 #include "modules.h"
    22 void fwrite_string( char *s, FILE *f )
    23 {
    24     uint32_t len = 0;
    25     if( s == NULL ) {
    26 	fwrite( &len, sizeof(len), 1, f );
    27     } else {
    28 	len = strlen(s)+1;
    29 	fwrite( &len, sizeof(len), 1, f );
    30 	fwrite( s, len, 1, f );
    31     }
    32 }
    34 int fread_string( char *s, int maxlen, FILE *f ) 
    35 {
    36     uint32_t len;
    37     fread( &len, sizeof(len), 1, f );
    38     if( len != 0 ) {
    39 	fread( s, len > maxlen ? maxlen : len, 1, f );
    40     }
    41     return len;
    42 }
.