2 * $Id: util.c,v 1.4 2006-03-20 11:58:37 nkeynes Exp $
4 * Miscellaneous utility functions.
6 * Copyright (c) 2005 Nathan Keynes.
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.
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.
21 void fwrite_string( char *s, FILE *f )
25 fwrite( &len, sizeof(len), 1, f );
28 fwrite( &len, sizeof(len), 1, f );
29 fwrite( s, len, 1, f );
33 int fread_string( char *s, int maxlen, FILE *f )
36 fread( &len, sizeof(len), 1, f );
38 fread( s, len > maxlen ? maxlen : len, 1, f );
43 void fwrite_dump( unsigned char *data, unsigned int length, FILE *f )
46 for( i =0; i<length; i+=16 ) {
47 fprintf( f, "%08X:", i);
48 for( j=i; j<i+16; j++ ) {
52 fprintf( f, " %02X", (unsigned int)(data[j]) );
57 for( j=i; j<i+16 && j<length; j++ ) {
58 fprintf( f, "%c", isprint(data[j]) ? data[j] : '.' );
.