home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / exec / sumlibrary.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  2.8 KB  |  123 lines

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