]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/genchecksum.c
Change copyright header to refer to version 3 of the GNU General Public License and...
[thirdparty/gcc.git] / gcc / genchecksum.c
CommitLineData
3fd30b88 1/* Generate checksums of executables for PCH validation
9dcd6f09 2 Copyright (C) 2005, 2007
3fd30b88
GK
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
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
3fd30b88
GK
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
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
3fd30b88
GK
20
21#include "bconfig.h"
22#include "system.h"
23#include "md5.h"
24
25static void
26usage (void)
27{
28 fputs ("Usage: genchecksums <filename>\n", stderr);
29}
30
31static void
32dosum (const char *file)
33{
34 FILE *f;
35 unsigned char result[16];
36 int i;
37
38 f = fopen (file, "rb");
39 if (!f)
40 {
41 fprintf (stderr, "opening %s: %s\n", file, xstrerror (errno));
42 exit (1);
43 }
44
45 /* Some executable formats have timestamps in the first 16 bytes, yuck. */
46 if (fseek (f, 16, SEEK_SET) != 0)
47 {
48 fprintf (stderr, "seeking in %s: %s\n", file, xstrerror (errno));
49 exit (1);
50 }
51
52 if (md5_stream (f, result) != 0
53 || fclose (f) != 0)
54 {
55 fprintf (stderr, "reading %s: %s\n", file, xstrerror (errno));
56 exit (1);
57 }
58
59 fputs ("const unsigned char executable_checksum[16] = { ", stdout);
60 for (i = 0; i < 16; i++)
61 printf ("%#02x%s", result[i], i == 15 ? " };\n" : ", ");
62}
63
64int
65main (int argc, char ** argv)
66{
67 if (argc != 2)
68 {
69 usage ();
70 return 1;
71 }
72
73 dosum (argv[1]);
74
75 return 0;
76}