123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <errno.h>
- #include <string.h>
- static int update_vector_checksum( const char *filename )
- {
- uint32_t sum;
- uint32_t header[8];
- FILE *fs;
- int i;
- if (( fs = fopen( filename, "r+b" )) == NULL )
- {
- fprintf( stderr, "Unable to open '%s' for reading/writing (%d): %s\n",
- filename, errno, strerror( errno ));
- return 0;
- }
- if ( fread( header, sizeof( header ), 1, fs ) != 1 )
- {
- fprintf( stderr, "Failed to read header from '%s' (perhaps the file is too small?)",
- filename );
- fclose( fs );
- return 0;
- }
- sum = 0;
- for ( i = 0; i < 7; i++ )
- {
- sum += header[i];
- }
- printf( "sum = 0x%08x, value to write = 0x%08x\n", sum, -sum );
-
- fseek(fs, 0x1c, SEEK_SET);
- sum = -sum;
- fwrite(&sum, 4, 1, fs);
- fclose( fs );
- return 1;
- }
- int main( int argc, char **argv )
- {
- int arg;
- if ( argc < 2)
- {
- fprintf( stderr, "Usage: lpc-vector-checksum file ...\n" );
- exit( 1 );
- }
- for ( arg = 1; arg < argc; arg++ )
- {
- update_vector_checksum( argv[ arg ]);
- }
- exit( 0 );
- return 0;
- }
|