Removed
Link Here
|
1 |
--- ccache.h.orig Wed Sep 8 21:30:40 2004 |
2 |
+++ ccache.h Wed Sep 8 21:31:53 2004 |
3 |
@@ -65,14 +65,14 @@ |
4 |
|
5 |
typedef unsigned uint32; |
6 |
|
7 |
-#include "mdfour.h" |
8 |
+#include <md4.h> |
9 |
|
10 |
void hash_start(void); |
11 |
void hash_string(const char *s); |
12 |
void hash_int(int x); |
13 |
void hash_file(const char *fname); |
14 |
char *hash_result(void); |
15 |
-void hash_buffer(const char *s, int len); |
16 |
+void hash_buffer(const unsigned char *s, unsigned int len); |
17 |
|
18 |
void cc_log(const char *format, ...); |
19 |
void fatal(const char *msg); |
20 |
--- hash.c.orig 2004-09-13 12:38:30.000000000 +0200 |
21 |
+++ hash.c 2009-07-21 23:37:00.000000000 +0200 |
22 |
@@ -20,17 +20,22 @@ |
23 |
*/ |
24 |
|
25 |
#include "ccache.h" |
26 |
+#include <sys/types.h> |
27 |
+#include <sys/mman.h> |
28 |
+#include <sys/stat.h> |
29 |
|
30 |
-static struct mdfour md; |
31 |
+static MD4_CTX md; |
32 |
+static off_t totalN; |
33 |
|
34 |
-void hash_buffer(const char *s, int len) |
35 |
+void hash_buffer(const unsigned char *s, unsigned int len) |
36 |
{ |
37 |
- mdfour_update(&md, (unsigned char *)s, len); |
38 |
+ totalN += len; |
39 |
+ MD4Update(&md, s, len); |
40 |
} |
41 |
|
42 |
void hash_start(void) |
43 |
{ |
44 |
- mdfour_begin(&md); |
45 |
+ MD4Init(&md); |
46 |
} |
47 |
|
48 |
void hash_string(const char *s) |
49 |
@@ -46,35 +51,44 @@ |
50 |
/* add contents of a file to the hash */ |
51 |
void hash_file(const char *fname) |
52 |
{ |
53 |
- char buf[1024]; |
54 |
- int fd, n; |
55 |
+ char *buf; |
56 |
+ int fd; |
57 |
+ struct stat stats; |
58 |
|
59 |
fd = open(fname, O_RDONLY|O_BINARY); |
60 |
if (fd == -1) { |
61 |
cc_log("Failed to open %s\n", fname); |
62 |
- fatal("hash_file"); |
63 |
+ fatal(__FUNCTION__); |
64 |
} |
65 |
|
66 |
- while ((n = read(fd, buf, sizeof(buf))) > 0) { |
67 |
- hash_buffer(buf, n); |
68 |
- } |
69 |
+ if (fstat(fd, &stats) != 0) { |
70 |
+ cc_log("Failed to fstat the opened %s (descriptor %d)\n", |
71 |
+ fname, fd); |
72 |
+ close(fd); |
73 |
+ fatal(__FUNCTION__); |
74 |
+ } |
75 |
+ if( stats.st_size == 0 ) |
76 |
+ buf = NULL; |
77 |
+ else { |
78 |
+ buf = mmap(NULL, stats.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
79 |
+ if (buf == MAP_FAILED) { |
80 |
+ cc_log("Failed to mmap %s\n", fname); |
81 |
+ close(fd); |
82 |
+ fatal(__FUNCTION__); |
83 |
+ } |
84 |
+ } |
85 |
+ |
86 |
+ hash_buffer(buf, stats.st_size); |
87 |
close(fd); |
88 |
} |
89 |
|
90 |
/* return the hash result as a static string */ |
91 |
char *hash_result(void) |
92 |
{ |
93 |
- unsigned char sum[16]; |
94 |
static char ret[53]; |
95 |
- int i; |
96 |
|
97 |
- hash_buffer(NULL, 0); |
98 |
- mdfour_result(&md, sum); |
99 |
+ MD4End(&md, ret); |
100 |
|
101 |
- for (i=0;i<16;i++) { |
102 |
- sprintf(&ret[i*2], "%02x", (unsigned)sum[i]); |
103 |
- } |
104 |
- sprintf(&ret[i*2], "-%u", (unsigned)md.totalN); |
105 |
- |
106 |
+ snprintf(ret + 32, sizeof ret - 32, "-%lu", (unsigned long)totalN); |
107 |
return ret; |
108 |
} |
109 |
--- unify.c.orig Wed Sep 8 21:36:41 2004 |
110 |
+++ unify.c Wed Sep 8 21:37:20 2004 |
111 |
@@ -104,13 +104,12 @@ |
112 |
hash_buffer((char *)buf, len); |
113 |
len = 0; |
114 |
} |
115 |
- hash_buffer(NULL, 0); |
116 |
return; |
117 |
} |
118 |
|
119 |
buf[len++] = c; |
120 |
- if (len == 64) { |
121 |
- hash_buffer((char *)buf, len); |
122 |
+ if (len == sizeof buf) { |
123 |
+ hash_buffer((char *)buf, sizeof buf); |
124 |
len = 0; |
125 |
} |
126 |
} |
127 |
--- Makefile.in.orig Mon Sep 6 09:04:22 2004 |
128 |
+++ Makefile.in Wed Sep 8 21:41:00 2004 |
129 |
@@ -11,16 +11,16 @@ |
130 |
CFLAGS=@CFLAGS@ -I. |
131 |
EXEEXT=@EXEEXT@ |
132 |
|
133 |
-OBJS= ccache.o mdfour.o hash.o execute.o util.o args.o stats.o \ |
134 |
+OBJS= ccache.o hash.o execute.o util.o args.o stats.o \ |
135 |
cleanup.o snprintf.o unify.o |
136 |
-HEADERS = ccache.h mdfour.h |
137 |
+HEADERS = ccache.h |
138 |
|
139 |
all: ccache$(EXEEXT) |
140 |
|
141 |
docs: ccache.1 web/ccache-man.html |
142 |
|
143 |
ccache$(EXEEXT): $(OBJS) $(HEADERS) |
144 |
- $(CC) $(CFLAGS) -o $@ $(OBJS) |
145 |
+ $(CC) $(CFLAGS) -o $@ $(OBJS) -lmd |
146 |
|
147 |
ccache.1: ccache.yo |
148 |
-yodl2man -o ccache.1 ccache.yo |