home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / varia / setpatch43_5 / checksetpatch.c next >
C/C++ Source or Header  |  1977-12-31  |  4KB  |  108 lines

  1. /*------------------------------------------------------------------------*/
  2. /****** misc/CheckSetPatchVersion ****************************************
  3. *
  4. *   NAME
  5. *     CheckSetPatchVersion - Determine the system SetPatch level
  6. *
  7. *   SYNOPSIS
  8. *       ok = CheckSetPatchVersion(SysBase, version, revision);
  9. *
  10. *       BOOL CheckSetPatchVersion(struct ExecBase *, UWORD, UWORD);
  11. *
  12. *   FUNCTION
  13. *       Determines and checks if at least a required SetPatch is
  14. *       installed. This is for software that wants to exploit
  15. *       knowledge about installed bug fixes to avoid internal hacks
  16. *       around OS bugs.
  17. *
  18. *   INPUTS
  19. *     SysBase   - A pointer to ExecBase.
  20. *
  21. *     version   - The minimum acceptable version of SetPatch
  22. *
  23. *     revision  - The minimum acceptable revision of SetPatch
  24. *
  25. *   RESULT
  26. *     ok        - This tells you if at least the patch you are looking
  27. *                 for is installed.
  28. *
  29. *   EXAMPLE
  30. *
  31. *   NOTES
  32. *       The result is valid until the system is rebooted. This function
  33. *       will continue to work in a future OS if you heed the warnings.
  34. *
  35. *       Once a bug has been fixed in SetPatch, you can rest assured that
  36. *       either a future OS or a future SetPatch will also contain that
  37. *       bug fix. It is unlikely that fixed things are intentionally broken
  38. *       again.
  39. *
  40. *       Obviously it is not enough to check the SetPatch version to see
  41. *       if a bug is fixed. First you must make sure that you are using the
  42. *       OS version that exhibits the bug to be fixed by SetPatch. Afterall
  43. *       a SetPatch V43 can't e.g. fix V39 bugs on a V37 based Amiga.
  44. *
  45. *       DO NOT USE THIS FUNCTION TO SEE IF A BUG IS PRESENT! There is no
  46. *       guarantee at all that any bug fix is not installed if this function
  47. *       returns FALSE. Don't rely on side effects of any bug! This function
  48. *       has been designed to tell you if known problems are fixed, not for
  49. *       the contrary or any other interpretation of this description.
  50. *
  51. *       An 68K C compiler will generate less than 80 bytes for this also
  52. *       ROMable function. There is little to be gained by recoding this in
  53. *       assembler. You only lose portability completely.
  54. *
  55. *   SEE ALSO
  56. *
  57. ******************************************************************************
  58. *
  59. */
  60. /*------------------------------------------------------------------------*/
  61. /* Only ps_Version and ps_Revision may be accessed! Read only!
  62.  * Do not try anything. This is off limits!
  63.  */
  64. struct SetPatchSemaphore
  65. {
  66.     struct SignalSemaphore  sps_Sem;        /* Don't touch! */
  67.     struct MinList          sps_Private;    /* Don't touch! */
  68.     UWORD                   sps_Version;    /* Version installed */
  69.     UWORD                   sps_Revision;   /* Revision installed */
  70.     /* Don't touch! */
  71. };
  72.  
  73. /*------------------------------------------------------------------------*/
  74. BOOL CheckSetPatchVersion(struct ExecBase *SysBase,
  75.                           UWORD version, UWORD revision)
  76. {
  77.     struct SetPatchSemaphore *sem;
  78.     BOOL foundsetpatch = FALSE;
  79.  
  80.     /* This may look strange, but it is ok.
  81.      * An installed SetPatch will never be removed and once it
  82.      * has been installed its version/revision won't change.
  83.      * This is _guaranteed_!
  84.      * So if the semaphore exists, it will never disappear again.
  85.      * The result is that we can keep the Forbid (Yuck!) very short.
  86.      * We pass in SysBase to be able to avoid any global/$4 access.
  87.      */
  88.     Forbid();
  89.     sem = (struct SetPatchSemaphore *)FindSemaphore((STRPTR)"« SetPatch »");
  90.     Permit();
  91.  
  92.     if(sem)
  93.     {
  94.         /* Do we have at least the requested version/revision? */
  95.         if((version > sem->sps_Version) ||
  96.            ((version == sem->sps_Version) && (revision >= sem->sps_Revision)))
  97.         {
  98.             /* Yes, we got it. The requested SetPatch has been installed */
  99.             foundsetpatch = TRUE;
  100.         } /* if */
  101.     } /* if */
  102.  
  103.     return(foundsetpatch);
  104.  
  105. } /* CheckSetPatchVersion */
  106.  
  107.  
  108.