summaryrefslogtreecommitdiff
path: root/src/postprocess/cutfile.c
blob: a2c87dc5d22f81c48b5d7b6bfb2974399a65d475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "mystdlib.h"
#include <unistd.h>

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;
}