home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / sumlibrary.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  3.0 KB  |  131 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: sumlibrary.c,v 1.7 1997/01/01 03:46:17 ldp Exp $
  4.     $Log: sumlibrary.c,v $
  5.     Revision 1.7  1997/01/01 03:46:17  ldp
  6.     Committed Amiga native (support) code
  7.  
  8.     Changed clib to proto
  9.  
  10.     Revision 1.6  1996/12/10 13:51:55  aros
  11.     Moved all #include's in the first column so makedepend can see it.
  12.  
  13.     Revision 1.5  1996/10/24 15:50:58  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.4  1996/08/13 13:56:09  digulla
  17.     Replaced AROS_LA by AROS_LHA
  18.     Replaced some AROS_LH*I by AROS_LH*
  19.     Sorted and added includes
  20.  
  21.     Revision 1.3  1996/08/01 17:41:20  digulla
  22.     Added standard header for all files
  23.  
  24.     Desc:
  25.     Lang: english
  26. */
  27. #include <exec/execbase.h>
  28. #include <exec/alerts.h>
  29. #include <aros/libcall.h>
  30. #include <proto/exec.h>
  31.  
  32. /*****************************************************************************
  33.  
  34.     NAME */
  35.  
  36.     AROS_LH1(void, SumLibrary,
  37.  
  38. /*  SYNOPSIS */
  39.     AROS_LHA(struct Library *, library,A1),
  40.  
  41. /*  LOCATION */
  42.     struct ExecBase *, SysBase, 71, Exec)
  43.  
  44. /*  FUNCTION
  45.     Builds the checksum over a given library's jumptable and either puts
  46.     it into the library->lib_Sum field (if the library is marked as changed)
  47.     or compares it with this field and Alert()s at mismatch.
  48.  
  49.     INPUTS
  50.     library - Pointer to library structure.
  51.  
  52.     RESULT
  53.  
  54.     NOTES
  55.  
  56.     EXAMPLE
  57.  
  58.     BUGS
  59.  
  60.     SEE ALSO
  61.     AddLibrary(), RemLibrary(), MakeLibrary(), MakeFunctions(), InitStruct().
  62.  
  63.     INTERNALS
  64.  
  65.     HISTORY
  66.  
  67. ******************************************************************************/
  68. {
  69.     AROS_LIBFUNC_INIT
  70.  
  71.     UBYTE oldflags;
  72.     ULONG sum;
  73.  
  74.     /* Arbitrate for library base */
  75.     Forbid();
  76.  
  77.     /*
  78.     If the library checksumming is already in progress or if the
  79.     checksum is unused skip this part
  80.     */
  81.     if(library->lib_Flags&LIBF_SUMUSED&&!(library->lib_Flags&LIBF_SUMMING))
  82.     {
  83.     /* As long as the library is marked as changed */
  84.     do
  85.     {
  86.         ULONG *lp;
  87.  
  88.         /* Memorize library flags */
  89.         oldflags=library->lib_Flags;
  90.  
  91.         /* Tell other tasks: Summing in progress */
  92.         library->lib_Flags|=LIBF_SUMMING;
  93.         library->lib_Flags&=~LIBF_CHANGED;
  94.  
  95.         /* As long as the summing goes multitasking may be permitted. */
  96.         Permit();
  97.  
  98.         /* Build checksum. Note: library bases are LONG aligned */
  99.         sum=0;
  100.         /* Get start of jumptable */
  101.         lp=(ULONG *)((UBYTE *)library+library->lib_NegSize);
  102.         /* And sum it up */
  103.         while(lp<(ULONG *)library)
  104.         sum+=*lp++;
  105.  
  106.         /* Summing complete. Arbitrate again. */
  107.         Forbid();
  108.  
  109.         /* Remove summing flag */
  110.         library->lib_Flags&=~LIBF_SUMMING;
  111.  
  112.         /* Do it again if the library changed while summing. */
  113.     }while(library->lib_Flags&LIBF_CHANGED);
  114.  
  115.     /*
  116.         Alert() if the library wasn't marked as changed and if the
  117.         checksum mismatches.
  118.     */
  119.     if(!(oldflags&LIBF_CHANGED)&&library->lib_Sum!=sum)
  120.         Alert(AT_DeadEnd|AN_LibChkSum);
  121.  
  122.     /* Set new checksum */
  123.     library->lib_Sum=sum;
  124.     }
  125.  
  126.     /* All done. */
  127.     Permit();
  128.     AROS_LIBFUNC_EXIT
  129. } /* SumLibrary */
  130.  
  131.