Forward compatibility: libarossupport.a - remove dependency on C library
[AROS.git] / compiler / arossupport / calcchecksum.c
blob87ba9c4a0e14f0b274a22b1e2904d74df018448e
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>
11 /*****************************************************************************
13 NAME */
14 #include <proto/arossupport.h>
16 ULONG CalcChecksum (
18 /* SYNOPSIS */
19 APTR memory,
20 ULONG size)
22 /* FUNCTION
23 Calculate a checksum for a given area of memory.
25 INPUTS
26 memory - Start here
27 size - This many bytes. Must be a multiple of sizeof(ULONG)
29 RESULT
30 The checksum for the memory. If you store the checksum somewhere
31 in the area and run CalcChecksum() again, the result will be 0.
32 To achieve this, you must set the place, where the checksum will
33 be placed later, to 0 before you call the function.
35 NOTES
36 This function is not part of a library and may thus be called
37 any time.
39 EXAMPLE
40 ULONG mem[512];
42 mem[0] = 0; // Store checksum here
43 mem[0] = CalcChecksum (mem, sizeof (mem));
45 if (CalcChecksum (mem, sizeof (mem))
46 printf ("Something is wrong !!\n");
47 else
48 printf ("Data is unchanged.\n");
50 BUGS
52 SEE ALSO
53 exec.library/SumKickData(), exec.library/SumLibrary()
55 INTERNALS
56 The function uses the DOS way: sum all the ULONGs and return the
57 negative result. Not very safe, but then it's quite fast :)
59 HISTORY
60 26-10-95 digulla created
62 ******************************************************************************/
64 ULONG sum;
65 ULONG * lptr;
67 for (sum=0, lptr=(ULONG *)memory; size>0; size-=sizeof(ULONG))
68 sum += *lptr ++;
70 return -sum;
71 } /* CalcChecksum */