diff options
Diffstat (limited to 'src/postprocess/cutfile.c')
| -rw-r--r-- | src/postprocess/cutfile.c | 33 |
1 files changed, 33 insertions, 0 deletions
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 @@ | |||
| 1 | #include "mystdlib.h" | ||
| 2 | #include <unistd.h> | ||
| 3 | |||
| 4 | int main( int argc, char **argv ) | ||
| 5 | { | ||
| 6 | MAP file = NULL; | ||
| 7 | unsigned long i = 0; | ||
| 8 | |||
| 9 | if( !(file = map_file( argv[1], 0 ) ) ) exit( 1 ); | ||
| 10 | |||
| 11 | if( file->size & 15 ) | ||
| 12 | puts( "WARNING: File size not multiple of 16" ); | ||
| 13 | |||
| 14 | while( i < file->size && *(unsigned long*)(file->addr+i) < 2911418625UL ) | ||
| 15 | i+= 16; | ||
| 16 | |||
| 17 | if( i < file->size) | ||
| 18 | { | ||
| 19 | if( i ) { | ||
| 20 | off_t newsize = (off_t)i; | ||
| 21 | printf( "%s reduced by %8d bytes. (Offending offset: %09lu)\n", argv[1], (unsigned long)(file->size - i ), *(unsigned long*)(file->addr+i) ); | ||
| 22 | ftruncate( file->fh, newsize ); | ||
| 23 | } else { | ||
| 24 | printf( "%s removed. (Offending offset: %09lu)\n", argv[1], *(unsigned long*)(file->addr+i) ); | ||
| 25 | unlink( argv[1] ); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | unmap_file( &file ); | ||
| 30 | |||
| 31 | |||
| 32 | return 0; | ||
| 33 | } | ||
