Search
lxdream.org :: lxdream :: r117:3b6a128ae733
lxdream 0.9.1
released Jun 29
Download Now
changeset117:3b6a128ae733
parent116:87e3bea309a5
child118:fcec54454d10
authornkeynes
dateMon Mar 20 11:58:37 2006 +0000 (14 years ago)
Add an fwrite_dump() method to do a binary block dump
src/util.c
1.1 --- a/src/util.c Fri Mar 17 12:45:11 2006 +0000
1.2 +++ b/src/util.c Mon Mar 20 11:58:37 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: util.c,v 1.3 2005-12-26 03:54:52 nkeynes Exp $
1.6 + * $Id: util.c,v 1.4 2006-03-20 11:58:37 nkeynes Exp $
1.7 *
1.8 * Miscellaneous utility functions.
1.9 *
1.10 @@ -39,3 +39,24 @@
1.11 }
1.12 return len;
1.13 }
1.14 +
1.15 +void fwrite_dump( unsigned char *data, unsigned int length, FILE *f )
1.16 +{
1.17 + unsigned int i, j;
1.18 + for( i =0; i<length; i+=16 ) {
1.19 + fprintf( f, "%08X:", i);
1.20 + for( j=i; j<i+16; j++ ) {
1.21 + if( (j % 4) == 0 )
1.22 + fprintf( f, " " );
1.23 + if( j < length )
1.24 + fprintf( f, " %02X", (unsigned int)(data[j]) );
1.25 + else
1.26 + fprintf( f, " " );
1.27 + }
1.28 + fprintf( f, " " );
1.29 + for( j=i; j<i+16 && j<length; j++ ) {
1.30 + fprintf( f, "%c", isprint(data[j]) ? data[j] : '.' );
1.31 + }
1.32 + fprintf( f, "\n" );
1.33 + }
1.34 +}
.