genchecksum.c revision 256281
1/* Generate checksums of executables for PCH validation 2 Copyright (C) 2005 3 Free Software Foundation, Inc. 4 5This file is part of GCC. 6 7GCC is free software; you can redistribute it and/or modify it under 8the terms of the GNU General Public License as published by the Free 9Software Foundation; either version 2, or (at your option) any later 10version. 11 12GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13WARRANTY; without even the implied warranty of MERCHANTABILITY or 14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15for more details. 16 17You should have received a copy of the GNU General Public License 18along with GCC; see the file COPYING. If not, write to the Free 19Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 2002110-1301, USA. */ 21 22#include "bconfig.h" 23#include "system.h" 24#include "md5.h" 25 26static void 27usage (void) 28{ 29 fputs ("Usage: genchecksums <filename>\n", stderr); 30} 31 32static void 33dosum (const char *file) 34{ 35 FILE *f; 36 unsigned char result[16]; 37 int i; 38 39 f = fopen (file, "rb"); 40 if (!f) 41 { 42 fprintf (stderr, "opening %s: %s\n", file, xstrerror (errno)); 43 exit (1); 44 } 45 46 /* Some executable formats have timestamps in the first 16 bytes, yuck. */ 47 if (fseek (f, 16, SEEK_SET) != 0) 48 { 49 fprintf (stderr, "seeking in %s: %s\n", file, xstrerror (errno)); 50 exit (1); 51 } 52 53 if (md5_stream (f, result) != 0 54 || fclose (f) != 0) 55 { 56 fprintf (stderr, "reading %s: %s\n", file, xstrerror (errno)); 57 exit (1); 58 } 59 60 fputs ("const unsigned char executable_checksum[16] = { ", stdout); 61 for (i = 0; i < 16; i++) 62 printf ("%#02x%s", result[i], i == 15 ? " };\n" : ", "); 63} 64 65int 66main (int argc, char ** argv) 67{ 68 if (argc != 2) 69 { 70 usage (); 71 return 1; 72 } 73 74 dosum (argv[1]); 75 76 return 0; 77} 78