annotate lib/swig/swigwin-2.0.11/CCache/hash.c @ 1979:92dfa0cafbe3

Fixing players not getting damaged by projectiles
author Grumpy7
date Mon, 28 Oct 2013 22:16:42 -0700
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 Copyright (C) Andrew Tridgell 2002
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7 (at your option) any later version.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 GNU General Public License for more details.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15 along with this program; if not, write to the Free Software
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 simple front-end functions to mdfour code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 #include "ccache.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 static struct mdfour md;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 void hash_buffer(const char *s, int len)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 mdfour_update(&md, (unsigned char *)s, len);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 void hash_start(void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 mdfour_begin(&md);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 void hash_string(const char *s)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 hash_buffer(s, strlen(s));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 void hash_int(int x)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 hash_buffer((char *)&x, sizeof(x));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 /* add contents of a file to the hash */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 void hash_file(const char *fname)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 char buf[1024];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 int fd, n;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 fd = open(fname, O_RDONLY|O_BINARY);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 if (fd == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 cc_log("Failed to open %s\n", fname);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 fatal("hash_file");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 while ((n = read(fd, buf, sizeof(buf))) > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 hash_buffer(buf, n);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61 close(fd);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 /* return the hash result as a static string */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65 char *hash_result(void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 unsigned char sum[16];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 static char ret[53];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 hash_buffer(NULL, 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 mdfour_result(&md, sum);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 for (i=0;i<16;i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 sprintf(&ret[i*2], "%02x", (unsigned)sum[i]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77 sprintf(&ret[i*2], "-%u", (unsigned)md.totalN);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 }