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