From 64c85dfc1d3b546dd4b5f84168e9256817f3a741 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Thu, 20 Feb 2014 02:46:41 +0100 Subject: clean up source directory --- src/postprocess/cutfile.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/postprocess/cutfile.c (limited to 'src/postprocess/cutfile.c') diff --git a/src/postprocess/cutfile.c b/src/postprocess/cutfile.c new file mode 100644 index 0000000..a2c87dc --- /dev/null +++ b/src/postprocess/cutfile.c @@ -0,0 +1,33 @@ +#include "mystdlib.h" +#include + +int main( int argc, char **argv ) +{ + MAP file = NULL; + unsigned long i = 0; + + if( !(file = map_file( argv[1], 0 ) ) ) exit( 1 ); + + if( file->size & 15 ) + puts( "WARNING: File size not multiple of 16" ); + + while( i < file->size && *(unsigned long*)(file->addr+i) < 2911418625UL ) + i+= 16; + + if( i < file->size) + { + if( i ) { + off_t newsize = (off_t)i; + printf( "%s reduced by %8d bytes. (Offending offset: %09lu)\n", argv[1], (unsigned long)(file->size - i ), *(unsigned long*)(file->addr+i) ); + ftruncate( file->fh, newsize ); + } else { + printf( "%s removed. (Offending offset: %09lu)\n", argv[1], *(unsigned long*)(file->addr+i) ); + unlink( argv[1] ); + } + } + + unmap_file( &file ); + + + return 0; +} -- cgit v1.2.3