Snoopy: print correct title for OpenResource patch.
[AROS.git] / compiler / arossupport / calcchecksum.c
blob701e2d91ec41901433a8afbca32012db3c25e2e2
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Calculate a checksum for a given area of memory
6 Lang: english
7 */
9 #include <aros/system.h>
10 #include <assert.h>
12 /*****************************************************************************
14 NAME */
15 #include <proto/arossupport.h>
17 ULONG CalcChecksum (
19 /* SYNOPSIS */
20 APTR memory,
21 ULONG size)
23 /* FUNCTION
24 Calculate a checksum for a given area of memory.
26 INPUTS
27 memory - Start here
28 size - This many bytes. Must be a multiple of sizeof(ULONG)
30 RESULT
31 The checksum for the memory. If you store the checksum somewhere
32 in the area and run CalcChecksum() again, the result will be 0.
33 To achieve this, you must set the place, where the checksum will
34 be placed later, to 0 before you call the function.
36 NOTES
37 This function is not part of a library and may thus be called
38 any time.
40 EXAMPLE
41 ULONG mem[512];
43 mem[0] = 0; // Store checksum here
44 mem[0] = CalcChecksum (mem, sizeof (mem));
46 if (CalcChecksum (mem, sizeof (mem))
47 printf ("Something is wrong !!\n");
48 else
49 printf ("Data is unchanged.\n");
51 BUGS
53 SEE ALSO
54 exec.library/SumKickData(), exec.library/SumLibrary()
56 INTERNALS
57 The function uses the DOS way: sum all the ULONGs and return the
58 negative result. Not very safe, but then it's quite fast :)
60 HISTORY
61 26-10-95 digulla created
63 ******************************************************************************/
65 ULONG sum;
66 ULONG * lptr;
68 assert (memory);
69 assert ((size&(sizeof(ULONG)-1))==0);
71 for (sum=0, lptr=(ULONG *)memory; size>0; size-=sizeof(ULONG))
72 sum += *lptr ++;
74 return -sum;
75 } /* CalcChecksum */